Browse Source

Merge pull request #965 from pelias/master

Merge master into staging
pull/966/head
Julian Simioni 7 years ago committed by GitHub
parent
commit
b97b1b28fd
  1. 12
      .circleci/config.yml
  2. 30
      .circleci/docker.sh
  3. 1
      .dockerignore
  4. 15
      Dockerfile
  5. 5
      app.js
  6. 18
      pelias.json.docker
  7. 12
      routes/default.js

12
.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

30
.circleci/docker.sh

@ -0,0 +1,30 @@
#!/bin/bash
set -u
# collect params from ENV vars
DATE=`date +%Y-%m-%d`
DOCKER_REPOSITORY="pelias"
DOCKER_PROJECT="${DOCKER_REPOSITORY}/${CIRCLE_PROJECT_REPONAME}"
# 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

1
.dockerignore

@ -0,0 +1 @@
.git

15
Dockerfile

@ -1,8 +1,10 @@
FROM node:4.6.0
MAINTAINER Pelias
# base image
FROM pelias/libpostal_baseimage
# maintainer information
LABEL maintainer="pelias@mapzen.com"
EXPOSE 3100
LABEL io.openshift.expose-services 3100:http
# Where the app is built and run inside the docker fs
ENV WORK=/opt/pelias
@ -11,18 +13,17 @@ ENV WORK=/opt/pelias
ENV HOME=/opt/pelias
WORKDIR ${WORK}
ADD . ${WORK}
COPY . ${WORK}
# Build and set permissions for arbitrary non-root user
RUN npm install && \
npm test && \
chmod -R a+rwX .
ADD pelias.json.docker pelias.json
# Don't run as root, because there's no reason to (https://docs.docker.com/engine/articles/dockerfile_best-practices/#user).
# This also reveals permission problems on local Docker.
RUN chown -R 9999:9999 ${WORK}
USER 9999
CMD npm start
# start service
CMD [ "npm", "start" ]

5
app.js

@ -1,4 +1,3 @@
var app = require('express')();
var peliasConfig = require( 'pelias-config' ).generate(require('./schema'));
@ -16,6 +15,10 @@ app.use( require('./middleware/jsonp') );
/** ----------------------- routes ----------------------- **/
var defaultRoutes = require('./routes/default');
defaultRoutes.addRoutes(app);
var v1 = require('./routes/v1');
v1.addRoutes(app, peliasConfig);

18
pelias.json.docker

@ -1,18 +0,0 @@
{
"esclient": {
"hosts": [
{
"env": "production",
"protocol": "http",
"host": "pelias-data-container",
"port": 9200
},
{
"env": "production",
"protocol": "http",
"host": "pelias-data-container",
"port": 9300
}
]
}
}

12
routes/default.js

@ -0,0 +1,12 @@
// set up routes that are outside any particular API version
function addRoutes(app) {
function redirectToV1(req, res, next) {
res.redirect(301, '/v1');
}
// default root URL traffic to V1 root
// which has a link to the readme and other helpful info
app.get('/', redirectToV1);
}
module.exports.addRoutes = addRoutes;
Loading…
Cancel
Save