1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-14 23:30:05 +02:00

fix: health checks work for private ips

This commit is contained in:
Wyatt Preul 2017-09-15 16:36:31 -05:00 committed by Sérgio Ramos
parent c390a05076
commit b9e946ddf8
14 changed files with 55 additions and 47 deletions

View File

@ -63,7 +63,7 @@ rethinkdb:
# FRONTEND # FRONTEND
############################################################################# #############################################################################
frontend: frontend:
image: joyent/copilot-frontend:1.3.4 image: joyent/copilot-frontend:1.3.5
mem_limit: 512m mem_limit: 512m
labels: labels:
- triton.cns.services=copilot - triton.cns.services=copilot
@ -81,7 +81,7 @@ frontend:
# BACKEND # BACKEND
############################################################################# #############################################################################
api: api:
image: joyent/copilot-api:1.8.10 image: joyent/copilot-api:1.8.11
mem_limit: 1g mem_limit: 1g
expose: expose:
- 3000 - 3000
@ -94,7 +94,7 @@ api:
# 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 image: joyent/copilot-compose:1.1.1
expose: expose:
- 4242 - 4242
env_file: env_file:

View File

@ -10,7 +10,7 @@ const Url = require('url');
let timeoutId; let timeoutId;
const loadConfig = function () { const loadConfig = function () {
const docker = Piloted.service('docker-compose-api'); const docker = Piloted.service('compose-api');
const rethink = Piloted.service('rethinkdb'); const rethink = Piloted.service('rethinkdb');
const retry = () => { const retry = () => {

View File

@ -89,7 +89,7 @@
name: 'onchange-compose-api', name: 'onchange-compose-api',
exec: 'pkill -SIGHUP node', exec: 'pkill -SIGHUP node',
when: { when: {
source: 'watch.docker-compose-api', source: 'watch.compose-api',
each: 'changed' each: 'changed'
} }
}, },
@ -104,7 +104,7 @@
], ],
watches: [ watches: [
{ {
name: 'docker-compose-api', name: 'compose-api',
interval: 3 interval: 3
}, },
{ {

View File

@ -1,6 +1,6 @@
{ {
"name": "api", "name": "api",
"version": "1.8.10", "version": "1.8.11",
"description": "", "description": "",
"main": "./server.js", "main": "./server.js",
"scripts": { "scripts": {
@ -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.10", "portal-api": "^1.8.11",
"toppsy": "^1.1.0", "toppsy": "^1.1.0",
"triton": "^5.2.0" "triton": "^5.2.0"
} }

View File

@ -14,7 +14,7 @@ const Url = require('url');
let started = false; let started = false;
let timeoutId; let timeoutId;
const loadConfig = function () { const loadConfig = function () {
const docker = Piloted.service('docker-compose-api'); const docker = Piloted.service('compose-api');
const rethink = Piloted.service('rethinkdb'); const rethink = Piloted.service('rethinkdb');
if (docker && rethink && !started) { if (docker && rethink && !started) {

View File

@ -11,8 +11,8 @@ RUN export CONSUL_VERSION=0.7.0 \
&& mkdir /config && mkdir /config
# Install Containerpilot # Install Containerpilot
ENV CONTAINERPILOT_VERSION 3.4.1 ENV CONTAINERPILOT_VERSION 3.4.2
RUN export CONTAINERPILOT_CHECKSUM=4d13cfb345de86135ab2271b77516c6b6a7bed3a \ RUN export CONTAINERPILOT_CHECKSUM=5c99ae9ede01e8fcb9b027b5b3cb0cfd8c0b8b88 \
&& export archive=containerpilot-${CONTAINERPILOT_VERSION}.tar.gz \ && export archive=containerpilot-${CONTAINERPILOT_VERSION}.tar.gz \
&& curl -Lso /tmp/${archive} \ && curl -Lso /tmp/${archive} \
"https://github.com/joyent/containerpilot/releases/download/${CONTAINERPILOT_VERSION}/${archive}" \ "https://github.com/joyent/containerpilot/releases/download/${CONTAINERPILOT_VERSION}/${archive}" \

View File

@ -6,7 +6,7 @@
"exec": "/bin/prestart.sh" "exec": "/bin/prestart.sh"
}, },
{ {
"name": "docker-compose-api", "name": "compose-api",
"port": 4242, "port": 4242,
"exec": [ "exec": [
"python", "python",

View File

@ -27,8 +27,8 @@ RUN curl --retry 7 --fail -vo /tmp/consul.zip "https://releases.hashicorp.com/co
&& mkdir /config && mkdir /config
# Install Containerpilot # Install Containerpilot
ENV CONTAINERPILOT_VERSION 3.4.1 ENV CONTAINERPILOT_VERSION 3.4.2
RUN export CONTAINERPILOT_CHECKSUM=4d13cfb345de86135ab2271b77516c6b6a7bed3a \ RUN export CONTAINERPILOT_CHECKSUM=5c99ae9ede01e8fcb9b027b5b3cb0cfd8c0b8b88 \
&& export archive=containerpilot-${CONTAINERPILOT_VERSION}.tar.gz \ && export archive=containerpilot-${CONTAINERPILOT_VERSION}.tar.gz \
&& curl -Lso /tmp/${archive} \ && curl -Lso /tmp/${archive} \
"https://github.com/joyent/containerpilot/releases/download/${CONTAINERPILOT_VERSION}/${archive}" \ "https://github.com/joyent/containerpilot/releases/download/${CONTAINERPILOT_VERSION}/${archive}" \

View File

@ -27,7 +27,7 @@
}, },
}, },
{ {
name: 'cp-frontend', name: 'frontend',
port: {{.PORT}}, port: {{.PORT}},
exec: 'nginx', exec: 'nginx',
interfaces: ["eth0", "eth1"], interfaces: ["eth0", "eth1"],

View File

@ -28,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-r20 image: autopilotpattern/prometheus:1.7.1-r24
restart: always restart: always
mem_limit: 1g mem_limit: 1g
ports: ports:
@ -46,7 +46,7 @@ prometheus:
# FRONTEND # FRONTEND
############################################################################# #############################################################################
frontend: frontend:
image: joyent/copilot-frontend:1.3.4 image: joyent/copilot-frontend:1.3.5
mem_limit: 512m mem_limit: 512m
links: links:
- consul:consul - consul:consul
@ -66,7 +66,7 @@ frontend:
# BACKEND # BACKEND
############################################################################# #############################################################################
api: api:
image: joyent/copilot-api:1.8.10 image: joyent/copilot-api:1.8.11
mem_limit: 512m mem_limit: 512m
links: links:
- consul:consul - consul:consul
@ -83,7 +83,7 @@ api:
# 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.1
links: links:
- consul:consul - consul:consul
expose: expose:
@ -95,7 +95,7 @@ compose-api:
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: links:

View File

@ -32,7 +32,7 @@ module.exports = function (server, options, next) {
const settings = Hoek.applyToDefaults(internals.defaults, options || {}); const settings = Hoek.applyToDefaults(internals.defaults, options || {});
try { try {
const docker = Piloted.service('docker-compose-api'); const docker = Piloted.service('compose-api');
if (docker) { if (docker) {
settings.data.dockerComposeHost = `tcp://${docker.address}:${docker.port}`; settings.data.dockerComposeHost = `tcp://${docker.address}:${docker.port}`;
} }
@ -106,7 +106,7 @@ module.exports.attributes = {
internals.refresh = function (data) { internals.refresh = function (data) {
return () => { return () => {
const docker = Piloted.service('docker-compose-api'); const docker = Piloted.service('compose-api');
if (docker) { if (docker) {
data.reconnectCompose(`tcp://${docker.address}:${docker.port}`); data.reconnectCompose(`tcp://${docker.address}:${docker.port}`);
} }

View File

@ -132,24 +132,26 @@ module.exports = class ContainerPilotWatcher extends Events {
return Name !== 'containerpilot'; return Name !== 'containerpilot';
}); });
cb(null, Object.assign({}, instance, { instance.cp = {
cp: Object.assign({}, status, { status,
Services: services Services: services
}) };
}));
cb(null, instance);
}; };
const fetchStatus = (ip) => { const fetchStatus = (ip) => {
return new Promise((resolve, reject) => {
Wreck.get(`http://${ip}:9090/status`, { Wreck.get(`http://${ip}:9090/status`, {
timeout: 2000, // 2 seconds timeout: 2000, // 2 seconds
json: 'force' json: 'force'
}, (err, res, status) => { }, (err, res, status) => {
if (err) { if (err) {
this.emit('error', err); return reject(err);
return cb();
} }
handleStatus(status); resolve(status);
});
}); });
}; };
@ -159,11 +161,21 @@ module.exports = class ContainerPilotWatcher extends Events {
return cb(); return cb();
} }
if (!machine) { if (!machine || !Array.isArray(machine.ips)) {
return cb(); return cb(null, instance);
} }
fetchStatus(machine.primaryIp); machine.ips.find(async (ip) => {
try {
const status = await fetchStatus(ip);
return handleStatus(status);
} catch (ex) {
this.emit('error', err);
return;
}
});
return cb(null, instance);
}); });
} }
@ -288,11 +300,7 @@ module.exports = class ContainerPilotWatcher extends Events {
} }
static _resolveInstanceHealth ({ name }, instance) { static _resolveInstanceHealth ({ name }, instance) {
if (!instance) { if (!instance || !instance.cp) {
return 'UNAVAILABLE';
}
if (!instance.cp) {
return 'UNAVAILABLE'; return 'UNAVAILABLE';
} }
@ -306,7 +314,7 @@ module.exports = class ContainerPilotWatcher extends Events {
return serviceJobs.shift().Status.toUpperCase(); return serviceJobs.shift().Status.toUpperCase();
} }
const almostJobNameRegexp = new RegExp(`${name}-.*`); const almostJobNameRegexp = new RegExp(`${name}`, 'ig');
const almostServiceJobs = jobNames.filter(({ Name }) => { const almostServiceJobs = jobNames.filter(({ Name }) => {
return almostJobNameRegexp.test(Name); return almostJobNameRegexp.test(Name);
}); });

View File

@ -1,6 +1,6 @@
{ {
"name": "portal-api", "name": "portal-api",
"version": "1.8.10", "version": "1.8.11",
"description": "", "description": "",
"main": "./lib/index.js", "main": "./lib/index.js",
"scripts": { "scripts": {

View File

@ -24,7 +24,7 @@
interval: 5 interval: 5
}, },
{ {
name: 'docker-compose-api', name: 'compose-api',
interval: 5 interval: 5
} }
] ]