/
logs.js
65 lines (59 loc) · 1.59 KB
/
logs.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const path = require('path')
const {
reporter,
exec,
tryCatchAsync,
chalk,
} = require('@dhis2/cli-helpers-engine')
const {
initDockerComposeCache,
makeComposeProject,
makeEnvironment,
resolveConfiguration,
} = require('../common')
const run = async function (argv) {
const { service, name } = argv
const cfg = await resolveConfiguration(argv)
const cacheLocation = await initDockerComposeCache({
composeProjectName: name,
cache: argv.getCache(),
dockerComposeRepository: cfg.dockerComposeRepository,
dockerComposeDirectory: cfg.dockerComposeDirectory,
force: false,
})
if (!cacheLocation) {
reporter.error('Failed to initialize cache...')
process.exit(1)
}
reporter.info(
`Reading logs from cluster version ${chalk.cyan(name)}${
service ? ` <${service}>` : ''
}`
)
const res = await tryCatchAsync(
'exec(docker-compose)',
exec({
cmd: 'docker-compose',
args: [
'-p',
makeComposeProject(name),
'-f',
path.join(cacheLocation, 'docker-compose.yml'),
'logs',
'-f',
].concat(service ? [service] : []),
env: makeEnvironment(cfg),
pipe: true,
})
)
if (res.err) {
reporter.error('Failed to read cluster logs')
process.exit(1)
}
}
module.exports = {
command: 'logs <name> [service]',
desc: 'Tail the logs from a given service',
aliases: 'l',
handler: run,
}