docker-build
is a small script for building, tagging and pushing docker images within circle CI. We use this as a way of pre-building Docker images for Tugboat to deploy to Empire.
It makes the following assumptions:
- Your docker registry repo and GitHub repo are the same (e.g. remind101/acme-inc on GitHub, remind101/acme-inc on Docker registry).
- You want to tag the docker image with the value of the
$CIRLE_SHA1
(git commit sha) and$CIRCLE_BRANCH
(git branch). - You're docker credentials are provided as
$DOCKER_EMAIL
,$DOCKER_USER
,$DOCKER_PASS
Build the image
$ docker-build build
Equivalent to:
$ docker build --no-cache -t "$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME" .
$ docker tag "$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME" \
"$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_SHA1"
$ docker tag "$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME" \
"$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH"
Push the resulting image to docker registry
$ docker-build push
Equivalent to:
$ docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
$ docker push "$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME"
To use this script, merge the following in to your circle.yml
:
machine:
services:
- docker
dependencies:
pre:
- curl https://raw.githubusercontent.com/remind101/docker-build/master/docker-build > /home/ubuntu/bin/docker-build
- chmod +x /home/ubuntu/bin/docker-build
override:
- docker-build build
deployment:
hub:
branch: /.*/
commands:
- docker-build push
- docker images