1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-28 06:00:06 +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:
image: joyent/copilot-frontend:1.3.4
image: joyent/copilot-frontend:1.3.5
mem_limit: 512m
labels:
- triton.cns.services=copilot
@ -81,7 +81,7 @@ frontend:
# BACKEND
#############################################################################
api:
image: joyent/copilot-api:1.8.10
image: joyent/copilot-api:1.8.11
mem_limit: 1g
expose:
- 3000
@ -94,7 +94,7 @@ api:
# Docker-compose wrapper
# Create _env file from running ./setup.sh
compose-api:
image: joyent/copilot-compose:1.1.0
image: joyent/copilot-compose:1.1.1
expose:
- 4242
env_file:

View File

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

View File

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

View File

@ -1,6 +1,6 @@
{
"name": "api",
"version": "1.8.10",
"version": "1.8.11",
"description": "",
"main": "./server.js",
"scripts": {
@ -21,7 +21,7 @@
"joi": "^10.6.0",
"joyent-cp-gql-schema": "^1.7.0",
"piloted": "^3.1.1",
"portal-api": "^1.8.10",
"portal-api": "^1.8.11",
"toppsy": "^1.1.0",
"triton": "^5.2.0"
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,7 +28,7 @@ consul:
# it is included here for demo purposes and is not required
#############################################################################
prometheus:
image: autopilotpattern/prometheus:1.7.1-r20
image: autopilotpattern/prometheus:1.7.1-r24
restart: always
mem_limit: 1g
ports:
@ -46,7 +46,7 @@ prometheus:
# FRONTEND
#############################################################################
frontend:
image: joyent/copilot-frontend:1.3.4
image: joyent/copilot-frontend:1.3.5
mem_limit: 512m
links:
- consul:consul
@ -66,7 +66,7 @@ frontend:
# BACKEND
#############################################################################
api:
image: joyent/copilot-api:1.8.10
image: joyent/copilot-api:1.8.11
mem_limit: 512m
links:
- consul:consul
@ -83,7 +83,7 @@ api:
# Docker-compose wrapper
# Create _env file from running ./setup.sh
compose-api:
image: joyent/copilot-compose:1.0.0
image: joyent/copilot-compose:1.1.1
links:
- consul:consul
expose:
@ -95,7 +95,7 @@ compose-api:
restart: always
rethinkdb:
image: autopilotpattern/rethinkdb:2.3.5r1
image: autopilotpattern/rethinkdb:2.3.5r2
restart: always
mem_limit: 1g
links:

View File

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

View File

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

View File

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

View File

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