Merge pull request #210 from hdevillers/master
[bioperl-live.git] / travis_scripts / trigger-dockerhub.sh
blob3674fa44f7e0082c9ad2bb07355f5328b69fbfb2
1 #!/bin/bash
3 set -e
5 # the Docker Hub API endpoint
6 dockerapi="https://registry.hub.docker.com/u/bioperl/bioperl/trigger"
8 ## Travis runs a build for several versions of Perl, but we want to
9 ## trigger only for the same version of Perl as is running in the
10 ## Docker container
11 docker_perl="5.18"
13 if [[ ${TRAVIS_PERL_VERSION:0:4} != "$docker_perl" ]] ; then
14 echo "Triggering Docker Hub only for Perl $docker_perl, not $TRAVIS_PERL_VERSION"
15 exit 0
18 if [[ "$TRAVIS_PULL_REQUEST" != "false" ]] ; then
19 echo "Not triggering Docker Hub for pull requests."
20 exit 0
23 if [[ -z "$DOCKERHUB_TOKEN" ]] ; then
24 echo "No API token for Docker Hub, add to repository settings."
25 exit 1
28 ## Should check for tag names that indicate release candidates rather
29 ## than release names, and then skip those.
30 ## However, this is already taken care of by the regular expression
31 ## for whitelisting branches.
33 if [[ -n "$TRAVIS_TAG" && "$TRAVIS_TAG" != "false" ]] ; then
34 # if we are building a whitelisted tag, we trigger the stable image
35 echo "Triggering rebuild of Docker image bioperl/bioperl:stable"
36 curl -H "Content-Type: application/json" \
37 --data '{"docker_tag": "stable"}' \
38 -X POST $dockerapi/$DOCKERHUB_TOKEN/
39 elif [[ "$TRAVIS_BRANCH" != "master" ]] ; then
40 # if someone were to create a branch that matches the whitelisting
41 # pattern, we skip that here, and only trigger on master
42 echo "Not triggering Docker Hub for branches other than master"
43 else
44 # not a pull request, not a tag, and the branch is master
45 echo "Triggering rebuild of Docker image bioperl/bioperl:latest"
46 curl -H "Content-Type: application/json" \
47 --data '{"docker_tag": "latest"}' \
48 -X POST $dockerapi/$DOCKERHUB_TOKEN/