From ea99ef519826278bcb2562b3d1e0a818af936024 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 25 Nov 2021 15:04:18 +0100 Subject: [PATCH 1/3] chore: added deprecation warnings and removing build-image command that has been deprecated for 6 months. think it's fine to remove this now. Co-authored-by: Johan Haals Signed-off-by: blam --- .changeset/long-spiders-bow.md | 5 + packages/cli/src/commands/app/build.ts | 9 ++ .../cli/src/commands/backend/buildImage.ts | 95 ------------------- packages/cli/src/commands/config/print.ts | 9 ++ packages/cli/src/commands/config/validate.ts | 8 ++ packages/cli/src/commands/index.ts | 28 +++--- .../commands/remove-plugin/removePlugin.ts | 6 ++ 7 files changed, 51 insertions(+), 109 deletions(-) create mode 100644 .changeset/long-spiders-bow.md delete mode 100644 packages/cli/src/commands/backend/buildImage.ts diff --git a/.changeset/long-spiders-bow.md b/.changeset/long-spiders-bow.md new file mode 100644 index 0000000000..c54641efe3 --- /dev/null +++ b/.changeset/long-spiders-bow.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': minor +--- + +Remove the `backend:build-image` command from the CLI and added more deprecation warnings to other deprecated fields like `--lax` and `remove-plugin` diff --git a/packages/cli/src/commands/app/build.ts b/packages/cli/src/commands/app/build.ts index 22e7fb9de9..434e4338fb 100644 --- a/packages/cli/src/commands/app/build.ts +++ b/packages/cli/src/commands/app/build.ts @@ -20,8 +20,17 @@ import { buildBundle } from '../../lib/bundler'; import { parseParallel, PARALLEL_ENV_VAR } from '../../lib/parallel'; import { loadCliConfig } from '../../lib/config'; import { paths } from '../../lib/paths'; +import chalk from 'chalk'; export default async (cmd: Command) => { + if (cmd.lax) { + console.warn( + chalk.yellow( + '[DEPRECATED] - The lax argument is deprecated and will be removed in the future.', + ), + ); + } + const { name } = await fs.readJson(paths.resolveTarget('package.json')); await buildBundle({ entry: 'src/index', diff --git a/packages/cli/src/commands/backend/buildImage.ts b/packages/cli/src/commands/backend/buildImage.ts deleted file mode 100644 index b352e38203..0000000000 --- a/packages/cli/src/commands/backend/buildImage.ts +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2020 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Command } from 'commander'; -import { yellow } from 'chalk'; -import fs from 'fs-extra'; -import { join as joinPath, relative as relativePath } from 'path'; -import { createDistWorkspace } from '../../lib/packager'; -import { paths } from '../../lib/paths'; -import { run } from '../../lib/run'; -import { parseParallel, PARALLEL_ENV_VAR } from '../../lib/parallel'; - -const PKG_PATH = 'package.json'; - -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; - } - - console.warn( - yellow(` -The backend:build-image command is deprecated and will be removed in the future. -Please use the backend:bundle command instead along with your own Docker setup. - - https://backstage.io/docs/deployment/docker -`), - ); - - 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' }, - ], - parallel: parseParallel(process.env[PARALLEL_ENV_VAR]), - skeleton: 'skeleton.tar', - }); - console.log(`Dist workspace ready at ${tempDistWorkspace}`); - - // all args are forwarded to docker build - await run('docker', ['image', 'build', '.', ...cmd.args], { - cwd: tempDistWorkspace, - }); - - await fs.remove(tempDistWorkspace); -}; - -/** - * Find all config files to copy into the image - */ -async function findAppConfigs(): Promise { - const files = []; - - for (const name of await fs.readdir(paths.targetRoot)) { - if (name.startsWith('app-config.') && name.endsWith('.yaml')) { - files.push(name); - } - } - - if (paths.targetRoot !== paths.targetDir) { - const dirPath = relativePath(paths.targetRoot, paths.targetDir); - - for (const name of await fs.readdir(paths.targetDir)) { - if (name.startsWith('app-config.') && name.endsWith('.yaml')) { - files.push(joinPath(dirPath, name)); - } - } - } - - return files; -} diff --git a/packages/cli/src/commands/config/print.ts b/packages/cli/src/commands/config/print.ts index b640ee4f37..4e7312b484 100644 --- a/packages/cli/src/commands/config/print.ts +++ b/packages/cli/src/commands/config/print.ts @@ -19,8 +19,17 @@ import { stringify as stringifyYaml } from 'yaml'; import { AppConfig, ConfigReader } from '@backstage/config'; import { loadCliConfig } from '../../lib/config'; import { ConfigSchema, ConfigVisibility } from '@backstage/config-loader'; +import chalk from 'chalk'; export default async (cmd: Command) => { + if (cmd.lax) { + console.warn( + chalk.yellow( + '[DEPRECATED] - The lax argument is deprecated and will be removed in the future.', + ), + ); + } + const { schema, appConfigs } = await loadCliConfig({ args: cmd.config, fromPackage: cmd.package, diff --git a/packages/cli/src/commands/config/validate.ts b/packages/cli/src/commands/config/validate.ts index 2d3ce60366..356af83c65 100644 --- a/packages/cli/src/commands/config/validate.ts +++ b/packages/cli/src/commands/config/validate.ts @@ -14,10 +14,18 @@ * limitations under the License. */ +import chalk from 'chalk'; import { Command } from 'commander'; import { loadCliConfig } from '../../lib/config'; export default async (cmd: Command) => { + if (cmd.lax) { + console.warn( + chalk.yellow( + '[DEPRECATED] - The lax argument is deprecated and will be removed in the future.', + ), + ); + } await loadCliConfig({ args: cmd.config, fromPackage: cmd.package, diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index a37d5e9ffe..daabe212ed 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -30,7 +30,11 @@ export function registerCommands(program: CommanderStatic) { .command('app:build') .description('Build an app for a production release') .option('--stats', 'Write bundle stats to output directory') - .option('--lax', 'Do not require environment variables to be set') + // Deprecated + .option( + '--lax', + '[DEPRECATED] - Do not require environment variables to be set', + ) .option(...configOption) .action(lazy(() => import('./app/build').then(m => m.default))); @@ -55,16 +59,6 @@ export function registerCommands(program: CommanderStatic) { ) .action(lazy(() => import('./backend/bundle').then(m => m.default))); - program - .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( - 'Bundles the package into a docker image. This command is deprecated and will be removed.', - ) - .action(lazy(() => import('./backend/buildImage').then(m => m.default))); - program .command('backend:dev') .description('Start local development server with HMR for the backend') @@ -115,7 +109,7 @@ export function registerCommands(program: CommanderStatic) { program .command('remove-plugin') - .description('Removes plugin in the current repository') + .description('[DEPRECATED] - Removes plugin in the current repository') .action( lazy(() => import('./remove-plugin/removePlugin').then(m => m.default)), ); @@ -178,7 +172,10 @@ export function registerCommands(program: CommanderStatic) { '--package ', 'Only load config schema that applies to the given package', ) - .option('--lax', 'Do not require environment variables to be set') + .option( + '--lax', + '[DEPRECATED] - Do not require environment variables to be set', + ) .option('--frontend', 'Print only the frontend configuration') .option('--with-secrets', 'Include secrets in the printed configuration') .option( @@ -195,7 +192,10 @@ export function registerCommands(program: CommanderStatic) { '--package ', 'Only load config schema that applies to the given package', ) - .option('--lax', 'Do not require environment variables to be set') + .option( + '--lax', + '[DEPRECATED] - Do not require environment variables to be set', + ) .option('--frontend', 'Only validate the frontend configuration') .option(...configOption) .description( diff --git a/packages/cli/src/commands/remove-plugin/removePlugin.ts b/packages/cli/src/commands/remove-plugin/removePlugin.ts index 11fdc8bb11..a82bfda36d 100644 --- a/packages/cli/src/commands/remove-plugin/removePlugin.ts +++ b/packages/cli/src/commands/remove-plugin/removePlugin.ts @@ -184,6 +184,12 @@ export const removeReferencesFromAppPackage = async ( }; export default async () => { + console.warn( + chalk.yellow( + '[DEPRECATED] - The remove-plugin command is deprecated and will be removed in the future.', + ), + ); + const questions: Question[] = [ { type: 'input', From e1aa50f9432da6313a16f814ab372d847ef2792f Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 29 Nov 2021 14:11:56 +0100 Subject: [PATCH 2/3] chore: don't deprecate lax on the config commands, and ammend the message that is logged in the console for the deprecations Signed-off-by: blam --- packages/cli/src/commands/app/build.ts | 4 +++- packages/cli/src/commands/config/print.ts | 9 --------- packages/cli/src/commands/config/validate.ts | 8 -------- packages/cli/src/commands/index.ts | 11 ++--------- 4 files changed, 5 insertions(+), 27 deletions(-) diff --git a/packages/cli/src/commands/app/build.ts b/packages/cli/src/commands/app/build.ts index 434e4338fb..104dddde01 100644 --- a/packages/cli/src/commands/app/build.ts +++ b/packages/cli/src/commands/app/build.ts @@ -26,7 +26,9 @@ export default async (cmd: Command) => { if (cmd.lax) { console.warn( chalk.yellow( - '[DEPRECATED] - The lax argument is deprecated and will be removed in the future.', + `[DEPRECATED] - The --lax option is deprecated and will be removed in the future. + Please open an issue towards https://github.com/backstage/backstage that describes your use-case if you need the flag to stay around + `, ), ); } diff --git a/packages/cli/src/commands/config/print.ts b/packages/cli/src/commands/config/print.ts index 4e7312b484..b640ee4f37 100644 --- a/packages/cli/src/commands/config/print.ts +++ b/packages/cli/src/commands/config/print.ts @@ -19,17 +19,8 @@ import { stringify as stringifyYaml } from 'yaml'; import { AppConfig, ConfigReader } from '@backstage/config'; import { loadCliConfig } from '../../lib/config'; import { ConfigSchema, ConfigVisibility } from '@backstage/config-loader'; -import chalk from 'chalk'; export default async (cmd: Command) => { - if (cmd.lax) { - console.warn( - chalk.yellow( - '[DEPRECATED] - The lax argument is deprecated and will be removed in the future.', - ), - ); - } - const { schema, appConfigs } = await loadCliConfig({ args: cmd.config, fromPackage: cmd.package, diff --git a/packages/cli/src/commands/config/validate.ts b/packages/cli/src/commands/config/validate.ts index 356af83c65..2d3ce60366 100644 --- a/packages/cli/src/commands/config/validate.ts +++ b/packages/cli/src/commands/config/validate.ts @@ -14,18 +14,10 @@ * limitations under the License. */ -import chalk from 'chalk'; import { Command } from 'commander'; import { loadCliConfig } from '../../lib/config'; export default async (cmd: Command) => { - if (cmd.lax) { - console.warn( - chalk.yellow( - '[DEPRECATED] - The lax argument is deprecated and will be removed in the future.', - ), - ); - } await loadCliConfig({ args: cmd.config, fromPackage: cmd.package, diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index daabe212ed..4eb34823ce 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -30,7 +30,6 @@ export function registerCommands(program: CommanderStatic) { .command('app:build') .description('Build an app for a production release') .option('--stats', 'Write bundle stats to output directory') - // Deprecated .option( '--lax', '[DEPRECATED] - Do not require environment variables to be set', @@ -172,10 +171,7 @@ export function registerCommands(program: CommanderStatic) { '--package ', 'Only load config schema that applies to the given package', ) - .option( - '--lax', - '[DEPRECATED] - Do not require environment variables to be set', - ) + .option('--lax', 'Do not require environment variables to be set') .option('--frontend', 'Print only the frontend configuration') .option('--with-secrets', 'Include secrets in the printed configuration') .option( @@ -192,10 +188,7 @@ export function registerCommands(program: CommanderStatic) { '--package ', 'Only load config schema that applies to the given package', ) - .option( - '--lax', - '[DEPRECATED] - Do not require environment variables to be set', - ) + .option('--lax', 'Do not require environment variables to be set') .option('--frontend', 'Only validate the frontend configuration') .option(...configOption) .description( From 7c89e7028d6bde702184ddfeb7fbf0f79eac4fb8 Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 29 Nov 2021 14:14:33 +0100 Subject: [PATCH 3/3] chore: fixing formatting of the warning message Signed-off-by: blam --- packages/cli/src/commands/app/build.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/cli/src/commands/app/build.ts b/packages/cli/src/commands/app/build.ts index 104dddde01..4fa3d1ac6e 100644 --- a/packages/cli/src/commands/app/build.ts +++ b/packages/cli/src/commands/app/build.ts @@ -26,9 +26,7 @@ export default async (cmd: Command) => { if (cmd.lax) { console.warn( chalk.yellow( - `[DEPRECATED] - The --lax option is deprecated and will be removed in the future. - Please open an issue towards https://github.com/backstage/backstage that describes your use-case if you need the flag to stay around - `, + `[DEPRECATED] - The --lax option is deprecated and will be removed in the future. Please open an issue towards https://github.com/backstage/backstage that describes your use-case if you need the flag to stay around.`, ), ); }