chore: allow undefined containerRunner in cookiecutter
this is only needed if the cookiecutter command is not available. Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
@@ -161,3 +161,5 @@ You can do so by including the following lines in the last step of your Dockerfi
|
||||
RUN apt-get update && apt-get install -y python3 python3-pip
|
||||
RUN pip3 install cookiecutter
|
||||
```
|
||||
|
||||
In this case, you don't have to include `containerRunner` in the action configuration.
|
||||
|
||||
@@ -15,7 +15,7 @@ import { UrlReader } from '@backstage/backend-common';
|
||||
export function createFetchCookiecutterAction(options: {
|
||||
reader: UrlReader;
|
||||
integrations: ScmIntegrations;
|
||||
containerRunner: ContainerRunner;
|
||||
containerRunner?: ContainerRunner;
|
||||
}): TemplateAction<{
|
||||
url: string;
|
||||
targetPath?: string | undefined;
|
||||
|
||||
@@ -223,4 +223,16 @@ describe('fetch:cookiecutter', () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw error if cookiecutter is not installed and containerRunner is undefined', async () => {
|
||||
commandExists.mockResolvedValue(false);
|
||||
const ccAction = createFetchCookiecutterAction({
|
||||
integrations,
|
||||
reader: mockReader,
|
||||
});
|
||||
|
||||
await expect(ccAction.handler(mockContext)).rejects.toThrow(
|
||||
/Invalid state: containerRunner cannot be undefined when cookiecutter is not installed/,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -33,9 +33,9 @@ import {
|
||||
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
|
||||
export class CookiecutterRunner {
|
||||
private readonly containerRunner: ContainerRunner;
|
||||
private readonly containerRunner?: ContainerRunner;
|
||||
|
||||
constructor({ containerRunner }: { containerRunner: ContainerRunner }) {
|
||||
constructor({ containerRunner }: { containerRunner?: ContainerRunner }) {
|
||||
this.containerRunner = containerRunner;
|
||||
}
|
||||
|
||||
@@ -101,6 +101,11 @@ export class CookiecutterRunner {
|
||||
logStream,
|
||||
});
|
||||
} else {
|
||||
if (this.containerRunner === undefined) {
|
||||
throw new Error(
|
||||
'Invalid state: containerRunner cannot be undefined when cookiecutter is not installed',
|
||||
);
|
||||
}
|
||||
await this.containerRunner.runContainer({
|
||||
imageName: imageName ?? 'spotify/backstage-cookiecutter',
|
||||
command: 'cookiecutter',
|
||||
@@ -139,7 +144,7 @@ export class CookiecutterRunner {
|
||||
export function createFetchCookiecutterAction(options: {
|
||||
reader: UrlReader;
|
||||
integrations: ScmIntegrations;
|
||||
containerRunner: ContainerRunner;
|
||||
containerRunner?: ContainerRunner;
|
||||
}) {
|
||||
const { reader, containerRunner, integrations } = options;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user