From ffb66639d7f41a5710ede77d316160a2331f1817 Mon Sep 17 00:00:00 2001 From: geek Date: Mon, 19 Jun 2017 09:37:38 -0500 Subject: [PATCH] build(portal-api): dockerizing --- local-compose.yml | 83 +++++++++++++++++++ packages/portal-api/Dockerfile | 14 ++++ packages/portal-api/etc/containerpilot.json | 46 ++++++++++ packages/portal-api/package.json | 2 +- packages/portal-api/{example.js => server.js} | 17 +++- 5 files changed, 158 insertions(+), 4 deletions(-) create mode 100644 local-compose.yml create mode 100644 packages/portal-api/Dockerfile create mode 100644 packages/portal-api/etc/containerpilot.json rename packages/portal-api/{example.js => server.js} (77%) diff --git a/local-compose.yml b/local-compose.yml new file mode 100644 index 00000000..3bd398fb --- /dev/null +++ b/local-compose.yml @@ -0,0 +1,83 @@ +############################################################################# +# CONSUL +# +# Consul is the service catalog that helps discovery between the components +# Change "-bootstrap" to "-bootstrap-expect 3", then scale to 3 or more to +# turn this into an HA Consul raft. +############################################################################# +consul: + image: autopilotpattern/consul:latest + command: > + /usr/local/bin/containerpilot + /bin/consul agent -server + -bootstrap-expect 1 + -config-dir=/etc/consul + -ui-dir /ui + restart: always + mem_limit: 128m + ports: + - 8500 + dns: + - 127.0.0.1 + +############################################################################# +# PROMETHEUS +# +# Prometheus is an open source performance monitoring tool +# it is included here for demo purposes and is not required +############################################################################# +prometheus: + image: autopilotpattern/prometheus:latest + restart: always + mem_limit: 1g + ports: + - 9090 + links: + - consul:consul + environment: + - CONSUL=consul + - CONSUL_AGENT=1 + +############################################################################# +# FRONTEND +############################################################################# +frontend: + build: packages/cp-frontend + mem_limit: 512m + links: + - consul:consul + environment: + - CONSUL=consul + - CONSUL_AGENT=1 + - PORT=5000 + ports: + - 5000 + +############################################################################# +# BACKEND +############################################################################# +api: + build: packages/portal-api + mem_limit: 512m + links: + - consul:consul + - rethinkdb:rethinkdb + environment: + - CONSUL=consul + - CONSUL_AGENT=1 + - PORT=3000 + - RETHINK_HOST=rethinkdb + ports: + - 3000 + +############################################################################# +# DATABASE +############################################################################# +rethinkdb: + image: rethinkdb + restart: always + mem_limit: 1g + expose: + - 8080 + - 28015 + - 29015 diff --git a/packages/portal-api/Dockerfile b/packages/portal-api/Dockerfile new file mode 100644 index 00000000..8493fef4 --- /dev/null +++ b/packages/portal-api/Dockerfile @@ -0,0 +1,14 @@ +# todo change to 7 +FROM quay.io/yldio/alpine-node-containerpilot:latest + +RUN yarn add lerna@^2.0.0-rc.5 \ + && ./node_modules/.bin/lerna clean --yes --scope portal-api --include-filtered-dependencies \ + && ./node_modules/.bin/lerna bootstrap --scope portal-api --include-filtered-dependencies + +WORKDIR /home/node/app/packages/portal-api +COPY packages/portal-api/etc/containerpilot.json /etc/ + +ARG CIRCLE_BRANCH + +EXPOSE 3000 +CMD ["/bin/containerpilot", "yarn", "start"] diff --git a/packages/portal-api/etc/containerpilot.json b/packages/portal-api/etc/containerpilot.json new file mode 100644 index 00000000..a6c55623 --- /dev/null +++ b/packages/portal-api/etc/containerpilot.json @@ -0,0 +1,46 @@ +{ + "consul": "0.0.0.0:8500", + "services": [ + { + "name": "cp-gql-mock-server", + "port": 3000, + "health": "/usr/bin/curl -o /dev/null --fail -s http://0.0.0.0:3000/", + "poll": 3, + "ttl": 10 + } + ], + "backends": [], + "telemetry": { + "port": 9090, + "sensors": [ + { + "name": "frontend_memory_percent", + "help": "percentage of memory used", + "type": "gauge", + "poll": 5, + "check": ["/bin/sensors", "memory"] + }, + { + "name": "frontend_cpu_load", + "help": "cpu load", + "type": "gauge", + "poll": 5, + "check": ["/bin/sensors", "cpu"] + }, + { + "name": "frontend_disk_capacity", + "help": "disk capacity", + "type": "gauge", + "poll": 60, + "check": ["/bin/sensors", "diskcapacity"] + }, + { + "name": "frontend_disk_usage", + "help": "disk usage", + "type": "gauge", + "poll": 60, + "check": ["/bin/sensors", "diskusage"] + } + ] + } +} \ No newline at end of file diff --git a/packages/portal-api/package.json b/packages/portal-api/package.json index c95e49fd..d2cbedda 100644 --- a/packages/portal-api/package.json +++ b/packages/portal-api/package.json @@ -11,7 +11,7 @@ "lint-ci": "belly-button", "test": "lab -c", "test-ci": "echo 0", - "start": "node example.js" + "start": "node server.js" }, "keywords": [], "author": "wyatt", diff --git a/packages/portal-api/example.js b/packages/portal-api/server.js similarity index 77% rename from packages/portal-api/example.js rename to packages/portal-api/server.js index 04790c1f..c88ca917 100644 --- a/packages/portal-api/example.js +++ b/packages/portal-api/server.js @@ -15,20 +15,31 @@ server.connection({ } }); -const options = { +const swaggerOptions = { info: { 'title': 'Portal API Documentation', 'version': Pack.version } }; +const portalOptions = { + data: { + db: { + host: process.env.RETHINK_HOST || 'localhost' + } + } +}; + server.register([ Inert, Vision, - Portal, + { + register: Portal, + options: portalOptions + }, { register: HapiSwagger, - options + options: swaggerOptions }], (err) => { handlerError(err);