mirror of
https://github.com/yldio/copilot.git
synced 2024-12-26 20:00:05 +02:00
8295bd6882
this shall be a progressive process
59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
const DockerComposeClient = require('./vendor/docker-compose-client');
|
|
const Router = require('router');
|
|
const { createServer } = require('http');
|
|
const bodyParser = require('body-parser');
|
|
const next = require('next');
|
|
const TritonWatch = require('triton-watch');
|
|
|
|
const app = next({
|
|
dev: process.env.NODE_ENV !== 'production'
|
|
});
|
|
|
|
const tritonWatch = new TritonWatch({
|
|
frequency: 16,
|
|
triton: {
|
|
profileName: 'sw1',
|
|
configDir: '~/.triton/'
|
|
}
|
|
});
|
|
|
|
const containers = {};
|
|
const handle = app.getRequestHandler();
|
|
const client = new DockerComposeClient();
|
|
const router = Router();
|
|
|
|
router.use(bodyParser.json());
|
|
|
|
tritonWatch.on('change', container => (containers[container.id] = container));
|
|
|
|
router.get('/api/status', (req, res) => {
|
|
res.end(JSON.stringify(containers));
|
|
});
|
|
|
|
router.post('/api/provision', (req, res) => {
|
|
client
|
|
.provision({
|
|
projectName: req.body.name,
|
|
manifest: req.body.manifest
|
|
})
|
|
.then(status => res.end(JSON.stringify(status)));
|
|
});
|
|
|
|
router.post('/api/scale', (req, res) => {
|
|
client
|
|
.provision({
|
|
projectName: req.body.name,
|
|
manifest: req.body.manifest,
|
|
services: req.body.services
|
|
})
|
|
.then(status => res.end(JSON.stringify(status)));
|
|
});
|
|
|
|
tritonWatch.poll();
|
|
|
|
app.prepare().then(() =>
|
|
createServer((req, res) => {
|
|
router(req, res, () => handle(req, res));
|
|
}).listen(3000)
|
|
);
|