From 5a91087e2de0c9e8973e9098675e19428b75e6e2 Mon Sep 17 00:00:00 2001 From: Himanshu Mishra Date: Thu, 21 Jan 2021 16:16:06 +0100 Subject: [PATCH 1/6] templates: Update Software Templates to use updated cookiecutter.storePath --- .../{{cookiecutter.component_id}}/catalog-info.yaml | 2 +- .../{{cookiecutter.component_id}}/catalog-info.yaml | 2 +- .../{{cookiecutter.component_id}}/catalog-info.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/scaffolder-backend/sample-templates/docs-template/{{cookiecutter.component_id}}/catalog-info.yaml b/plugins/scaffolder-backend/sample-templates/docs-template/{{cookiecutter.component_id}}/catalog-info.yaml index e39350e928..90b55801a6 100644 --- a/plugins/scaffolder-backend/sample-templates/docs-template/{{cookiecutter.component_id}}/catalog-info.yaml +++ b/plugins/scaffolder-backend/sample-templates/docs-template/{{cookiecutter.component_id}}/catalog-info.yaml @@ -5,7 +5,7 @@ metadata: description: {{cookiecutter.description | jsonify}} annotations: github.com/project-slug: {{cookiecutter.storePath | jsonify}} - backstage.io/techdocs-ref: github:https://github.com/{{cookiecutter.storePath}} + backstage.io/techdocs-ref: url:{{cookiecutter.storePath}} spec: type: documentation lifecycle: experimental diff --git a/plugins/scaffolder-backend/sample-templates/react-ssr-template/{{cookiecutter.component_id}}/catalog-info.yaml b/plugins/scaffolder-backend/sample-templates/react-ssr-template/{{cookiecutter.component_id}}/catalog-info.yaml index 423c8683a1..980d107c5b 100644 --- a/plugins/scaffolder-backend/sample-templates/react-ssr-template/{{cookiecutter.component_id}}/catalog-info.yaml +++ b/plugins/scaffolder-backend/sample-templates/react-ssr-template/{{cookiecutter.component_id}}/catalog-info.yaml @@ -5,7 +5,7 @@ metadata: description: {{cookiecutter.description | jsonify}} annotations: github.com/project-slug: {{cookiecutter.storePath | jsonify}} - backstage.io/techdocs-ref: github:https://github.com/{{cookiecutter.storePath}} + backstage.io/techdocs-ref: url:{{cookiecutter.storePath}} spec: type: website lifecycle: experimental diff --git a/plugins/scaffolder-backend/sample-templates/springboot-grpc-template/{{cookiecutter.component_id}}/catalog-info.yaml b/plugins/scaffolder-backend/sample-templates/springboot-grpc-template/{{cookiecutter.component_id}}/catalog-info.yaml index f4ff350d10..2addbe23da 100644 --- a/plugins/scaffolder-backend/sample-templates/springboot-grpc-template/{{cookiecutter.component_id}}/catalog-info.yaml +++ b/plugins/scaffolder-backend/sample-templates/springboot-grpc-template/{{cookiecutter.component_id}}/catalog-info.yaml @@ -5,7 +5,7 @@ metadata: description: {{cookiecutter.description | jsonify}} annotations: github.com/project-slug: {{cookiecutter.storePath | jsonify}} - backstage.io/techdocs-ref: github:https://github.com/{{cookiecutter.storePath}} + backstage.io/techdocs-ref: url:{{cookiecutter.storePath}} spec: type: service lifecycle: experimental From 51b2c3999ac18503e9caf68470b1258497ac1b18 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 21 Jan 2021 18:15:31 +0100 Subject: [PATCH 2/6] chore: moving the storePath to it's own variable as source-ref and fixing templates to use cookiecutter vars --- .../catalog-info.yaml | 4 +- .../catalog-info.yaml | 3 +- .../catalog-info.yaml | 3 +- .../stages/templater/cookiecutter.test.ts | 53 +++++++++++++++---- .../stages/templater/cookiecutter.ts | 1 + .../scaffolder/stages/templater/cra/index.ts | 4 +- .../src/scaffolder/stages/templater/types.ts | 6 ++- .../src/service/router.test.ts | 36 ++++++++----- .../scaffolder-backend/src/service/router.ts | 11 ++-- 9 files changed, 90 insertions(+), 31 deletions(-) diff --git a/plugins/scaffolder-backend/sample-templates/docs-template/{{cookiecutter.component_id}}/catalog-info.yaml b/plugins/scaffolder-backend/sample-templates/docs-template/{{cookiecutter.component_id}}/catalog-info.yaml index 90b55801a6..3464fc8d5d 100644 --- a/plugins/scaffolder-backend/sample-templates/docs-template/{{cookiecutter.component_id}}/catalog-info.yaml +++ b/plugins/scaffolder-backend/sample-templates/docs-template/{{cookiecutter.component_id}}/catalog-info.yaml @@ -3,8 +3,8 @@ kind: Component metadata: name: {{cookiecutter.component_id | jsonify}} description: {{cookiecutter.description | jsonify}} - annotations: - github.com/project-slug: {{cookiecutter.storePath | jsonify}} + github.com/project-slug: {{cookiecutter.destination.git.owner + "/" + cookiecutter.destination.git.name}} + backstage.io/source-ref: {{cookiecutter.storePath | jsonify}} backstage.io/techdocs-ref: url:{{cookiecutter.storePath}} spec: type: documentation diff --git a/plugins/scaffolder-backend/sample-templates/react-ssr-template/{{cookiecutter.component_id}}/catalog-info.yaml b/plugins/scaffolder-backend/sample-templates/react-ssr-template/{{cookiecutter.component_id}}/catalog-info.yaml index 980d107c5b..b6e152ee72 100644 --- a/plugins/scaffolder-backend/sample-templates/react-ssr-template/{{cookiecutter.component_id}}/catalog-info.yaml +++ b/plugins/scaffolder-backend/sample-templates/react-ssr-template/{{cookiecutter.component_id}}/catalog-info.yaml @@ -4,7 +4,8 @@ metadata: name: {{cookiecutter.component_id | jsonify}} description: {{cookiecutter.description | jsonify}} annotations: - github.com/project-slug: {{cookiecutter.storePath | jsonify}} + github.com/project-slug: {{cookiecutter.destination.git.owner + "/" + cookiecutter.destination.git.name}} + backstage.io/source-url: {{cookiecutter.storePath | jsonify}} backstage.io/techdocs-ref: url:{{cookiecutter.storePath}} spec: type: website diff --git a/plugins/scaffolder-backend/sample-templates/springboot-grpc-template/{{cookiecutter.component_id}}/catalog-info.yaml b/plugins/scaffolder-backend/sample-templates/springboot-grpc-template/{{cookiecutter.component_id}}/catalog-info.yaml index 2addbe23da..83e0c58d20 100644 --- a/plugins/scaffolder-backend/sample-templates/springboot-grpc-template/{{cookiecutter.component_id}}/catalog-info.yaml +++ b/plugins/scaffolder-backend/sample-templates/springboot-grpc-template/{{cookiecutter.component_id}}/catalog-info.yaml @@ -4,7 +4,8 @@ metadata: name: {{cookiecutter.component_id | jsonify}} description: {{cookiecutter.description | jsonify}} annotations: - github.com/project-slug: {{cookiecutter.storePath | jsonify}} + github.com/project-slug: {{cookiecutter.destination.git.owner + "/" + cookiecutter.destination.git.name}} + backstage.io/source-url: {{cookiecutter.storePath | jsonify}} backstage.io/techdocs-ref: url:{{cookiecutter.storePath}} spec: type: service diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/templater/cookiecutter.test.ts b/plugins/scaffolder-backend/src/scaffolder/stages/templater/cookiecutter.test.ts index 568c95a073..656abd9613 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/templater/cookiecutter.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/templater/cookiecutter.test.ts @@ -26,6 +26,7 @@ import path from 'path'; import { RunDockerContainerOptions, RunCommandOptions } from './helpers'; import { PassThrough } from 'stream'; import Docker from 'dockerode'; +import parseGitUrl from 'git-url-parse'; const commandExists = require('command-exists-promise'); @@ -56,16 +57,21 @@ describe('CookieCutter Templater', () => { const values = { owner: 'blobby', - storePath: 'backstage/end-repo', + storePath: 'https://github.com/org/repo', description: 'description', component_id: 'newthing', + destination: { + git: parseGitUrl('https://github.com/org/repo'), + }, }; await cookie.run({ directory: tempdir, values, dockerClient: mockDocker }); const cookieCutterJson = await fs.readJSON(`${tempdir}/cookiecutter.json`); - expect(cookieCutterJson).toEqual(expect.objectContaining(values)); + expect(cookieCutterJson).toEqual( + expect.objectContaining(JSON.parse(JSON.stringify(values))), + ); }); it('should merge any value that is in the cookiecutter.json path already', async () => { @@ -78,15 +84,24 @@ describe('CookieCutter Templater', () => { const values = { owner: 'blobby', - storePath: 'backstage/end-repo', + storePath: 'https://github.com/org/repo', component_id: 'something', + destination: { + git: parseGitUrl('https://github.com/org/repo'), + }, }; await cookie.run({ directory: tempdir, values, dockerClient: mockDocker }); const cookieCutterJson = await fs.readJSON(`${tempdir}/cookiecutter.json`); - expect(cookieCutterJson).toEqual({ ...existingJson, ...values }); + expect(cookieCutterJson).toEqual({ + ...existingJson, + ...values, + destination: { + git: expect.objectContaining({ organization: 'org', name: 'repo' }), + }, + }); }); it('should throw an error if the cookiecutter json is malformed and not missing', async () => { @@ -96,7 +111,10 @@ describe('CookieCutter Templater', () => { const values = { owner: 'blobby', - storePath: 'backstage/end-repo', + storePath: 'https://github.com/org/repo', + destination: { + git: parseGitUrl('https://github.com/org/repo'), + }, }; await expect( @@ -109,8 +127,11 @@ describe('CookieCutter Templater', () => { const values = { owner: 'blobby', - storePath: 'backstage/end-repo', + storePath: 'https://github.com/org/repo', component_id: 'newthing', + destination: { + git: parseGitUrl('https://github.com/org/repo'), + }, }; await cookie.run({ directory: tempdir, values, dockerClient: mockDocker }); @@ -137,8 +158,11 @@ describe('CookieCutter Templater', () => { const values = { owner: 'blobby', - storePath: 'backstage/end-repo', + storePath: 'https://github.com/org/repo', component_id: 'newthing', + destination: { + git: parseGitUrl('https://github.com/org/repo'), + }, }; const { resultDir } = await cookie.run({ @@ -157,8 +181,11 @@ describe('CookieCutter Templater', () => { const values = { owner: 'blobby', - storePath: 'backstage/end-repo', + storePath: 'https://github.com/org/repo', component_id: 'newthing', + destination: { + git: parseGitUrl('https://github.com/org/repo'), + }, }; await cookie.run({ @@ -203,8 +230,11 @@ describe('CookieCutter Templater', () => { const values = { owner: 'blobby', - storePath: 'backstage/end-repo', + storePath: 'https://github.com/org/repo', component_id: 'newthing', + destination: { + git: parseGitUrl('https://github.com/org/repo'), + }, }; await cookie.run({ @@ -243,7 +273,10 @@ describe('CookieCutter Templater', () => { directory: tempdir, values: { owner: 'blobby', - storePath: 'backstage/end-repo', + storePath: 'https://github.com/org/repo', + destination: { + git: parseGitUrl('https://github.com/org/repo'), + }, }, logStream: stream, dockerClient: mockDocker, diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/templater/cookiecutter.ts b/plugins/scaffolder-backend/src/scaffolder/stages/templater/cookiecutter.ts index 7be8730bd9..7f7fd3494f 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/templater/cookiecutter.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/templater/cookiecutter.ts @@ -18,6 +18,7 @@ import { JsonValue } from '@backstage/config'; import { runDockerContainer, runCommand } from './helpers'; import { TemplaterBase, TemplaterRunOptions } from '.'; import path from 'path'; + import { TemplaterRunResult } from './types'; const commandExists = require('command-exists-promise'); diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/templater/cra/index.ts b/plugins/scaffolder-backend/src/scaffolder/stages/templater/cra/index.ts index b30e86d903..601c2375f4 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/templater/cra/index.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/templater/cra/index.ts @@ -70,7 +70,9 @@ export class CreateReactAppTemplater implements TemplaterBase { `${finalDir}/.github/workflows/main.yml`, ); - extraAnnotations[GITHUB_ACTIONS_ANNOTATION] = options.values.storePath; + extraAnnotations[ + GITHUB_ACTIONS_ANNOTATION + ] = `${options.values.destination.git.owner}/${options.values.destination.git.name}`; } const componentInfo = { diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/templater/types.ts b/plugins/scaffolder-backend/src/scaffolder/stages/templater/types.ts index 5b01960612..9d03401467 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/templater/types.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/templater/types.ts @@ -17,6 +17,7 @@ import type { Writable } from 'stream'; import Docker from 'dockerode'; import { JsonValue } from '@backstage/config'; import { TemplateEntityV1alpha1 } from '@backstage/catalog-model'; +import gitUrlParse from 'git-url-parse'; /** * Currently the required template values. The owner @@ -25,6 +26,9 @@ import { TemplateEntityV1alpha1 } from '@backstage/catalog-model'; export type RequiredTemplateValues = { owner: string; storePath: string; + destination: { + git: gitUrlParse.GitUrl; + }; }; /** @@ -42,7 +46,7 @@ export type TemplaterRunResult = { */ export type TemplaterRunOptions = { directory: string; - values: RequiredTemplateValues & Record; + values: RequiredTemplateValues & Record; logStream?: Writable; dockerClient: Docker; }; diff --git a/plugins/scaffolder-backend/src/service/router.test.ts b/plugins/scaffolder-backend/src/service/router.test.ts index 785e099c3f..59d5f4696e 100644 --- a/plugins/scaffolder-backend/src/service/router.test.ts +++ b/plugins/scaffolder-backend/src/service/router.test.ts @@ -107,10 +107,14 @@ describe('createRouter - working directory', () => { }); const app = express().use(router); - await request(app).post('/v1/jobs').send({ - templateName: '', - values: {}, - }); + await request(app) + .post('/v1/jobs') + .send({ + templateName: '', + values: { + storePath: 'https://github.com/backstage/good', + }, + }); expect(mockPrepare).toBeCalledWith(expect.anything(), { logger: expect.anything(), @@ -130,10 +134,14 @@ describe('createRouter - working directory', () => { }); const app = express().use(router); - await request(app).post('/v1/jobs').send({ - templateName: '', - values: {}, - }); + await request(app) + .post('/v1/jobs') + .send({ + templateName: '', + values: { + storePath: 'https://github.com/backstage/goodrepo', + }, + }); expect(mockPrepare).toBeCalledWith(expect.anything(), { logger: expect.anything(), @@ -200,10 +208,14 @@ describe('createRouter', () => { describe('POST /v1/jobs', () => { it('rejects template values which do not match the template schema definition', async () => { - const response = await request(app).post('/v1/jobs').send({ - templateName: '', - values: {}, - }); + const response = await request(app) + .post('/v1/jobs') + .send({ + templateName: '', + values: { + storePath: 'https://github.com/backstage/backstage', + }, + }); expect(response.status).toEqual(400); }); diff --git a/plugins/scaffolder-backend/src/service/router.ts b/plugins/scaffolder-backend/src/service/router.ts index 8af32f6c0c..e74c06ecc2 100644 --- a/plugins/scaffolder-backend/src/service/router.ts +++ b/plugins/scaffolder-backend/src/service/router.ts @@ -32,6 +32,7 @@ import { } from '../scaffolder'; import { CatalogEntityClient } from '../lib/catalog'; import { validate, ValidatorResult } from 'jsonschema'; +import parseGitUrl from 'git-url-parse'; export interface RouterOptions { preparers: PreparerBuilder; @@ -109,8 +110,13 @@ export async function createRouter( }) .post('/v1/jobs', async (req, res) => { const templateName: string = req.body.templateName; - const values: RequiredTemplateValues & Record = - req.body.values; + const values: RequiredTemplateValues & Record = { + ...req.body.values, + destination: { + git: parseGitUrl(req.body.values.storePath), + }, + }; + req.body.values; const template = await entityClient.findTemplate(templateName); @@ -123,7 +129,6 @@ export async function createRouter( res.status(400).json({ errors: validationResult.errors }); return; } - const job = jobProcessor.create({ entity: template, values, From 979bcccf23eddce2a9584a3cd9c89c501d706c22 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 21 Jan 2021 20:06:49 +0100 Subject: [PATCH 3/6] chore: fixing last of the typescripts --- .../extending/create-your-own-publisher.md | 2 +- .../extending/create-your-own-templater.md | 2 +- .../src/scaffolder/jobs/processor.test.ts | 6 +++++- .../scaffolder-backend/src/scaffolder/jobs/processor.ts | 5 ++--- plugins/scaffolder-backend/src/scaffolder/jobs/types.ts | 7 +++---- .../src/scaffolder/stages/publish/types.ts | 5 ++--- .../src/scaffolder/stages/templater/cra/index.ts | 2 +- .../src/scaffolder/stages/templater/types.ts | 9 +++++---- plugins/scaffolder-backend/src/service/router.ts | 7 +++---- 9 files changed, 23 insertions(+), 22 deletions(-) diff --git a/docs/features/software-templates/extending/create-your-own-publisher.md b/docs/features/software-templates/extending/create-your-own-publisher.md index 97854c999a..5e2809e006 100644 --- a/docs/features/software-templates/extending/create-your-own-publisher.md +++ b/docs/features/software-templates/extending/create-your-own-publisher.md @@ -57,7 +57,7 @@ That type looks like the following: export type PublisherBase = { publish(opts: { entity: TemplateEntityV1alpha1; - values: RequiredTemplateValues & Record; + values: TemplaterValues; directory: string; }): Promise<{ remoteUrl: string }>; }; diff --git a/docs/features/software-templates/extending/create-your-own-templater.md b/docs/features/software-templates/extending/create-your-own-templater.md index 19c54733b4..37e68c4153 100644 --- a/docs/features/software-templates/extending/create-your-own-templater.md +++ b/docs/features/software-templates/extending/create-your-own-templater.md @@ -61,7 +61,7 @@ That type looks like the following: ```ts export type TemplaterRunOptions = { directory: string; - values: RequiredTemplateValues & Record; + values: TemplaterValues; logStream?: Writable; dockerClient: Docker; }; diff --git a/plugins/scaffolder-backend/src/scaffolder/jobs/processor.test.ts b/plugins/scaffolder-backend/src/scaffolder/jobs/processor.test.ts index d23db937bb..eaae937337 100644 --- a/plugins/scaffolder-backend/src/scaffolder/jobs/processor.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/jobs/processor.test.ts @@ -17,6 +17,7 @@ import { JobProcessor } from './processor'; import { TemplateEntityV1alpha1 } from '@backstage/catalog-model'; import { StageInput } from './types'; import { RequiredTemplateValues } from '../stages/templater'; +import parseGitUrl from 'git-url-parse'; describe('JobProcessor', () => { const mockEntity: TemplateEntityV1alpha1 = { @@ -61,7 +62,10 @@ describe('JobProcessor', () => { const mockValues: RequiredTemplateValues = { owner: 'blobby', - storePath: 'backstage/mock-repo', + storePath: 'https://github.com/backstage/mock-repo', + destination: { + git: parseGitUrl('https://github.com/backstage/mock-repo'), + }, }; describe('create', () => { diff --git a/plugins/scaffolder-backend/src/scaffolder/jobs/processor.ts b/plugins/scaffolder-backend/src/scaffolder/jobs/processor.ts index 4ea0b4371b..b932db7fe1 100644 --- a/plugins/scaffolder-backend/src/scaffolder/jobs/processor.ts +++ b/plugins/scaffolder-backend/src/scaffolder/jobs/processor.ts @@ -14,11 +14,10 @@ * limitations under the License. */ import { Processor, Job, StageContext, StageInput } from './types'; -import { JsonValue } from '@backstage/config'; import { TemplateEntityV1alpha1 } from '@backstage/catalog-model'; import * as uuid from 'uuid'; import Docker from 'dockerode'; -import { RequiredTemplateValues, TemplaterBase } from '../stages/templater'; +import { TemplaterValues, TemplaterBase } from '../stages/templater'; import { PreparerBuilder } from '../stages/prepare'; import { makeLogStream } from './logger'; @@ -42,7 +41,7 @@ export class JobProcessor implements Processor { stages, }: { entity: TemplateEntityV1alpha1; - values: RequiredTemplateValues & Record; + values: TemplaterValues; stages: StageInput[]; }): Job { const id = uuid.v4(); diff --git a/plugins/scaffolder-backend/src/scaffolder/jobs/types.ts b/plugins/scaffolder-backend/src/scaffolder/jobs/types.ts index 73da47aed9..4d0369708c 100644 --- a/plugins/scaffolder-backend/src/scaffolder/jobs/types.ts +++ b/plugins/scaffolder-backend/src/scaffolder/jobs/types.ts @@ -15,15 +15,14 @@ */ import type { Writable } from 'stream'; import { TemplateEntityV1alpha1 } from '@backstage/catalog-model'; -import { JsonValue } from '@backstage/config'; -import { RequiredTemplateValues } from '../stages/templater'; +import { TemplaterValues } from '../stages/templater'; import { Logger } from 'winston'; // Context will be a mutable object which is passed between stages // To share data, but also thinking that we can pass in functions here too // To maybe create sub steps or fail the entire thing, or skip stages down the line. export type StageContext = { - values: RequiredTemplateValues & Record; + values: TemplaterValues; entity: TemplateEntityV1alpha1; logger: Logger; logStream: Writable; @@ -58,7 +57,7 @@ export type Processor = { stages, }: { entity: TemplateEntityV1alpha1; - values: RequiredTemplateValues & Record; + values: TemplaterValues; stages: StageInput[]; }): Job; diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/types.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/types.ts index 456e1c0ca0..fbf656206d 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/types.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/types.ts @@ -13,8 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { RequiredTemplateValues } from '../templater'; -import { JsonValue } from '@backstage/config'; +import { TemplaterValues } from '../templater'; import { Logger } from 'winston'; /** @@ -32,7 +31,7 @@ export type PublisherBase = { }; export type PublisherOptions = { - values: RequiredTemplateValues & Record; + values: TemplaterValues; directory: string; logger: Logger; }; diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/templater/cra/index.ts b/plugins/scaffolder-backend/src/scaffolder/stages/templater/cra/index.ts index 601c2375f4..f5863feb10 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/templater/cra/index.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/templater/cra/index.ts @@ -72,7 +72,7 @@ export class CreateReactAppTemplater implements TemplaterBase { extraAnnotations[ GITHUB_ACTIONS_ANNOTATION - ] = `${options.values.destination.git.owner}/${options.values.destination.git.name}`; + ] = `${options.values?.destination?.git?.owner}/${options.values?.destination?.git?.name}`; } const componentInfo = { diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/templater/types.ts b/plugins/scaffolder-backend/src/scaffolder/stages/templater/types.ts index 9d03401467..812fb972d5 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/templater/types.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/templater/types.ts @@ -15,7 +15,6 @@ */ import type { Writable } from 'stream'; import Docker from 'dockerode'; -import { JsonValue } from '@backstage/config'; import { TemplateEntityV1alpha1 } from '@backstage/catalog-model'; import gitUrlParse from 'git-url-parse'; @@ -26,11 +25,13 @@ import gitUrlParse from 'git-url-parse'; export type RequiredTemplateValues = { owner: string; storePath: string; - destination: { - git: gitUrlParse.GitUrl; + destination?: { + git?: gitUrlParse.GitUrl; }; }; +export type TemplaterValues = RequiredTemplateValues & Record; + /** * The returned directory from the templater which is ready * to pass to the next stage of the scaffolder which is publishing @@ -46,7 +47,7 @@ export type TemplaterRunResult = { */ export type TemplaterRunOptions = { directory: string; - values: RequiredTemplateValues & Record; + values: TemplaterValues; logStream?: Writable; dockerClient: Docker; }; diff --git a/plugins/scaffolder-backend/src/service/router.ts b/plugins/scaffolder-backend/src/service/router.ts index e74c06ecc2..115efc2ec4 100644 --- a/plugins/scaffolder-backend/src/service/router.ts +++ b/plugins/scaffolder-backend/src/service/router.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Config, JsonValue } from '@backstage/config'; +import { Config } from '@backstage/config'; import fs from 'fs-extra'; import Docker from 'dockerode'; import express from 'express'; @@ -23,9 +23,9 @@ import { Logger } from 'winston'; import { JobProcessor, PreparerBuilder, - RequiredTemplateValues, StageContext, TemplaterBuilder, + TemplaterValues, PublisherBuilder, parseLocationAnnotation, FilePreparer, @@ -110,13 +110,12 @@ export async function createRouter( }) .post('/v1/jobs', async (req, res) => { const templateName: string = req.body.templateName; - const values: RequiredTemplateValues & Record = { + const values: TemplaterValues = { ...req.body.values, destination: { git: parseGitUrl(req.body.values.storePath), }, }; - req.body.values; const template = await entityClient.findTemplate(templateName); From 6137dbba320a50cdbc372820c7d96a9f69eadb92 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 21 Jan 2021 20:16:17 +0100 Subject: [PATCH 4/6] chore: remove source for now --- .../{{cookiecutter.component_id}}/catalog-info.yaml | 2 +- .../{{cookiecutter.component_id}}/catalog-info.yaml | 1 - .../{{cookiecutter.component_id}}/catalog-info.yaml | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/scaffolder-backend/sample-templates/docs-template/{{cookiecutter.component_id}}/catalog-info.yaml b/plugins/scaffolder-backend/sample-templates/docs-template/{{cookiecutter.component_id}}/catalog-info.yaml index 3464fc8d5d..2f9ce4d153 100644 --- a/plugins/scaffolder-backend/sample-templates/docs-template/{{cookiecutter.component_id}}/catalog-info.yaml +++ b/plugins/scaffolder-backend/sample-templates/docs-template/{{cookiecutter.component_id}}/catalog-info.yaml @@ -3,8 +3,8 @@ kind: Component metadata: name: {{cookiecutter.component_id | jsonify}} description: {{cookiecutter.description | jsonify}} + annotations: github.com/project-slug: {{cookiecutter.destination.git.owner + "/" + cookiecutter.destination.git.name}} - backstage.io/source-ref: {{cookiecutter.storePath | jsonify}} backstage.io/techdocs-ref: url:{{cookiecutter.storePath}} spec: type: documentation diff --git a/plugins/scaffolder-backend/sample-templates/react-ssr-template/{{cookiecutter.component_id}}/catalog-info.yaml b/plugins/scaffolder-backend/sample-templates/react-ssr-template/{{cookiecutter.component_id}}/catalog-info.yaml index b6e152ee72..6197888f36 100644 --- a/plugins/scaffolder-backend/sample-templates/react-ssr-template/{{cookiecutter.component_id}}/catalog-info.yaml +++ b/plugins/scaffolder-backend/sample-templates/react-ssr-template/{{cookiecutter.component_id}}/catalog-info.yaml @@ -5,7 +5,6 @@ metadata: description: {{cookiecutter.description | jsonify}} annotations: github.com/project-slug: {{cookiecutter.destination.git.owner + "/" + cookiecutter.destination.git.name}} - backstage.io/source-url: {{cookiecutter.storePath | jsonify}} backstage.io/techdocs-ref: url:{{cookiecutter.storePath}} spec: type: website diff --git a/plugins/scaffolder-backend/sample-templates/springboot-grpc-template/{{cookiecutter.component_id}}/catalog-info.yaml b/plugins/scaffolder-backend/sample-templates/springboot-grpc-template/{{cookiecutter.component_id}}/catalog-info.yaml index 83e0c58d20..02a8a7adf2 100644 --- a/plugins/scaffolder-backend/sample-templates/springboot-grpc-template/{{cookiecutter.component_id}}/catalog-info.yaml +++ b/plugins/scaffolder-backend/sample-templates/springboot-grpc-template/{{cookiecutter.component_id}}/catalog-info.yaml @@ -5,7 +5,6 @@ metadata: description: {{cookiecutter.description | jsonify}} annotations: github.com/project-slug: {{cookiecutter.destination.git.owner + "/" + cookiecutter.destination.git.name}} - backstage.io/source-url: {{cookiecutter.storePath | jsonify}} backstage.io/techdocs-ref: url:{{cookiecutter.storePath}} spec: type: service From 0ea0023788858e9cf7e9a8a04d564853441a12cf Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 21 Jan 2021 20:20:19 +0100 Subject: [PATCH 5/6] chore(changeset): fixing changeset --- .changeset/orange-roses-visit.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/orange-roses-visit.md diff --git a/.changeset/orange-roses-visit.md b/.changeset/orange-roses-visit.md new file mode 100644 index 0000000000..0351d14859 --- /dev/null +++ b/.changeset/orange-roses-visit.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': patch +--- + +Fixing issues with templating and full URL's as `storePath`'s From 2baa2035dd71fca11aaec8b9826fca8e76d2e209 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 21 Jan 2021 21:06:42 +0100 Subject: [PATCH 6/6] chore(deps): move giturl parse to dependency --- plugins/scaffolder-backend/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/scaffolder-backend/package.json b/plugins/scaffolder-backend/package.json index dacbca54cf..914b151eeb 100644 --- a/plugins/scaffolder-backend/package.json +++ b/plugins/scaffolder-backend/package.json @@ -38,6 +38,7 @@ "@octokit/rest": "^18.0.12", "@types/dockerode": "^3.2.1", "@types/express": "^4.17.6", + "@types/git-url-parse": "^9.0.0", "azure-devops-node-api": "^10.1.1", "command-exists-promise": "^2.0.2", "compression": "^1.7.4", @@ -61,7 +62,6 @@ "@backstage/cli": "^0.4.7", "@backstage/test-utils": "^0.1.5", "@types/fs-extra": "^9.0.1", - "@types/git-url-parse": "^9.0.0", "@types/supertest": "^2.0.8", "supertest": "^4.0.2", "yaml": "^1.10.0",