From 0bbcccfa676a73ff7fb5bada8089a8f45c88a026 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 22 Jun 2018 15:03:17 +0200 Subject: [PATCH] feat(dockerize): add docker configuration --- .circleci/config.yml | 12 ++++++++++++ .circleci/docker.sh | 35 +++++++++++++++++++++++++++++++++++ .dockerignore | 5 +++++ Dockerfile | 19 +++++++++++++++++++ README.md | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 .circleci/config.yml create mode 100644 .circleci/docker.sh create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..8aeea9d --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,12 @@ +version: 2 +jobs: + build: + working_directory: /app + docker: + - image: docker:17.05.0-ce-git + steps: + - checkout + - setup_remote_docker + - run: + name: Build and push image to Docker Hub + command: sh .circleci/docker.sh diff --git a/.circleci/docker.sh b/.circleci/docker.sh new file mode 100644 index 0000000..1acd51c --- /dev/null +++ b/.circleci/docker.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -u + +# collect params from ENV vars +DATE=`date +%Y-%m-%d` +DOCKER_REPOSITORY="pelias" +DOCKER_PROJECT="${DOCKER_REPOSITORY}/${CIRCLE_PROJECT_REPONAME}" + +# skip builds on greenkeeper branches +if [[ -z "${CIRCLE_BRANCH##*greenkeeper*}" ]]; then + exit 0 +fi + +# the name of the image that represents the "branch", that is an image that will be updated over time with the git branch +# the production branch is changed to "latest", otherwise the git branch becomes the name of the version +if [[ "${CIRCLE_BRANCH}" == "production" ]]; then + DOCKER_BRANCH_IMAGE_VERSION="latest" +else + DOCKER_BRANCH_IMAGE_VERSION="${CIRCLE_BRANCH}" +fi +DOCKER_BRANCH_IMAGE_NAME="${DOCKER_PROJECT}:${DOCKER_BRANCH_IMAGE_VERSION}" + +# the name of the image that represents the "tag", that is an image that is named with the date and git commit and will never be changed +DOCKER_TAG_IMAGE_VERSION="${CIRCLE_BRANCH}-${DATE}-${CIRCLE_SHA1}" +DOCKER_TAG_IMAGE_NAME="${DOCKER_PROJECT}:${DOCKER_TAG_IMAGE_VERSION}" + +# build image and login to docker hub +docker build -t $DOCKER_PROJECT . +docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" + +# copy the image to each of the two tags, and push +docker tag $DOCKER_PROJECT $DOCKER_BRANCH_IMAGE_NAME +docker tag $DOCKER_PROJECT $DOCKER_TAG_IMAGE_NAME +docker push $DOCKER_BRANCH_IMAGE_NAME +docker push $DOCKER_TAG_IMAGE_NAME diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..bbade39 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.git +node_modules +data +*.png +*.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..807a905 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +# base image +FROM pelias/baseimage + +# change working dir +ENV WORKDIR /code/pelias/fuzzy-tester +WORKDIR ${WORKDIR} + +# install npm dependencies +COPY ./package.json ${WORKDIR} +RUN npm install + +# add code from local checkout +ADD . ${WORKDIR} + +# run tests +RUN npm test + +# set entrypoint +ENTRYPOINT [ "./bin/fuzzy-tester" ] \ No newline at end of file diff --git a/README.md b/README.md index 88715ca..2644f3c 100644 --- a/README.md +++ b/README.md @@ -157,3 +157,42 @@ giving it a weight of 10 points, set weights to the following: ``` Weights can be nested and are completely optional, in which case the defaults will be in effect. + +## Using the Docker image + +### rebuild the image + +you can rebuild the image on any system with the following command: + +```bash +$ docker build -t pelias/fuzzy-tester . +``` + +### download pre-built image + +Up to date Docker images are built and automatically pushed to Docker Hub from our continuous integration pipeline + +You can pull the latest stable image with + +```bash +$ docker pull pelias/fuzzy-tester +``` + +### running tests in a container + +You can bind-mount local tests to make them available inside the container using the `-v` flag. + +In this example, the local file `./pelias.json` and local directory `./test_cases` are bind-mounted in to the container. + +```bash +docker run --rm -i \ + -v './pelias.json:/code/pelias.json' \ + -v './test_cases:/code/pelias/fuzzy-tester/test_cases' \ + pelias/fuzzy-tester --help +``` + +### download custom image tags + +We publish each commit and the latest of each branch to separate tags + +A list of all available tags to download can be found at https://hub.docker.com/r/pelias/fuzzy-tester/tags/