1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-28 06:00:06 +02:00

bug: fix bootstrap process

This commit is contained in:
geek 2017-09-14 19:08:35 -05:00 committed by Sérgio Ramos
parent beb8062572
commit 1b5a2bfa9a
11 changed files with 137 additions and 136 deletions

View File

@ -51,32 +51,35 @@ $ ./setup.sh ~/path/to/TRITON_PRIVATE_KEY keys-test.com/ca.crt keys-test.com/ser
## Usage ## Usage
You have 3 options for where to run CoPilot. You can either run it using the published docker images locally, or on Triton. The last option is to build the docker images and run docker containers from these locally built images. You have 3 options for where to run CoPilot. You can either run it using the published docker images on Triton or locally. The last option is to build the docker images and run docker containers from these locally built images.
### Deploy and run CoPilot on Triton
Optionally use [_triton-docker_](https://github.com/joyent/triton-docker-cli)
```sh
$ triton-compose up -d
```
Or use `docker-compose` with preconfigured Triton environment variables
```sh
$ docker-compose up -d
```
### Start CoPilot using published docker images locally ### Start CoPilot using published docker images locally
```sh ```sh
$ docker-compose up -d $ docker-compose -f local-compose.yml up -d
``` ```
Navigate to [https://localhost]() to load the dashboard. Navigate to [https://localhost]() to load the dashboard.
### Deploy and run CoPilot on Triton ### Build and run CoPilot locally for development
```sh ```sh
$ docker-compose -f triton-compose.yml up -d $ docker-compose -f dev-compose.yml up -d
```
Optionally use [_triton-docker_](https://github.com/joyent/triton-docker-cli)
```sh
$ triton-compose -f triton-compose.yml up -d
```
### Build and run CoPilot locally
```sh
$ docker-compose -f local-compose.yml up -d
``` ```
## Contribute ## Contribute

View File

@ -16,8 +16,6 @@ consul:
-ui-dir /ui -ui-dir /ui
restart: always restart: always
mem_limit: 128m mem_limit: 128m
labels:
- triton.cns.services=copilot-consul
ports: ports:
- 8500:8500 - 8500:8500
@ -33,82 +31,80 @@ prometheus:
mem_limit: 1g mem_limit: 1g
ports: ports:
- 9090:9090 - 9090:9090
labels: links:
# This label sets the CNS name, Triton's automatic DNS - consul:consul
# Learn more at https://docs.joyent.com/public-cloud/network/cns
- triton.cns.services=prometheus
# This label selects the proper Joyent resource package
# https://www.joyent.com/blog/optimizing-docker-on-triton#ram-cpu-and-disk-resources-for-your-containers
- com.joyent.package=g4-highcpu-1G
env_file:
- _env
environment: environment:
- CONSUL=consul
- CONSUL_AGENT=1 - CONSUL_AGENT=1
dns:
- 127.0.0.1
rethinkdb:
image: autopilotpattern/rethinkdb:2.3.5r1
restart: always
mem_limit: 1g
env_file:
- _env
environment:
- CONSUL_AGENT=1
expose:
- 28015
- 29015
############################################################################# #############################################################################
# FRONTEND # FRONTEND
############################################################################# #############################################################################
frontend: frontend:
image: joyent/copilot-frontend:1.3.4 build: docker/frontend
mem_limit: 512m mem_limit: 512m
labels: links:
- triton.cns.services=copilot - consul:consul
env_file: env_file:
- _env - _env
environment: environment:
- CONSUL=consul
- PORT=443 - PORT=443
ports: ports:
- "80:80" - "80:80"
- "443:443" - "443:443"
restart: always dns:
- 127.0.0.1
############################################################################# #############################################################################
# BACKEND # BACKEND
############################################################################# #############################################################################
api: api:
image: joyent/copilot-api:1.8.8 build: docker/api
mem_limit: 1g mem_limit: 512m
expose: links:
- 3000 - consul:consul
env_file: env_file:
- _env - _env
environment: environment:
- CONSUL=consul
- PORT=3000 - PORT=3000
restart: always expose:
- 3000
# Docker-compose wrapper # Docker-compose wrapper
# Create _env file from running ./setup.sh # Create _env file from running ./setup.sh
compose-api: compose-api:
image: joyent/copilot-compose:1.1.0 build: docker/compose-api
links:
- consul:consul
expose: expose:
- 4242 - 4242
env_file: env_file:
- _env - _env
environment:
- CONSUL=consul
restart: always restart: always
rethinkdb: rethinkdb:
image: autopilotpattern/rethinkdb:2.3.5r2 image: autopilotpattern/rethinkdb:2.3.5r1
restart: always restart: always
mem_limit: 1g mem_limit: 1g
links:
- consul:consul
env_file: env_file:
- _env - _env
environment: environment:
- CONSUL=consul
- CONSUL_AGENT=1 - CONSUL_AGENT=1
ports:
- 8080:8080
expose: expose:
- 28015 - 28015
- 29015 - 29015
dns:
- 127.0.0.1

View File

@ -16,10 +16,10 @@ consul:
-ui-dir /ui -ui-dir /ui
restart: always restart: always
mem_limit: 128m mem_limit: 128m
labels:
- triton.cns.services=copilot-consul
ports: ports:
- 8500:8500 - 8500:8500
dns:
- 127.0.0.1
############################################################################# #############################################################################
# PROMETHEUS # PROMETHEUS
@ -28,87 +28,87 @@ consul:
# it is included here for demo purposes and is not required # it is included here for demo purposes and is not required
############################################################################# #############################################################################
prometheus: prometheus:
image: autopilotpattern/prometheus:1.7.1-r20 image: autopilotpattern/prometheus:1.7.1-r24
restart: always restart: always
mem_limit: 1g mem_limit: 1g
ports: ports:
- 9090:9090 - 9090:9090
links: labels:
- consul:consul # This label sets the CNS name, Triton's automatic DNS
# Learn more at https://docs.joyent.com/public-cloud/network/cns
- triton.cns.services=prometheus
# This label selects the proper Joyent resource package
# https://www.joyent.com/blog/optimizing-docker-on-triton#ram-cpu-and-disk-resources-for-your-containers
- com.joyent.package=g4-highcpu-1G
env_file:
- _env
environment: environment:
- CONSUL=consul
- CONSUL_AGENT=1 - CONSUL_AGENT=1
dns:
- 127.0.0.1
rethinkdb:
image: autopilotpattern/rethinkdb:2.3.5r1
restart: always
mem_limit: 1g
env_file:
- _env
environment:
- CONSUL_AGENT=1
expose:
- 28015
- 29015
############################################################################# #############################################################################
# FRONTEND # FRONTEND
############################################################################# #############################################################################
frontend: frontend:
image: joyent/copilot-frontend:1.0.0 image: joyent/copilot-frontend:1.3.4
mem_limit: 512m mem_limit: 512m
links: labels:
- consul:consul - triton.cns.services=copilot
env_file: env_file:
- _env - _env
environment: environment:
- CONSUL=consul
- PORT=443 - PORT=443
ports: ports:
- "80:80" - "80:80"
- "443:443" - "443:443"
dns: restart: always
- 127.0.0.1
############################################################################# #############################################################################
# BACKEND # BACKEND
############################################################################# #############################################################################
api: api:
image: joyent/copilot-api:1.8.8 image: joyent/copilot-api:1.8.9
mem_limit: 512m mem_limit: 1g
links: expose:
- consul:consul - 3000
- rethinkdb:rethinkdb
env_file: env_file:
- _env - _env
environment: environment:
- CONSUL=consul
- PORT=3000 - PORT=3000
- RETHINK_HOST=rethinkdb restart: always
expose:
- 3000
# Docker-compose wrapper # Docker-compose wrapper
# Create _env file from running ./setup.sh # Create _env file from running ./setup.sh
compose-api: compose-api:
image: joyent/copilot-compose:1.0.0 image: joyent/copilot-compose:1.1.0
links:
- consul:consul
expose: expose:
- 4242 - 4242
env_file: env_file:
- _env - _env
environment:
- CONSUL=consul
restart: always restart: always
rethinkdb: rethinkdb:
image: autopilotpattern/rethinkdb:2.3.5r1 image: autopilotpattern/rethinkdb:2.3.5r2
restart: always restart: always
mem_limit: 1g mem_limit: 1g
links:
- consul:consul
env_file: env_file:
- _env - _env
environment: environment:
- CONSUL=consul
- CONSUL_AGENT=1 - CONSUL_AGENT=1
ports:
- 8080:8080
expose: expose:
- 28015 - 28015
- 29015 - 29015
dns:
- 127.0.0.1

View File

@ -73,13 +73,9 @@ const bootstrap = function ({ docker, rethink }, cb) {
return cb(err); return cb(err);
} }
data.getDatacenters((err, datacenters) => { data.getPortal({}, (err, portal) => {
if (err) {
return cb(err);
}
// Don't continue since data is already bootstrapped // Don't continue since data is already bootstrapped
if (datacenters && datacenters.length) { if (portal) {
return cb(); return cb();
} }
@ -98,17 +94,13 @@ const bootstrap = function ({ docker, rethink }, cb) {
return cb(err); return cb(err);
} }
cloudapi.getAccount((err, { cloudapi.getAccount({}, (err, body) => {
id,
firstName,
lastName,
email,
login
}) => {
if (err) { if (err) {
return cb(err); return cb(err);
} }
const { id, firstName, lastName, email, login } = body;
data.createUser({ data.createUser({
tritonId: id, tritonId: id,
firstName, firstName,

View File

@ -6,13 +6,34 @@
exec: '/bin/prestart.sh' exec: '/bin/prestart.sh'
}, },
{ {
name: 'bootstrap', name: 'consul-agent',
exec: 'node bootstrap-data.js', exec: ['/usr/local/bin/consul', 'agent',
'-data-dir=/data',
'-config-dir=/config',
'-log-level=err',
'-rejoin',
'-retry-join', '{{ .CONSUL | default "consul" }}',
'-retry-max', '20',
'-retry-interval', '5s'],
restarts: 'unlimited',
"health": {
"exec": "curl -so /dev/null http://localhost:8500",
"interval": 10,
"ttl": 25
},
when: { when: {
source: 'setup-config', source: 'setup-config',
once: 'exitSuccess' once: 'exitSuccess'
} }
}, },
{
name: 'bootstrap',
exec: 'node bootstrap-data.js',
when: {
source: 'consul-agent',
once: 'healthy'
}
},
{ {
name: 'api', name: 'api',
port: {{.PORT}}, port: {{.PORT}},
@ -28,18 +49,6 @@
}, },
restarts: 'unlimited' restarts: 'unlimited'
}, },
{
name: 'consul-agent',
exec: ['/usr/local/bin/consul', 'agent',
'-data-dir=/data',
'-config-dir=/config',
'-log-level=err',
'-rejoin',
'-retry-join', '{{ .CONSUL | default "consul" }}',
'-retry-max', '20',
'-retry-interval', '5s'],
restarts: 'unlimited'
},
{ {
name: 'sensor_memory_usage', name: 'sensor_memory_usage',
exec: '/bin/sensors.sh memory', exec: '/bin/sensors.sh memory',

View File

@ -21,7 +21,7 @@
"joi": "^10.6.0", "joi": "^10.6.0",
"joyent-cp-gql-schema": "^1.7.0", "joyent-cp-gql-schema": "^1.7.0",
"piloted": "^3.1.1", "piloted": "^3.1.1",
"portal-api": "^1.8.8", "portal-api": "^1.8.9",
"toppsy": "^1.1.0", "toppsy": "^1.1.0",
"triton": "^5.2.0" "triton": "^5.2.0"
} }

View File

@ -18,6 +18,8 @@ consul:
mem_limit: 128m mem_limit: 128m
ports: ports:
- 8500:8500 - 8500:8500
dns:
- 127.0.0.1
############################################################################# #############################################################################
# PROMETHEUS # PROMETHEUS
@ -26,7 +28,7 @@ consul:
# it is included here for demo purposes and is not required # it is included here for demo purposes and is not required
############################################################################# #############################################################################
prometheus: prometheus:
image: autopilotpattern/prometheus:1.7.1-r24 image: autopilotpattern/prometheus:1.7.1-r20
restart: always restart: always
mem_limit: 1g mem_limit: 1g
ports: ports:
@ -36,13 +38,15 @@ prometheus:
environment: environment:
- CONSUL=consul - CONSUL=consul
- CONSUL_AGENT=1 - CONSUL_AGENT=1
dns:
- 127.0.0.1
############################################################################# #############################################################################
# FRONTEND # FRONTEND
############################################################################# #############################################################################
frontend: frontend:
build: docker/frontend image: joyent/copilot-frontend:1.3.4
mem_limit: 512m mem_limit: 512m
links: links:
- consul:consul - consul:consul
@ -54,28 +58,32 @@ frontend:
ports: ports:
- "80:80" - "80:80"
- "443:443" - "443:443"
dns:
- 127.0.0.1
############################################################################# #############################################################################
# BACKEND # BACKEND
############################################################################# #############################################################################
api: api:
build: docker/api image: joyent/copilot-api:1.8.9
mem_limit: 512m mem_limit: 512m
links: links:
- consul:consul - consul:consul
- rethinkdb:rethinkdb
env_file: env_file:
- _env - _env
environment: environment:
- CONSUL=consul - CONSUL=consul
- PORT=3000 - PORT=3000
- RETHINK_HOST=rethinkdb
expose: expose:
- 3000 - 3000
# Docker-compose wrapper # Docker-compose wrapper
# Create _env file from running ./setup.sh # Create _env file from running ./setup.sh
compose-api: compose-api:
build: docker/compose-api image: joyent/copilot-compose:1.0.0
links: links:
- consul:consul - consul:consul
expose: expose:

View File

@ -263,7 +263,7 @@ class Data extends EventEmitter {
// datacenters // datacenters
createDatacenter (datacenter, cb) { createDatacenter (datacenter, cb) {
this._db.datacenters.insert(datacenter, (err, key) => { this._db.datacenters.insert(datacenter, { merge: true }, (err, key) => {
if (err) { if (err) {
return cb(err); return cb(err);
} }

View File

@ -49,8 +49,10 @@ module.exports = function (server, options, next) {
settings.data.server = server; settings.data.server = server;
const data = new Data(settings.data); const data = new Data(settings.data);
const cpWatcher = new ContainerPilotWatcher(Object.assign(settings.watch, { data })); const watcherOptions = settings.watch;
const machinesWatcher = new MachinesWatcher(Object.assign(settings.watch, { data })); watcherOptions.data = data;
const cpWatcher = new ContainerPilotWatcher(watcherOptions);
const machinesWatcher = new MachinesWatcher(watcherOptions);
// watcher <-> watcher // watcher <-> watcher
// portal depends on watcher and vice-versa // portal depends on watcher and vice-versa

View File

@ -186,24 +186,15 @@ module.exports = class ContainerPilotWatcher extends Events {
const fetchStatus = (ip, next) => { const fetchStatus = (ip, next) => {
Wreck.get(`http://${ip}:9090/status`, { Wreck.get(`http://${ip}:9090/status`, {
timeout: 1000 // 1s timeout: 2000, // 2 seconds
}, (err, res, payload) => { json: 'force'
}, (err, res, status) => {
if (err) { if (err) {
this.emit('error', err); this.emit('error', err);
return next(); return next();
} }
if (Buffer.isBuffer(payload)) {
payload = payload.toString();
}
try {
const status = JSON.parse(payload);
next(null, status); next(null, status);
} catch (err) {
this.emit('error', err);
next();
}
}); });
}; };

View File

@ -1,6 +1,6 @@
{ {
"name": "portal-api", "name": "portal-api",
"version": "1.8.8", "version": "1.8.9",
"description": "", "description": "",
"main": "./lib/index.js", "main": "./lib/index.js",
"scripts": { "scripts": {
@ -29,7 +29,7 @@
"hapi": "^16.5.2", "hapi": "^16.5.2",
"lab": "^14.2.2", "lab": "^14.2.2",
"lodash.findindex": "^4.6.0", "lodash.findindex": "^4.6.0",
"wreck": "^12.4.0" "wreck": "^12.5.0"
}, },
"dependencies": { "dependencies": {
"boom": "^5.2.0", "boom": "^5.2.0",