Docker has been the star of the recent times and I have recently been building a lot of Docker images, deploying them to both development and production (luckily yes!).
Travis CI is one of the most popular CI services and
I have lately been using it extensively. It is awesome!
Here is a simple
.travis.yml to get started with Docker builds on
sudo: requiredservices:- dockerenv:# IMPORTANT! Add your docker slug here (commit once)- DOCKER_REPO_SLUG=activatedgeek/mariadbscript:# build latest image always- docker build -t $DOCKER_REPO_SLUG:latest .# build the tagged image- if [[ $TRAVIS_TAG = $TRAVIS_BRANCH ]]; then docker build -t $DOCKER_REPO_SLUG:$TRAVIS_BRANCH .; else true ; fiafter_success:# IMPORTANT! Add the environment variables in Travis Build Environment (one time!)- docker login -e="$DOCKER_EMAIL" -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"# push to latest if master branch- if [[ $TRAVIS_BRANCH = master ]]; then docker push $DOCKER_REPO_SLUG:latest; else true; fi# push tag as well- if [[ $TRAVIS_TAG = $TRAVIS_BRANCH ]]; then docker push $DOCKER_REPO_SLUG:$TRAVIS_TAG; else true ; fi
Here is how the build behaves under different scenarios:
Push to a branch other than master -> Builds image and exits
Push to branch master -> Builds the image tag
Push a tag -> Builds the image with corresponding git tag
As a reference project, have a look at https://github.com/activatedgeek/docker-mariadb.
The corresponding Travis builds are available publicly at https://travis-ci.org/activatedgeek/docker-mariadb.
Dockerfilepresent in the root of the project
The implications of above two assumptions are easy to overcome if need be.