Merge branch 'backend-docker' into 'master'
[Add] Container start/stop 추가 See merge request !17
Showing
1 changed file
with
56 additions
and
2 deletions
... | @@ -137,6 +137,7 @@ exports.listImage = async (req, res) => { | ... | @@ -137,6 +137,7 @@ exports.listImage = async (req, res) => { |
137 | return sendError(res, 500, error.message) | 137 | return sendError(res, 500, error.message) |
138 | } | 138 | } |
139 | } | 139 | } |
140 | + | ||
140 | exports.buildImage = async (req, res) => { | 141 | exports.buildImage = async (req, res) => { |
141 | const requiredKey = ['id', 'name'] | 142 | const requiredKey = ['id', 'name'] |
142 | const required = checkRequiredExist(req.body, requiredKey) | 143 | const required = checkRequiredExist(req.body, requiredKey) |
... | @@ -175,6 +176,7 @@ exports.buildImage = async (req, res) => { | ... | @@ -175,6 +176,7 @@ exports.buildImage = async (req, res) => { |
175 | return sendError(res, 500, error.message) | 176 | return sendError(res, 500, error.message) |
176 | } | 177 | } |
177 | } | 178 | } |
179 | + | ||
178 | exports.removeImage = async (req, res) => { | 180 | exports.removeImage = async (req, res) => { |
179 | const requiredKey = ['id'] | 181 | const requiredKey = ['id'] |
180 | const required = checkRequiredExist(req.body, requiredKey) | 182 | const required = checkRequiredExist(req.body, requiredKey) |
... | @@ -252,15 +254,67 @@ exports.listContainer = async (req, res) => { | ... | @@ -252,15 +254,67 @@ exports.listContainer = async (req, res) => { |
252 | return sendError(res, 500, error.message) | 254 | return sendError(res, 500, error.message) |
253 | } | 255 | } |
254 | } | 256 | } |
257 | + | ||
255 | exports.createContainer = async (req, res) => { | 258 | exports.createContainer = async (req, res) => { |
256 | 259 | ||
257 | } | 260 | } |
258 | -exports.startContainer = async (req, res) => { | ||
259 | 261 | ||
262 | +exports.startContainer = async (req, res) => { | ||
263 | + const requiredKey = ['id'] | ||
264 | + const required = checkRequiredExist(req.body, requiredKey) | ||
265 | + if (required) { | ||
266 | + logging('container', 'error', { code: 400, message: 'missingKey:${required}' }, req) | ||
267 | + return sendError(res, 400, `missingKey:${required}`) | ||
268 | + } | ||
269 | + try { | ||
270 | + const containerId = req.body.id | ||
271 | + let container = await Image.findByPk(containerId) | ||
272 | + if (!container) { | ||
273 | + logging('container', 'error', { code: 404, message: 'NoContainerFound' }, req) | ||
274 | + return sendError(res, 404, 'NoContainerFound') | ||
275 | + } | ||
276 | + docker.listContainers(function (err, containers) { | ||
277 | + containers.forEach(function (containerInfo) { | ||
278 | + if (containerInfo.names === container.name) { | ||
279 | + docker.getContainer(containerInfo.Id).start(cb) | ||
280 | + return sendResponse(res, containerInfo, 200) | ||
281 | + } | ||
282 | + }) | ||
283 | + }) | ||
284 | + } catch (error) { | ||
285 | + logging('container', 'error', { code: 500, message: error.message }, req) | ||
286 | + return sendError(res, 500, error.message) | ||
287 | + } | ||
260 | } | 288 | } |
261 | -exports.stopContainer = async (req, res) => { | ||
262 | 289 | ||
290 | +exports.stopContainer = async (req, res) => { | ||
291 | + const requiredKey = ['id'] | ||
292 | + const required = checkRequiredExist(req.body, requiredKey) | ||
293 | + if (required) { | ||
294 | + logging('container', 'error', { code: 400, message: 'missingKey:${required}' }, req) | ||
295 | + return sendError(res, 400, `missingKey:${required}`) | ||
296 | + } | ||
297 | + try { | ||
298 | + const containerId = req.body.id | ||
299 | + let container = await Image.findByPk(containerId) | ||
300 | + if (!container) { | ||
301 | + logging('container', 'error', { code: 404, message: 'NoContainerFound' }, req) | ||
302 | + return sendError(res, 404, 'NoContainerFound') | ||
303 | + } | ||
304 | + docker.listContainers(function (err, containers) { | ||
305 | + containers.forEach(function (containerInfo) { | ||
306 | + if (containerInfo.names === container.name) { | ||
307 | + docker.getContainer(containerInfo.Id).stop(cb) | ||
308 | + return sendResponse(res, containerInfo, 200) | ||
309 | + } | ||
310 | + }) | ||
311 | + }) | ||
312 | + } catch (error) { | ||
313 | + logging('container', 'error', { code: 500, message: error.message }, req) | ||
314 | + return sendError(res, 500, error.message) | ||
315 | + } | ||
263 | } | 316 | } |
317 | + | ||
264 | exports.removeContainer = async (req, res) => { | 318 | exports.removeContainer = async (req, res) => { |
265 | const requiredKey = ['id'] | 319 | const requiredKey = ['id'] |
266 | const required = checkRequiredExist(req.body, requiredKey) | 320 | const required = checkRequiredExist(req.body, requiredKey) | ... | ... |
-
Please register or login to post a comment