test pls
This commit is contained in:
parent
d3a75c3271
commit
e6390f3f9b
2 changed files with 44 additions and 0 deletions
3
app.js
3
app.js
|
@ -5,6 +5,8 @@ var logger = require('morgan');
|
||||||
|
|
||||||
var statusRouter = require('./routes/status');
|
var statusRouter = require('./routes/status');
|
||||||
var startRouter = require('./routes/start');
|
var startRouter = require('./routes/start');
|
||||||
|
var restartRouter = require('./routes/restart');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var app = express();
|
var app = express();
|
||||||
|
@ -17,6 +19,7 @@ app.use(express.static(path.join(__dirname, 'public')));
|
||||||
|
|
||||||
app.use('/status', statusRouter);
|
app.use('/status', statusRouter);
|
||||||
app.use('/start', startRouter);
|
app.use('/start', startRouter);
|
||||||
|
app.use('/restart', restartRouter);
|
||||||
|
|
||||||
|
|
||||||
module.exports = app;
|
module.exports = app;
|
||||||
|
|
41
routes/restart.js
Normal file
41
routes/restart.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
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;
|
Loading…
Reference in a new issue