-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
49 lines (43 loc) · 1.53 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
import { Command, Flags } from '@oclif/core';
import {
buildImage,
confirmImageNotExists,
exportImage,
maybeGetValueFromPackageFile,
} from '../utils/index.js';
export default class Build extends Command {
static description = [
'Build docker images with `build` service in `docker-compose.yaml` file.',
'It will inject `IMAGE_NAME` and `VERSION` environment variables.',
].join('\n');
static examples = [
'<%= config.bin %> <%= command.id %> # Use the `name` and `version` field of the `package.json` file in CWD.',
'<%= config.bin %> <%= command.id %> --image example # Specify image name',
'<%= config.bin %> <%= command.id %> --version 1.0.0 # Specify image version',
];
static flags = {
image: Flags.string({
description:
'Docker image name. Use the `name` field of the `package.json` file in CWD.',
}),
'no-export': Flags.boolean({
default: false,
description: "Don't export image after the docker build is successful.",
}),
version: Flags.string({
description:
'Docker image version. Use the `version` field of the `package.json` file in CWD.',
}),
};
public async run(): Promise<void> {
const { flags } = await this.parse(Build);
const name = maybeGetValueFromPackageFile('name', flags.image);
const v = maybeGetValueFromPackageFile('version', flags.version);
const image = `${name}:${v}`;
confirmImageNotExists(image);
buildImage(image);
if (!flags['no-export']) {
await exportImage(image);
}
}
}