-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.ts
59 lines (49 loc) · 1.54 KB
/
build.ts
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
import { Command, flags } from '@oclif/command';
import runCompose from '../docker/runCompose';
import { dryRunFlag, verboseFlag } from '../flags';
import findProject from '../project/findProject';
export default class Build extends Command {
static description = 'build or rebuild all images';
static flags = {
help: flags.help({ char: 'h' }),
'dry-run': dryRunFlag,
parallel: flags.boolean({
allowNo: true,
default: true,
description: 'build in parallel (defaults to true)',
}),
pull: flags.boolean({
allowNo: true,
default: true,
description: 'pull latest docker image versions (defaults to true)',
}),
verbose: verboseFlag,
};
static args = [];
async run() {
const { flags } = this.parse(Build);
const project = await findProject();
if (project === null || project.type !== 'compose') {
return this.error(
'Could not find a docker-compose.yml file in the current directory or any parent',
{ exit: 1 },
);
}
const buildCommand = ['build'];
if (flags.parallel) {
buildCommand.push('--parallel');
}
if (flags.pull) {
buildCommand.push('--pull');
}
const command = await runCompose(buildCommand, {
cwd: project.root,
extraFiles: ['docker-compose.cli.yml'],
});
// Output command information before execution if the verbose flag is enabled.
if (flags['verbose'] && !flags['dry-run']) {
command.dryRun();
}
return flags['dry-run'] ? command.dryRun() : command.run();
}
}