-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlist.js
More file actions
73 lines (65 loc) · 1.81 KB
/
list.js
File metadata and controls
73 lines (65 loc) · 1.81 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
67
68
69
70
71
72
73
const { reporter, exec, chalk } = require('@dhis2/cli-helpers-engine')
const Table = require('cli-table3')
const { makeComposeProject, listClusters } = require('../common.js')
const getStatus = async (cluster) =>
// TODO: check the status of the other services, not just `core`
await exec({
cmd: 'docker',
args: [
'ps',
'-a', // Include stopped containers
'--filter',
`name=${makeComposeProject(cluster.name)}_core`,
'--format',
'{{.Status}}',
],
pipe: false,
captureOut: true,
})
const formatStatus = (status) => {
status = status.trim()
if (status.length === 0) {
return chalk.grey('Down')
} else if (/\(Paused\)$/.test(status)) {
return chalk.cyan(status)
} else if (/^Up/.test(status)) {
return chalk.green(status)
} else if (/^Exited/.test(status)) {
return chalk.red(status)
} else {
return chalk.yellow(status)
}
}
const run = async function (argv) {
const clusters = await listClusters(argv)
const table = new Table({
head: [
'Name',
'Port',
'Channel',
'DHIS2 Version',
'DB Version',
'Status',
],
})
await Promise.all(
clusters.map(async (cluster) => {
const status = await getStatus(cluster)
table.push([
chalk.blue(cluster.name),
cluster.port,
cluster.channel,
cluster.dhis2Version,
cluster.dbVersion,
formatStatus(status),
])
})
)
reporter.print(table)
}
module.exports = {
command: 'list',
desc: 'List all active cluster configurations',
aliases: 'ls',
handler: run,
}