-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdown.js
More file actions
66 lines (60 loc) · 1.7 KB
/
down.js
File metadata and controls
66 lines (60 loc) · 1.7 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const path = require('path')
const { exec, reporter, chalk } = require('@dhis2/cli-helpers-engine')
const {
initDockerComposeCache,
resolveConfiguration,
makeComposeProject,
makeEnvironment,
cleanCache,
} = require('../common.js')
const run = async function (argv) {
const { name, clean, getCache } = argv
const cfg = await resolveConfiguration(argv)
const cacheLocation = await initDockerComposeCache({
composeProjectName: name,
cache: getCache(),
dockerComposeRepository: cfg.dockerComposeRepository,
dockerComposeDirectory: cfg.dockerComposeDirectory,
force: false,
})
if (!cacheLocation) {
reporter.error('Failed to initialize cache...')
process.exit(1)
}
reporter.info(`Winding down cluster ${chalk.cyan(name)}`)
try {
await exec({
cmd: 'docker-compose',
args: [
'-p',
makeComposeProject(name),
'-f',
path.join(cacheLocation, 'docker-compose.yml'),
'down',
].concat(clean ? ['--volumes'] : []),
env: makeEnvironment(cfg),
})
if (clean) {
cleanCache({
name,
cache: getCache(),
})
}
} catch (e) {
reporter.error('Failed to execute docker-compose', e)
process.exit(1)
}
}
module.exports = {
command: 'down <name>',
desc: 'Destroy a running container',
aliases: 'd',
builder: {
clean: {
desc: 'Destroy all data volumes as well as ephemeral containers',
type: 'boolean',
default: false,
},
},
handler: run,
}