Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
feat(docker): Add CloudOps Dockerfile & CircleCI build instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
jbuck committed Sep 26, 2016
1 parent 32f8679 commit a80b4b4
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Dockerfile-build
@@ -0,0 +1,20 @@
FROM node:4.5.0

RUN groupadd --gid 10001 app && \
useradd --uid 10001 --gid 10001 --home /app --create-home app

USER app

WORKDIR /app

COPY scripts/gen_keys.js scripts/gen_keys.js
COPY package.json package.json

RUN npm install && \
npm cache clear && \
rm -rf ~app/.node-gyp ~app/.npm

COPY . /app

ENTRYPOINT ["/app/scripts/docker-exec.sh"]
CMD ["test"]
49 changes: 49 additions & 0 deletions circle.yml
@@ -0,0 +1,49 @@
# These environment variables must be set in CircleCI UI
#
# DOCKERHUB_REPO - docker hub repo, format: <username>/<repo>
# DOCKER_EMAIL - login info for docker hub
# DOCKER_USER
# DOCKER_PASS
#
machine:
services:
- docker
dependencies:
override:
- docker info

- >
printf '{"version":{"hash":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}}\n'
"$CIRCLE_SHA1"
"$CIRCLE_TAG"
"$CIRCLE_PROJECT_USERNAME"
"$CIRCLE_PROJECT_REPONAME"
"$CIRCLE_BUILD_URL"
| tee config/version.json version.json
- docker build -f Dockerfile-build -t app:build .

test:
override:
- docker run app:build test

# appropriately tag and push the container to dockerhub
deployment:
hub_latest:
branch: "master"
commands:
- "[ ! -z $DOCKERHUB_REPO ]"
- docker login -e "$DOCKER_EMAIL" -u "$DOCKER_USER" -p "$DOCKER_PASS"
- "docker tag app:build ${DOCKERHUB_REPO}:latest"
- "docker push ${DOCKERHUB_REPO}:latest"

hub_releases:
# push all tags
tag: /.*/
commands:
- "[ ! -z $DOCKERHUB_REPO ]"
- docker login -e "$DOCKER_EMAIL" -u "$DOCKER_USER" -p "$DOCKER_PASS"
- "echo ${DOCKERHUB_REPO}:${CIRCLE_TAG}"
- "docker tag app:build ${DOCKERHUB_REPO}:${CIRCLE_TAG}"
- "docker images"
- "docker push ${DOCKERHUB_REPO}:${CIRCLE_TAG}"
16 changes: 16 additions & 0 deletions scripts/docker-exec.sh
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

if [ "$1" == "test" ]; then
exec npm test
elif [ "$1" == "web" ]; then
exec node bin/server.js
elif [ "$1" == "internal" ]; then
exec node bin/internal.js
elif [ "$1" == "purge_expired_tokens" ]; then
exec node bin/purge_expired_tokens.js
elif [ "$1" == "gen_keys" ]; then
exec node scripts/gen_keys.js
else
echo "unknown mode: $1"
exit 1
fi
7 changes: 7 additions & 0 deletions scripts/gen_keys.js
Expand Up @@ -38,6 +38,13 @@ function main(cb) {
var privKey = JwTool.JWK.fromPEM(generateRSAKeypair().private, {
kid: '2015.12.16-1'
});

try {
fs.mkdirSync('./config');
} catch (accessEx) {

}

fs.writeFileSync(keyPath, JSON.stringify(privKey.toJSON(), undefined, 2));
console.log('Key saved:', keyPath); //eslint-disable-line no-console

Expand Down

0 comments on commit a80b4b4

Please sign in to comment.