fix(scaffolder): integrate with backend
This commit is contained in:
@@ -50,7 +50,7 @@ export class CookieCutter implements TemplaterBase {
|
||||
const resultDir = await fs.promises.mkdtemp(`${options.directory}-result`);
|
||||
|
||||
await runDockerContainer({
|
||||
imageName: 'spotify/backstage-cookiecutter',
|
||||
imageName: 'backstage/cookiecutter',
|
||||
args: [
|
||||
'cookiecutter',
|
||||
'--no-input',
|
||||
|
||||
@@ -20,7 +20,7 @@ import express from 'express';
|
||||
import { PreparerBuilder, TemplaterBase, JobProcessor } from '../scaffolder';
|
||||
import { TemplateEntityV1alpha1 } from '@backstage/catalog-model';
|
||||
import Docker from 'dockerode';
|
||||
import {} from '@backstage/backend-common';
|
||||
import { InputError } from '@backstage/backend-common';
|
||||
import { StageContext } from '../scaffolder/jobs/types';
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import { GithubStorer } from '../scaffolder/stages/store/github';
|
||||
@@ -76,36 +76,22 @@ export async function createRouter(
|
||||
error: job.error,
|
||||
});
|
||||
})
|
||||
.post('/v1/jobs', async (_, res) => {
|
||||
.post('/v1/jobs', async (req, res) => {
|
||||
// TODO(blam): Create a unique job here and return the ID so that
|
||||
// The end user can poll for updates on the current job
|
||||
|
||||
// TODO(blam): Take this entity from the post body sent from the frontend
|
||||
const mockEntity: TemplateEntityV1alpha1 = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Template',
|
||||
metadata: {
|
||||
annotations: {
|
||||
'backstage.io/managed-by-location':
|
||||
'file:/Users/blam/dev/spotify/backstage/plugins/scaffolder-backend/sample-templates/react-ssr-template/template.yaml',
|
||||
},
|
||||
name: 'graphql-starter',
|
||||
title: 'GraphQL Service',
|
||||
description:
|
||||
'A GraphQL starter template for backstage to get you up and running\nthe best pracices with GraphQL\n',
|
||||
uid: '9cf16bad-16e0-4213-b314-c4eec773c50b',
|
||||
etag: 'ZTkxMjUxMjUtYWY3Yi00MjU2LWFkYWMtZTZjNjU5ZjJhOWM2',
|
||||
console.log(req.body);
|
||||
const template: TemplateEntityV1alpha1 = req.body.template;
|
||||
|
||||
generation: 1,
|
||||
},
|
||||
spec: {
|
||||
type: 'cookiecutter',
|
||||
path: '.',
|
||||
},
|
||||
};
|
||||
if (!template) {
|
||||
throw new InputError(
|
||||
'You should specify the template to scaffold from',
|
||||
);
|
||||
}
|
||||
|
||||
const job = jobProcessor.create({
|
||||
entity: mockEntity,
|
||||
entity: template,
|
||||
values: {
|
||||
component_id: `blob${Date.now()}`,
|
||||
org: 'hojden',
|
||||
|
||||
@@ -44,6 +44,9 @@ export class ScaffolderApi {
|
||||
const url = `${this.apiOrigin}${this.basePath}/jobs`;
|
||||
const { id: jobId } = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ template, values }),
|
||||
}).then(x => x.json());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user