In the after_success section of the .travis.yml file, we log on Docker Hub registry, then we build the image.
We also tag the generated image with:
the short git commit hash the travis build number latest if it is the master branch, otherwise the name of the branch And finally we push it on the Docker Hub registry
after_success:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
- export REPO=sebestblog/travis-demo
- export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo $TRAVIS_BRANCH ; fi`
- docker build -f Dockerfile -t $REPO:$COMMIT .
- docker tag $REPO:$COMMIT $REPO:$TAG
- docker tag $REPO:$COMMIT $REPO:travis-$TRAVIS_BUILD_NUMBER
- docker push $REPO