1
0
mirror of https://github.com/yldio/copilot.git synced 2024-12-01 07:30:07 +02:00
copilot/packages/docker-compose-client/lib/index.js

65 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-06-03 01:16:49 +03:00
const { Client } = require('zerorpc');
const EventEmitter = require('events');
module.exports = class DockerComposeClient extends EventEmitter {
constructor(endpoint = 'tcp://0.0.0.0:4242', timeout = 60 * 30) {
super();
this.client = new Client({
heartbeatInterval: 60 * 4 * 1000, // 4m
timeout // 30m
});
this.client.on('error', err => this.emit('error', err));
this.client.connect(endpoint);
}
_invoke(method, options, manifest, cb) {
this.client.invoke(method, options, manifest, cb);
2017-06-03 01:16:49 +03:00
}
close() {
this.client.close();
2017-06-03 01:16:49 +03:00
}
provision({ projectName, environment, manifest, files }, cb) {
2017-07-26 17:28:14 +03:00
this._invoke(
'up',
{
// eslint-disable-next-line camelcase
project_name: projectName,
files,
environment
},
manifest,
cb
);
2017-06-03 01:16:49 +03:00
}
scale({ projectName, services, environment, manifest, files }, cb) {
2017-06-03 01:16:49 +03:00
const options = {
2017-07-05 16:33:16 +03:00
environment,
2017-06-03 01:16:49 +03:00
// eslint-disable-next-line camelcase
project_name: projectName,
files,
2017-06-03 01:16:49 +03:00
services: Object.keys(services).map(name => ({
name,
num: services[name]
}))
};
this._invoke('scale', options, manifest, cb);
2017-06-03 01:16:49 +03:00
}
2017-06-08 21:43:24 +03:00
config({ projectName, environment, manifest, files }, cb) {
2017-06-08 21:43:24 +03:00
const options = {
// eslint-disable-next-line camelcase
2017-07-05 16:33:16 +03:00
project_name: projectName,
files,
2017-07-05 16:33:16 +03:00
environment
2017-06-08 21:43:24 +03:00
};
this._invoke('config', options, manifest, cb);
2017-06-08 21:43:24 +03:00
}
2017-06-03 01:16:49 +03:00
};