mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-17 10:19:47 +00:00
Implement container management endpoints
This commit is contained in:
parent
8101d08433
commit
3d2f3ad94b
@ -171,9 +171,9 @@ module.exports = (application) ->
|
|||||||
api.delete '/v1/images/:name', dockerUtils.deleteImage
|
api.delete '/v1/images/:name', dockerUtils.deleteImage
|
||||||
api.get '/v1/images', dockerUtils.listImages
|
api.get '/v1/images', dockerUtils.listImages
|
||||||
api.post '/v1/containers/create', parseBody, dockerUtils.createContainer
|
api.post '/v1/containers/create', parseBody, dockerUtils.createContainer
|
||||||
api.post '/v1/containers/:id/start', dockerUtils.startContainer
|
api.post '/v1/containers/:id/start', parseBody, dockerUtils.startContainer
|
||||||
api.post '/v1/containers/:id/stop', dockerUtils.stopContainer
|
api.post '/v1/containers/:id/stop', dockerUtils.stopContainer
|
||||||
api.delete '/v1/containers/:name', dockerUtils.deleteContainer
|
api.delete '/v1/containers/:id', dockerUtils.deleteContainer
|
||||||
api.get '/v1/containers', dockerUtils.listContainers
|
api.get '/v1/containers', dockerUtils.listContainers
|
||||||
|
|
||||||
return api
|
return api
|
||||||
|
@ -244,9 +244,9 @@ do ->
|
|||||||
|
|
||||||
exports.createImage = (req, res) ->
|
exports.createImage = (req, res) ->
|
||||||
{ registry, repo, tag, fromImage, fromSrc } = req.query
|
{ registry, repo, tag, fromImage, fromSrc } = req.query
|
||||||
if fromSrc != '-'
|
if fromImage
|
||||||
res.status('422').send('Using a fromSrc other than "-" is not supported')
|
repoTag = fromImage
|
||||||
return
|
else
|
||||||
repoTag = buildRepoTag(repo, tag, registry)
|
repoTag = buildRepoTag(repo, tag, registry)
|
||||||
Promise.using lockImages(), ->
|
Promise.using lockImages(), ->
|
||||||
knex('image').insert({ repoTag })
|
knex('image').insert({ repoTag })
|
||||||
@ -277,14 +277,48 @@ do ->
|
|||||||
.catch (err) ->
|
.catch (err) ->
|
||||||
res.status(500).send(err?.message or err or 'Unknown error')
|
res.status(500).send(err?.message or err or 'Unknown error')
|
||||||
|
|
||||||
|
docker.modem.dialAsync = Promise.promisify(docker.modem.dial)
|
||||||
exports.createContainer = (req, res) ->
|
exports.createContainer = (req, res) ->
|
||||||
res.status(500).send('Not implemented')
|
Promise.using lockImages(), ->
|
||||||
|
knex('image').select().where('repoTag', req.body.Image)
|
||||||
|
.then (images) ->
|
||||||
|
throw new Error('Only images created via the Supervisor can be used for creating containers.') if images.length == 0
|
||||||
|
optsf =
|
||||||
|
path: '/containers/create?'
|
||||||
|
method: 'POST'
|
||||||
|
options: req.body
|
||||||
|
statusCodes:
|
||||||
|
200: true
|
||||||
|
201: true
|
||||||
|
404: 'no such container'
|
||||||
|
406: 'impossible to attach'
|
||||||
|
500: 'server error'
|
||||||
|
docker.modem.dialAsync(optsf)
|
||||||
|
.then (data) ->
|
||||||
|
res.json(data)
|
||||||
|
.catch (err) ->
|
||||||
|
res.status(500).send(err?.message or err or 'Unknown error')
|
||||||
|
|
||||||
exports.startContainer = (req, res) ->
|
exports.startContainer = (req, res) ->
|
||||||
res.status(500).send('Not implemented')
|
docker.getContainer(req.params.id).startAsync(req.body)
|
||||||
|
.then (data) ->
|
||||||
|
res.json(data)
|
||||||
|
.catch (err) ->
|
||||||
|
res.status(500).send(err?.message or err or 'Unknown error')
|
||||||
|
|
||||||
exports.stopContainer = (req, res) ->
|
exports.stopContainer = (req, res) ->
|
||||||
res.status(500).send('Not implemented')
|
docker.getContainer(req.params.id).stopAsync(sanitizeQuery(req.query))
|
||||||
|
.then (data) ->
|
||||||
|
res.json(data)
|
||||||
|
.catch (err) ->
|
||||||
|
res.status(500).send(err?.message or err or 'Unknown error')
|
||||||
|
|
||||||
exports.deleteContainer = (req, res) ->
|
exports.deleteContainer = (req, res) ->
|
||||||
res.status(500).send('Not implemented')
|
docker.getContainer(req.params.id).removeAsync(sanitizeQuery(req.query))
|
||||||
|
.then (data) ->
|
||||||
|
res.json(data)
|
||||||
|
.catch (err) ->
|
||||||
|
res.status(500).send(err?.message or err or 'Unknown error')
|
||||||
|
|
||||||
exports.listContainers = (req, res) ->
|
exports.listContainers = (req, res) ->
|
||||||
docker.listContainersAsync(sanitizeQuery(req.query))
|
docker.listContainersAsync(sanitizeQuery(req.query))
|
||||||
|
Loading…
Reference in New Issue
Block a user