Build docker images with Travis

- Add Docker hub secrets to Travis
- Push to Docker Hub
- Ignore .git directory and things like coverage logs, so as to minimise
  the container size

I placed the Docker hub login commands in the commands in the .travis.yml file,
rather than in the Makefile. This is because the Makefile would display the
Docker password to stdout, which would then become publically available in the
Travis logs.

I also run `git clean -fd .` and `git checkout -- .` to ensure that anything
written to the repo directory during tests isn't added to the docker container.
I do this in the Travis file rather than the Makefile, since running things with
`make` reverted my changes while experimenting, and I want to save others the
same issue.

To make this work on Travis, we need to set secrets for the DOCKER_USER and
DOCKER_PASS environment variable.
This commit is contained in:
Oskar Pearson
2017-02-11 01:43:09 +00:00
parent 340a38226b
commit 65428aab7c
4 changed files with 74 additions and 2 deletions
+25 -1
View File
@@ -24,6 +24,8 @@ ISTANBUL=./node_modules/.bin/istanbul
ANALYZED=./coverage/lcov.info
export CODACY_REPO_TOKEN=e29ae5cf671f4f918912d9864316207c
DOCKER_IMAGE=oskarpearson/cgm-remote-monitor-testing
all: test
coverage:
@@ -45,4 +47,26 @@ travis:
NODE_ENV=test ${MONGO_SETTINGS} \
${ISTANBUL} cover ${MOCHA} --report lcovonly -- -R tap ${TESTS}
.PHONY: all coverage report test travis
docker_release:
# Get the version from the package.json file
$(eval DOCKER_TAG=$(shell cat package.json | jq '.version' | tr -d '"'))
#
# Rebuild the image. We do this with no-cache so that we have all security upgrades,
# since that's more important than fewer layers in the Docker image.
docker build --no-cache=true -f Dockerfile.example -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
# Push an image to Docker Hub with the version from package.json:
docker push $(DOCKER_IMAGE):$(DOCKER_TAG)
#
# Push the master branch to Docker hub as 'latest'
if [ "$(TRAVIS_BRANCH)" = "master" ]; then \
docker tag $(DOCKER_IMAGE):$(DOCKER_TAG) $(DOCKER_IMAGE):latest && \
docker push $(DOCKER_IMAGE):latest; \
fi
#
# Push the dev branch to Docker Hub as 'latest_dev'
if [ "$(TRAVIS_BRANCH)" = "dev" ]; then \
docker tag $(DOCKER_IMAGE):$(DOCKER_TAG) $(DOCKER_IMAGE):latest_dev && \
docker push $(DOCKER_IMAGE):latest_dev; \
fi
.PHONY: all coverage docker_release report test travis