Skip to content

Commit

Permalink
Merge pull request #151 from pelias/dockerize
Browse files Browse the repository at this point in the history
feat(dockerize): add docker configuration
  • Loading branch information
missinglink authored Jun 22, 2018
2 parents d5617aa + 0bbcccf commit aeec1e0
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions .circleci/docker.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git
node_modules
data
*.png
*.md
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/

0 comments on commit aeec1e0

Please sign in to comment.