42 lines
957 B
JavaScript
42 lines
957 B
JavaScript
|
var express = require('express');
|
||
|
var router = express.Router();
|
||
|
var docker = require('../bin/dockerode');
|
||
|
|
||
|
const registry = 'registry.cliffbreak.de/';
|
||
|
|
||
|
router.get('/:id/:image', (req, res, next) => {
|
||
|
if (req.params.image = ! null) {
|
||
|
await pullImage(req.params.image);
|
||
|
restartContainer().then(data => {
|
||
|
res.send(data);
|
||
|
});
|
||
|
|
||
|
}
|
||
|
else {
|
||
|
restartContainer(req.params.id).then(data => {
|
||
|
res.send(data);
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
|
||
|
|
||
|
function restartContainer(containername) {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
const container = docker.getContainer(containername);
|
||
|
container.restart((err, data) => {
|
||
|
resolve({ err, data });
|
||
|
});
|
||
|
})
|
||
|
}
|
||
|
|
||
|
function pullImage(image) {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
docker.pull(registry + image, (err, stream) => {
|
||
|
resolve({ err, stream });
|
||
|
});
|
||
|
})
|
||
|
}
|
||
|
|
||
|
|
||
|
module.exports = router;
|