build(portal-api): dockerizing

This commit is contained in:
geek 2017-06-19 09:37:38 -05:00 committed by Sérgio Ramos
parent 3fc72f667e
commit ffb66639d7
5 changed files with 158 additions and 4 deletions

83
local-compose.yml Normal file
View File

@ -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

View File

@ -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"]

View File

@ -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"]
}
]
}
}

View File

@ -11,7 +11,7 @@
"lint-ci": "belly-button", "lint-ci": "belly-button",
"test": "lab -c", "test": "lab -c",
"test-ci": "echo 0", "test-ci": "echo 0",
"start": "node example.js" "start": "node server.js"
}, },
"keywords": [], "keywords": [],
"author": "wyatt", "author": "wyatt",

View File

@ -15,20 +15,31 @@ server.connection({
} }
}); });
const options = { const swaggerOptions = {
info: { info: {
'title': 'Portal API Documentation', 'title': 'Portal API Documentation',
'version': Pack.version 'version': Pack.version
} }
}; };
const portalOptions = {
data: {
db: {
host: process.env.RETHINK_HOST || 'localhost'
}
}
};
server.register([ server.register([
Inert, Inert,
Vision, Vision,
Portal, {
register: Portal,
options: portalOptions
},
{ {
register: HapiSwagger, register: HapiSwagger,
options options: swaggerOptions
}], }],
(err) => { (err) => {
handlerError(err); handlerError(err);