From d84df12d3b03424663ffe54f6844db9a6ec58dde Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 12 Feb 2021 22:48:57 +0100 Subject: [PATCH 1/4] bug: fixing the input path to the FilePreparer, and fixing the destination directory for the preparer to template --- .../src/scaffolder/stages/prepare/file.ts | 6 +++--- plugins/scaffolder-backend/src/service/router.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.ts b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.ts index 4d49ba222e..7e4e542165 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.ts @@ -25,12 +25,12 @@ export class FilePreparer implements PreparerBase { throw new InputError(`Wrong location protocol, should be 'file', ${url}`); } - const checkoutDir = path.join(workspacePath, 'checkout'); - await fs.ensureDir(checkoutDir); + const templateDir = path.join(workspacePath, 'template'); + await fs.ensureDir(templateDir); const templatePath = fileURLToPath(url); - await fs.copy(templatePath, checkoutDir, { + await fs.copy(templatePath, templateDir, { recursive: true, }); } diff --git a/plugins/scaffolder-backend/src/service/router.ts b/plugins/scaffolder-backend/src/service/router.ts index 51425f75e8..e8aa9e7c43 100644 --- a/plugins/scaffolder-backend/src/service/router.ts +++ b/plugins/scaffolder-backend/src/service/router.ts @@ -17,7 +17,7 @@ import { Config } from '@backstage/config'; import Docker from 'dockerode'; import express from 'express'; -import { resolve as resolvePath } from 'path'; +import { resolve as resolvePath, dirname } from 'path'; import Router from 'express-promise-router'; import { Logger } from 'winston'; import { @@ -164,7 +164,7 @@ export async function createRouter( const preparer = new FilePreparer(); const path = resolvePath( - templateEntityLocation, + dirname(templateEntityLocation), template.spec.path || '.', ); From 3957c024f555e419b651b871a0833e818ebdaba8 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 12 Feb 2021 22:54:20 +0100 Subject: [PATCH 2/4] chore: renaming to use targetPath rather than templatePath like the rest of the preparers --- .../src/scaffolder/stages/prepare/file.test.ts | 6 +++--- .../src/scaffolder/stages/prepare/file.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.test.ts b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.test.ts index 0c94edce42..f6e5600a83 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.test.ts @@ -28,7 +28,7 @@ describe('File preparer', () => { const preparer = new FilePreparer(); const root = os.platform() === 'win32' ? 'C:\\' : '/'; const workspacePath = path.join(root, 'tmp'); - const checkoutPath = path.resolve(workspacePath, 'checkout'); + const targetPath = path.resolve(workspacePath, 'template'); await preparer.prepare({ url: `file:///${root}path/to/template`, @@ -37,12 +37,12 @@ describe('File preparer', () => { }); expect(fs.copy).toHaveBeenCalledWith( path.join(root, 'path', 'to', 'template'), - checkoutPath, + targetPath, { recursive: true, }, ); - expect(fs.ensureDir).toHaveBeenCalledWith(checkoutPath); + expect(fs.ensureDir).toHaveBeenCalledWith(targetPath); await expect( preparer.prepare({ diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.ts b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.ts index 7e4e542165..687cc39452 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/file.ts @@ -25,12 +25,12 @@ export class FilePreparer implements PreparerBase { throw new InputError(`Wrong location protocol, should be 'file', ${url}`); } - const templateDir = path.join(workspacePath, 'template'); - await fs.ensureDir(templateDir); + const targetDir = path.join(workspacePath, 'template'); + await fs.ensureDir(targetDir); const templatePath = fileURLToPath(url); - await fs.copy(templatePath, templateDir, { + await fs.copy(templatePath, targetDir, { recursive: true, }); } From 29c8bcc532e5f4b6b42918c0220c03be82db8585 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 12 Feb 2021 22:58:47 +0100 Subject: [PATCH 3/4] chore: added changeset --- .changeset/soft-rings-obey.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/soft-rings-obey.md diff --git a/.changeset/soft-rings-obey.md b/.changeset/soft-rings-obey.md new file mode 100644 index 0000000000..792b023785 --- /dev/null +++ b/.changeset/soft-rings-obey.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-scaffolder-backend': patch +--- + +Fixed the `prepare` step for when using local templates that were added to the catalog using the `file:` target configuration. +No more `EPERM: operation not permitted` error messages. � From 8bed34a764d33dfd2460bfdd66dbdea6d070449f Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 12 Feb 2021 23:54:57 +0100 Subject: [PATCH 4/4] chore: remove the random characters that were not artifacts of me trying to quit vim. --- .changeset/soft-rings-obey.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/soft-rings-obey.md b/.changeset/soft-rings-obey.md index 792b023785..91308bdc50 100644 --- a/.changeset/soft-rings-obey.md +++ b/.changeset/soft-rings-obey.md @@ -3,4 +3,4 @@ --- Fixed the `prepare` step for when using local templates that were added to the catalog using the `file:` target configuration. -No more `EPERM: operation not permitted` error messages. � +No more `EPERM: operation not permitted` error messages.