mirror of
https://github.com/yldio/copilot.git
synced 2024-11-28 06:00:06 +02:00
feat(portal-api): use primaryIp for health checks
This commit is contained in:
parent
1b5a2bfa9a
commit
c390a05076
@ -81,7 +81,7 @@ frontend:
|
|||||||
# BACKEND
|
# BACKEND
|
||||||
#############################################################################
|
#############################################################################
|
||||||
api:
|
api:
|
||||||
image: joyent/copilot-api:1.8.9
|
image: joyent/copilot-api:1.8.10
|
||||||
mem_limit: 1g
|
mem_limit: 1g
|
||||||
expose:
|
expose:
|
||||||
- 3000
|
- 3000
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "api",
|
"name": "api",
|
||||||
"version": "1.0.0",
|
"version": "1.8.10",
|
||||||
"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.9",
|
"portal-api": "^1.8.10",
|
||||||
"toppsy": "^1.1.0",
|
"toppsy": "^1.1.0",
|
||||||
"triton": "^5.2.0"
|
"triton": "^5.2.0"
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ frontend:
|
|||||||
# BACKEND
|
# BACKEND
|
||||||
#############################################################################
|
#############################################################################
|
||||||
api:
|
api:
|
||||||
image: joyent/copilot-api:1.8.9
|
image: joyent/copilot-api:1.8.10
|
||||||
mem_limit: 512m
|
mem_limit: 512m
|
||||||
links:
|
links:
|
||||||
- consul:consul
|
- consul:consul
|
||||||
|
@ -120,55 +120,10 @@ module.exports = class ContainerPilotWatcher extends Events {
|
|||||||
this._data.getPortal({}, getDeploymentGroups);
|
this._data.getPortal({}, getDeploymentGroups);
|
||||||
}
|
}
|
||||||
|
|
||||||
_getNetworks (networkIds = [], cb) {
|
|
||||||
VAsync.forEachParallel({
|
|
||||||
inputs: networkIds,
|
|
||||||
func: (id, next) => {
|
|
||||||
this._triton.getNetwork(id, next);
|
|
||||||
}
|
|
||||||
}, (err, results) => {
|
|
||||||
cb(err, ForceArray((results || {}).successes));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
_getPublicIps (machine, cb) {
|
|
||||||
this._getNetworks(machine.networks, (err, networks) => {
|
|
||||||
if (err) {
|
|
||||||
return cb(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
const privateNetworkSubnets = networks
|
|
||||||
.filter((network) => {
|
|
||||||
return !network['public'];
|
|
||||||
})
|
|
||||||
.map((network) => {
|
|
||||||
return network.subnet;
|
|
||||||
})
|
|
||||||
.filter(Boolean);
|
|
||||||
|
|
||||||
const cidr = new CIDRMatcher(privateNetworkSubnets);
|
|
||||||
|
|
||||||
const nonPrivateIps = machine.ips.filter((ip) => {
|
|
||||||
return !cidr.contains(ip);
|
|
||||||
});
|
|
||||||
|
|
||||||
cb(null, nonPrivateIps);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
_fetchInstanceStatus (instance, cb) {
|
_fetchInstanceStatus (instance, cb) {
|
||||||
const { machineId } = instance;
|
const { machineId } = instance;
|
||||||
|
|
||||||
const handleStatuses = (err, results) => {
|
const handleStatus = (status) => {
|
||||||
if (err) {
|
|
||||||
this.emit('error', err);
|
|
||||||
return cb();
|
|
||||||
}
|
|
||||||
|
|
||||||
const statuses = ForceArray((results || {}).successes);
|
|
||||||
|
|
||||||
const status = statuses.filter(Boolean).shift();
|
|
||||||
|
|
||||||
if (!status) {
|
if (!status) {
|
||||||
return cb(null, instance);
|
return cb(null, instance);
|
||||||
}
|
}
|
||||||
@ -184,39 +139,31 @@ module.exports = class ContainerPilotWatcher extends Events {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchStatus = (ip, next) => {
|
const fetchStatus = (ip) => {
|
||||||
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);
|
this.emit('error', err);
|
||||||
return next();
|
return cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
next(null, status);
|
handleStatus(status);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePublicIps = (err, ips) => {
|
|
||||||
if (err) {
|
|
||||||
this.emit('error', err);
|
|
||||||
return cb();
|
|
||||||
}
|
|
||||||
|
|
||||||
VAsync.forEachParallel({
|
|
||||||
inputs: ips,
|
|
||||||
func: fetchStatus
|
|
||||||
}, handleStatuses);
|
|
||||||
};
|
|
||||||
|
|
||||||
this._triton.getMachine(machineId, (err, machine) => {
|
this._triton.getMachine(machineId, (err, machine) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.emit('error', err);
|
this.emit('error', err);
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._getPublicIps(machine, handlePublicIps);
|
if (!machine) {
|
||||||
|
return cb();
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchStatus(machine.primaryIp);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "portal-api",
|
"name": "portal-api",
|
||||||
"version": "1.8.9",
|
"version": "1.8.10",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
Loading…
Reference in New Issue
Block a user