From bbad7b3e9c718d5ddb41ba0d6d7e5c89140c2e31 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 15 Jan 2021 12:23:50 +0100 Subject: [PATCH 1/5] bug(create-app): updating create-app to have support for url protocol for the scaffolder --- .../templates/default-app/app-config.yaml.hbs | 10 +-- .../backend/src/plugins/scaffolder.ts | 80 +------------------ 2 files changed, 8 insertions(+), 82 deletions(-) diff --git a/packages/create-app/templates/default-app/app-config.yaml.hbs b/packages/create-app/templates/default-app/app-config.yaml.hbs index 90f272270a..d253102f71 100644 --- a/packages/create-app/templates/default-app/app-config.yaml.hbs +++ b/packages/create-app/templates/default-app/app-config.yaml.hbs @@ -88,23 +88,23 @@ catalog: target: https://github.com/backstage/backstage/blob/master/packages/catalog-model/examples/all-apis.yaml # Backstage example templates - - type: github + - type: url target: https://github.com/backstage/backstage/blob/master/plugins/scaffolder-backend/sample-templates/react-ssr-template/template.yaml rules: - allow: [Template] - - type: github + - type: url target: https://github.com/backstage/backstage/blob/master/plugins/scaffolder-backend/sample-templates/springboot-grpc-template/template.yaml rules: - allow: [Template] - - type: github + - type: url target: https://github.com/backstage/backstage/blob/master/plugins/scaffolder-backend/sample-templates/create-react-app/template.yaml rules: - allow: [Template] - - type: github + - type: url target: https://github.com/spotify/cookiecutter-golang/blob/master/template.yaml rules: - allow: [Template] - - type: github + - type: url target: https://github.com/backstage/backstage/blob/master/plugins/scaffolder-backend/sample-templates/docs-template/template.yaml rules: - allow: [Template] diff --git a/packages/create-app/templates/default-app/packages/backend/src/plugins/scaffolder.ts b/packages/create-app/templates/default-app/packages/backend/src/plugins/scaffolder.ts index 2dc69feb45..e6b8ad96fc 100644 --- a/packages/create-app/templates/default-app/packages/backend/src/plugins/scaffolder.ts +++ b/packages/create-app/templates/default-app/packages/backend/src/plugins/scaffolder.ts @@ -1,21 +1,13 @@ import { CookieCutter, createRouter, - FilePreparer, - GithubPreparer, - GitlabPreparer, Preparers, Publishers, - GithubPublisher, - GitlabPublisher, CreateReactAppTemplater, Templaters, - RepoVisibilityOptions, CatalogEntityClient, } from '@backstage/plugin-scaffolder-backend'; import { SingleHostDiscovery } from '@backstage/backend-common'; -import { Octokit } from '@octokit/rest'; -import { Gitlab } from '@gitbeaker/node'; import type { PluginEnvironment } from '../types'; import Docker from 'dockerode'; @@ -29,74 +21,8 @@ export default async function createPlugin({ templaters.register('cookiecutter', cookiecutterTemplater); templaters.register('cra', craTemplater); - const filePreparer = new FilePreparer(); - const githubPreparer = new GithubPreparer(); - const gitlabPreparer = new GitlabPreparer(config); - const preparers = new Preparers(); - - preparers.register('file', filePreparer); - preparers.register('github', githubPreparer); - preparers.register('gitlab', gitlabPreparer); - preparers.register('gitlab/api', gitlabPreparer); - - const publishers = new Publishers(); - - const githubConfig = config.getOptionalConfig('scaffolder.github'); - - if (githubConfig) { - try { - const repoVisibility = githubConfig.getString( - 'visibility', - ) as RepoVisibilityOptions; - - const githubToken = githubConfig.getString('token'); - const githubHost = githubConfig.getOptionalString('host'); - const githubClient = new Octokit({ auth: githubToken, baseUrl: githubHost }); - const githubPublisher = new GithubPublisher({ - client: githubClient, - token: githubToken, - repoVisibility, - }); - publishers.register('file', githubPublisher); - publishers.register('github', githubPublisher); - } catch (e) { - const providerName = 'github'; - if (process.env.NODE_ENV !== 'development') { - throw new Error( - `Failed to initialize ${providerName} scaffolding provider, ${e.message}`, - ); - } - - logger.warn( - `Skipping ${providerName} scaffolding provider, ${e.message}`, - ); - } - } - - const gitLabConfig = config.getOptionalConfig('scaffolder.gitlab.api'); - if (gitLabConfig) { - try { - const gitLabToken = gitLabConfig.getString('token'); - const gitLabClient = new Gitlab({ - host: gitLabConfig.getOptionalString('baseUrl'), - token: gitLabToken, - }); - const gitLabPublisher = new GitlabPublisher(gitLabClient, gitLabToken); - publishers.register('gitlab', gitLabPublisher); - publishers.register('gitlab/api', gitLabPublisher); - } catch (e) { - const providerName = 'gitlab'; - if (process.env.NODE_ENV !== 'development') { - throw new Error( - `Failed to initialize ${providerName} scaffolding provider, ${e.message}`, - ); - } - - logger.warn( - `Skipping ${providerName} scaffolding provider, ${e.message}`, - ); - } - } + const preparers = await Preparers.fromConfig(config, { logger }); + const publishers = await Publishers.fromConfig(config, { logger }); const dockerClient = new Docker(); @@ -112,4 +38,4 @@ export default async function createPlugin({ dockerClient, entityClient, }); -} +} \ No newline at end of file From d176671d1a8c341e53ce75d7c10745ed7522689f Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 15 Jan 2021 12:25:12 +0100 Subject: [PATCH 2/5] chore(create-app): added changeset --- .changeset/swift-baboons-refuse.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/swift-baboons-refuse.md diff --git a/.changeset/swift-baboons-refuse.md b/.changeset/swift-baboons-refuse.md new file mode 100644 index 0000000000..529d2d1258 --- /dev/null +++ b/.changeset/swift-baboons-refuse.md @@ -0,0 +1,5 @@ +--- +'@backstage/create-app': patch +--- + +use `fromConfig` for all scaffolder helpers, and use the url protocol for app-config location entries From 532b788679c634dbb70dbdc43c4574d2f4d87bed Mon Sep 17 00:00:00 2001 From: Ben Lambert Date: Fri, 15 Jan 2021 15:39:13 +0100 Subject: [PATCH 3/5] chore(create-app): new line at the end of the file! --- .../default-app/packages/backend/src/plugins/scaffolder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-app/templates/default-app/packages/backend/src/plugins/scaffolder.ts b/packages/create-app/templates/default-app/packages/backend/src/plugins/scaffolder.ts index e6b8ad96fc..196d48ec78 100644 --- a/packages/create-app/templates/default-app/packages/backend/src/plugins/scaffolder.ts +++ b/packages/create-app/templates/default-app/packages/backend/src/plugins/scaffolder.ts @@ -38,4 +38,4 @@ export default async function createPlugin({ dockerClient, entityClient, }); -} \ No newline at end of file +} From 6e02373449c58b751417be8099685bd4b1949c94 Mon Sep 17 00:00:00 2001 From: Ben Lambert Date: Fri, 15 Jan 2021 15:42:39 +0100 Subject: [PATCH 4/5] Update swift-baboons-refuse.md --- .changeset/swift-baboons-refuse.md | 50 +++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/.changeset/swift-baboons-refuse.md b/.changeset/swift-baboons-refuse.md index 529d2d1258..093fd727be 100644 --- a/.changeset/swift-baboons-refuse.md +++ b/.changeset/swift-baboons-refuse.md @@ -2,4 +2,52 @@ '@backstage/create-app': patch --- -use `fromConfig` for all scaffolder helpers, and use the url protocol for app-config location entries +use `fromConfig` for all scaffolder helpers, and use the url protocol for app-config location entries. + +To apply this change to your local installation, replace the contents of your `packages/backend/src/plugins/scaffolder.ts` with the following contents: + +```ts +import { + CookieCutter, + createRouter, + Preparers, + Publishers, + CreateReactAppTemplater, + Templaters, + CatalogEntityClient, +} from '@backstage/plugin-scaffolder-backend'; +import { SingleHostDiscovery } from '@backstage/backend-common'; +import type { PluginEnvironment } from '../types'; +import Docker from 'dockerode'; + +export default async function createPlugin({ + logger, + config, +}: PluginEnvironment) { + const cookiecutterTemplater = new CookieCutter(); + const craTemplater = new CreateReactAppTemplater(); + const templaters = new Templaters(); + templaters.register('cookiecutter', cookiecutterTemplater); + templaters.register('cra', craTemplater); + + const preparers = await Preparers.fromConfig(config, { logger }); + const publishers = await Publishers.fromConfig(config, { logger }); + + const dockerClient = new Docker(); + + const discovery = SingleHostDiscovery.fromConfig(config); + const entityClient = new CatalogEntityClient({ discovery }); + + return await createRouter({ + preparers, + templaters, + publishers, + logger, + config, + dockerClient, + entityClient, + }); +} +``` + +This will ensure that the `scaffolder-backend` backage can add handlers for the `url` protocol which is becoming the standard when registering entities in the `catalog` From 1012fcfb5d9f3701abe1d1aa3cbb8b18613f48ad Mon Sep 17 00:00:00 2001 From: Ben Lambert Date: Fri, 15 Jan 2021 17:26:40 +0100 Subject: [PATCH 5/5] Update .changeset/swift-baboons-refuse.md Co-authored-by: Himanshu Mishra --- .changeset/swift-baboons-refuse.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/swift-baboons-refuse.md b/.changeset/swift-baboons-refuse.md index 093fd727be..4cefb534ff 100644 --- a/.changeset/swift-baboons-refuse.md +++ b/.changeset/swift-baboons-refuse.md @@ -50,4 +50,4 @@ export default async function createPlugin({ } ``` -This will ensure that the `scaffolder-backend` backage can add handlers for the `url` protocol which is becoming the standard when registering entities in the `catalog` +This will ensure that the `scaffolder-backend` package can add handlers for the `url` protocol which is becoming the standard when registering entities in the `catalog`