-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove.js
47 lines (44 loc) · 1.38 KB
/
remove.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Stops and deletes containers.
* @module lib/tasks/containers/remove
*/
'use strict'
// external
const exists = require('101/exists')
const Promise = require('bluebird')
const WorkerStopError = require('error-cat/errors/worker-stop-error')
// internal
const Docker = require('models/docker')
const log = require('logger').getChild(__filename)
const Swarm = require('models/swarm')
/**
* Task handler that removes a single container from a dock. This does not
* assume the container is stopped and will attempt to stop it.
* @param {object} job Job parameters.
* @param {string} job.dockerHost Docker host to find the container.
* @param {string} job.containerId ID of the Docker container to remove.
* @return {promise} Resolved when the container is removed.
*/
module.exports = (job) => {
return Promise
.try(() => {
if (!exists(job.dockerHost)) {
throw new WorkerStopError('dockerHost is required')
}
if (!exists(job.containerId)) {
throw new WorkerStopError('containerId is required')
}
})
.then(() => {
var swarm = new Swarm()
return swarm.checkHostExists(job.dockerHost)
})
.then(() => {
var docker = new Docker(job.dockerHost)
return docker.removeContainer(job.containerId)
})
.catch((err) => {
log.error({ err: err }, 'remove container task error, ignore')
})
.return(null)
}