cli: forward all extra backend:build-image args to docker build
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "backstage-cli backend:build",
|
||||
"build-image": "backstage-cli backend:build-image example-backend",
|
||||
"build-image": "backstage-cli backend:build-image --tag example-backend",
|
||||
"start": "backstage-cli backend:dev",
|
||||
"lint": "backstage-cli lint",
|
||||
"test": "backstage-cli test",
|
||||
|
||||
@@ -18,10 +18,17 @@ import fs from 'fs-extra';
|
||||
import { createDistWorkspace } from '../../lib/packager';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { run } from '../../lib/run';
|
||||
import { Command } from 'commander';
|
||||
|
||||
const PKG_PATH = 'package.json';
|
||||
|
||||
export default async (imageTag: string) => {
|
||||
export default async (cmd: Command) => {
|
||||
// Skip the preparation steps if we're being asked for help
|
||||
if (cmd.args.includes('--help')) {
|
||||
await run('docker', ['image', 'build', '--help']);
|
||||
return;
|
||||
}
|
||||
|
||||
const pkgPath = paths.resolveTarget(PKG_PATH);
|
||||
const pkg = await fs.readJson(pkgPath);
|
||||
const tempDistWorkspace = await createDistWorkspace([pkg.name], {
|
||||
@@ -34,7 +41,8 @@ export default async (imageTag: string) => {
|
||||
});
|
||||
console.log(`Dist workspace ready at ${tempDistWorkspace}`);
|
||||
|
||||
await run('docker', ['build', '.', '-t', imageTag], {
|
||||
// all args are forwarded to docker build
|
||||
await run('docker', ['image', 'build', '.', ...cmd.args], {
|
||||
cwd: tempDistWorkspace,
|
||||
});
|
||||
|
||||
|
||||
@@ -36,9 +36,12 @@ export function registerCommands(program: CommanderStatic) {
|
||||
.action(lazy(() => import('./backend/build').then(m => m.default)));
|
||||
|
||||
program
|
||||
.command('backend:build-image <image-tag>')
|
||||
.command('backend:build-image')
|
||||
.allowUnknownOption(true)
|
||||
.helpOption(', --backstage-cli-help') // Let docker handle --help
|
||||
.option('--build', 'Build packages before packing them into the image')
|
||||
.description(
|
||||
'Builds a docker image from the package, with all local deps included',
|
||||
'Build a docker , all extra options are forwarded to docker build',
|
||||
)
|
||||
.action(lazy(() => import('./backend/buildImage').then(m => m.default)));
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "backstage-cli backend:build",
|
||||
"build-image": "backstage-cli backend:build-image example-backend",
|
||||
"build-image": "backstage-cli backend:build-image --tag example-backend",
|
||||
"start": "backstage-cli backend:dev",
|
||||
"lint": "backstage-cli lint",
|
||||
"test": "backstage-cli test",
|
||||
|
||||
Reference in New Issue
Block a user