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
+18
View File
@@ -0,0 +1,18 @@
# Don't include the .git history in the Docker image:
.git
# Items from .gitignore
bower_components/
node_modules/
bundle/bundle.out.js
.idea/
*.iml
my.env
*.env
static/bower_components/
.*.sw?
.DS_Store
.vagrant
/iisnode
coverage/
npm-debug.log
+7 -1
View File
@@ -14,9 +14,15 @@ services:
- mongodb
- docker
script: make travis
after_success:
- nvm version
- if [[ ! -z "$DOCKER_USER" ]] && [[ "$(nvm version)" = "v0.12."* ]]; then docker login -u ${DOCKER_USER} -p ${DOCKER_PASS} && git checkout -- . && git clean -fd . && make docker_release; fi
after_script: make report
env:
- CXX=g++-4.8
global:
- CXX=g++-4.8
- secure: "QW33rAsCulSORXkSQK9fQotS5GuXwsr3P0KX+R0CE88N0rNE1gZuKZL5cIfYvHTdd4BiReMWja6Cox+QJJC/lu3UKZTPdArT5yUMvJ1AP8nbzzEYR1gKMy7DmcQ7OaZ8lD8LGG27P1+uRTiQ+94FmR31izg8jVXjD6ogEAayDMy5in3HoklnG+07RLdqo/8N5N7LoPcajHG051m/DRxvREdLg2L9K4yMqGKi1fpNFFti8L8jm5jAlylDlL9NGWdUj/4G1NeNIjkFrYZFodvd6R8oBDf8C6V6Tj0yvdyUQBLivTD9B8gKUWpyqE9fuy1Hz7UrZ9I9m7X6G5WPne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TAINER Nightscout Contributors
RUN apt-get update && \
apt-get -y dist-upgrade && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
git \
nodejs \
nodejs-legacy \
npm && \
apt-get -y clean
RUN mkdir -p /opt/app
ADD . /opt/app
WORKDIR /opt/app
RUN npm install && \
npm run postinstall && \
npm run env
EXPOSE 1337
CMD ["node", "server.js"]
+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