From e6dfbeec51405b3f0b767c97c7944267fe215349 Mon Sep 17 00:00:00 2001 From: Tom Gallacher Date: Mon, 17 Oct 2016 16:41:17 +0100 Subject: [PATCH] Dockerising the cloudapi application --- bin/setup.sh | 3 +++ cloudapi-graphql/Dockerfile | 32 ++++++++++++++++++++++++ cloudapi-graphql/etc/containerpilot.json | 14 +++++++++++ cloudapi-graphql/src/api/request.js | 7 +++++- docker-compose.yml | 12 +++++++++ local-compose.yml | 10 ++++++++ 6 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 cloudapi-graphql/Dockerfile create mode 100644 cloudapi-graphql/etc/containerpilot.json diff --git a/bin/setup.sh b/bin/setup.sh index 7f682690..301069ea 100755 --- a/bin/setup.sh +++ b/bin/setup.sh @@ -64,6 +64,9 @@ write_env_file() { [[ -f .env ]] || { echo '# Consul discovery via Triton CNS' >> .env echo CONSUL=consul.svc.${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com >> .env + echo SDC_KEY_ID=${SDC_KEY_ID} >> .env + echo SDC_ACCOUNT=${SDC_ACCOUNT} >> .env + echo SDC_URL=${SDC_URL} >> .env echo >> .env } } diff --git a/cloudapi-graphql/Dockerfile b/cloudapi-graphql/Dockerfile new file mode 100644 index 00000000..cdc33c7d --- /dev/null +++ b/cloudapi-graphql/Dockerfile @@ -0,0 +1,32 @@ +FROM node:slim + +RUN set -x \ + && apt-key adv --keyserver pgp.mit.edu --recv D101F7899D41F3C3 \ + && echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \ + && apt-get update && apt-get install -y git yarn --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* \ + && groupadd -g 433 -r nodejs \ + && useradd -u 431 -r -g nodejs -d /home/nodejs -s /sbin/nologin -c "Docker image user" nodejs \ + && mkdir -p /home/nodejs/ \ + && chown -R nodejs:nodejs /home/nodejs/ + +# Get and configure containerpilot +ENV CONTAINERPILOT_VERSION 2.4.1 +ENV CONTAINERPILOT file:///etc/containerpilot.json + +RUN export CP_SHA1=198d96c8d7bfafb1ab6df96653c29701510b833c \ + && curl -Lso /tmp/containerpilot.tar.gz \ + "https://github.com/joyent/containerpilot/releases/download/${CONTAINERPILOT_VERSION}/containerpilot-${CONTAINERPILOT_VERSION}.tar.gz" \ + && echo "${CP_SHA1} /tmp/containerpilot.tar.gz" | sha1sum -c \ + && tar zxf /tmp/containerpilot.tar.gz -C /bin \ + && rm /tmp/containerpilot.tar.gz + +COPY ./etc/containerpilot.json /etc/ + +USER nodejs +WORKDIR /home/nodejs/ +ADD package.json . +RUN npm install # yarn +ADD . . + +CMD [ "/bin/containerpilot", "node", "src/index.js" ] diff --git a/cloudapi-graphql/etc/containerpilot.json b/cloudapi-graphql/etc/containerpilot.json new file mode 100644 index 00000000..95440e70 --- /dev/null +++ b/cloudapi-graphql/etc/containerpilot.json @@ -0,0 +1,14 @@ +{ + "consul": "{{ .CONSUL }}:8500", + "services": [ + { + "name": "cloudapi-graphql", + "port": 3000, + "health": "/usr/bin/curl -o /dev/null --fail -s http://localhost:3000/", + "poll": 3, + "ttl": 10 + } + ], + "backends": [ + ] +} diff --git a/cloudapi-graphql/src/api/request.js b/cloudapi-graphql/src/api/request.js index ba35db74..68a0d3be 100644 --- a/cloudapi-graphql/src/api/request.js +++ b/cloudapi-graphql/src/api/request.js @@ -1,4 +1,9 @@ -const credentials = require('../../credentials.json'); +const credentials = { + url: process.env.SDC_URL, + account: process.env.SDC_ACCOUNT, + user: process.env.SDC_USER || '', + keyId: process.env.SDC_KEY_ID, +}; const auth = require('smartdc-auth'); const cloudapi = require('triton/lib/cloudapi2'); diff --git a/docker-compose.yml b/docker-compose.yml index 61a2ecd0..5245bf07 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,3 +18,15 @@ consul: ports: - 8500:8500 command: -server -bootstrap -ui-dir /ui +############################################################################# +# CloudAPI GraphQL +############################################################################# +cloudapi: + build: ./cloudapi-graphql + labels: + - triton.cns.services=cloudapi + env_file: .env + environment: + - PORT=3000 + ports: + - 3000:3000 diff --git a/local-compose.yml b/local-compose.yml index fd1cb89e..cd34a095 100644 --- a/local-compose.yml +++ b/local-compose.yml @@ -4,3 +4,13 @@ consul: service: consul ports: - 8500:8500 +cloudapi: + extends: + file: docker-compose.yml + service: cloudapi + links: + - consul:consul + environment: + - PORT=3000 + - ROOT_URL=http://localhost:3000 + - CONSUL=consul