diff --git a/.changeset/spotty-paws-think.md b/.changeset/spotty-paws-think.md new file mode 100644 index 0000000000..552b65d7e6 --- /dev/null +++ b/.changeset/spotty-paws-think.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Support `.npmrc` when building with private NPM registries diff --git a/packages/cli/src/commands/backend/buildImage.ts b/packages/cli/src/commands/backend/buildImage.ts index b6ae0dd579..654f51cd10 100644 --- a/packages/cli/src/commands/backend/buildImage.ts +++ b/packages/cli/src/commands/backend/buildImage.ts @@ -34,11 +34,15 @@ export default async (cmd: Command) => { const pkgPath = paths.resolveTarget(PKG_PATH); const pkg = await fs.readJson(pkgPath); const appConfigs = await findAppConfigs(); + const npmrc = (await fs.pathExists(paths.resolveTargetRoot('.npmrc'))) + ? ['.npmrc'] + : []; const tempDistWorkspace = await createDistWorkspace([pkg.name], { buildDependencies: Boolean(cmd.build), files: [ 'package.json', 'yarn.lock', + ...npmrc, ...appConfigs, { src: paths.resolveTarget('Dockerfile'), dest: 'Dockerfile' }, ], diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 2b0e3e25b9..db88c57fb1 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -55,7 +55,11 @@ export function registerCommands(program: CommanderStatic) { .helpOption(', --backstage-cli-help') // Let docker handle --help .option('--build', 'Build packages before packing them into the image') .description( - 'Bundles the package into a docker image. All extra args are forwarded to docker image build', + // TODO: Add example use cases in Backstage documentation. + // For example, if a $NPM_TOKEN needs to be exposed, run `backend:build-image --secret + // id=NPM_TOKEN,src=/NPM_TOKEN.txt`. + 'Bundles the package into a docker image. All extra args are forwarded to ' + + '`docker image build`.', ) .action(lazy(() => import('./backend/buildImage').then(m => m.default)));