정민우

[Add] Container start/stop 추가

......@@ -137,6 +137,7 @@ exports.listImage = async (req, res) => {
return sendError(res, 500, error.message)
}
}
exports.buildImage = async (req, res) => {
const requiredKey = ['id', 'name']
const required = checkRequiredExist(req.body, requiredKey)
......@@ -175,6 +176,7 @@ exports.buildImage = async (req, res) => {
return sendError(res, 500, error.message)
}
}
exports.removeImage = async (req, res) => {
const requiredKey = ['id']
const required = checkRequiredExist(req.body, requiredKey)
......@@ -252,15 +254,67 @@ exports.listContainer = async (req, res) => {
return sendError(res, 500, error.message)
}
}
exports.createContainer = async (req, res) => {
}
exports.startContainer = async (req, res) => {
exports.startContainer = async (req, res) => {
const requiredKey = ['id']
const required = checkRequiredExist(req.body, requiredKey)
if (required) {
logging('container', 'error', { code: 400, message: 'missingKey:${required}' }, req)
return sendError(res, 400, `missingKey:${required}`)
}
try {
const containerId = req.body.id
let container = await Image.findByPk(containerId)
if (!container) {
logging('container', 'error', { code: 404, message: 'NoContainerFound' }, req)
return sendError(res, 404, 'NoContainerFound')
}
docker.listContainers(function (err, containers) {
containers.forEach(function (containerInfo) {
if (containerInfo.names === container.name) {
docker.getContainer(containerInfo.Id).start(cb)
return sendResponse(res, containerInfo, 200)
}
})
})
} catch (error) {
logging('container', 'error', { code: 500, message: error.message }, req)
return sendError(res, 500, error.message)
}
}
exports.stopContainer = async (req, res) => {
exports.stopContainer = async (req, res) => {
const requiredKey = ['id']
const required = checkRequiredExist(req.body, requiredKey)
if (required) {
logging('container', 'error', { code: 400, message: 'missingKey:${required}' }, req)
return sendError(res, 400, `missingKey:${required}`)
}
try {
const containerId = req.body.id
let container = await Image.findByPk(containerId)
if (!container) {
logging('container', 'error', { code: 404, message: 'NoContainerFound' }, req)
return sendError(res, 404, 'NoContainerFound')
}
docker.listContainers(function (err, containers) {
containers.forEach(function (containerInfo) {
if (containerInfo.names === container.name) {
docker.getContainer(containerInfo.Id).stop(cb)
return sendResponse(res, containerInfo, 200)
}
})
})
} catch (error) {
logging('container', 'error', { code: 500, message: error.message }, req)
return sendError(res, 500, error.message)
}
}
exports.removeContainer = async (req, res) => {
const requiredKey = ['id']
const required = checkRequiredExist(req.body, requiredKey)
......