From 0b2a30deada0e2fb206906b33b96f42c71ba2877 Mon Sep 17 00:00:00 2001 From: Matteo Silvestri Date: Wed, 7 Sep 2022 15:34:47 +0200 Subject: [PATCH 001/143] fixing techdocs-cli Docker client creation Docker client does not need to be created when --no-docker option is provided. If you had DOCKER_CERT_PATH environment variable defined the Docker client was looking for certificates and breaking techdocs-cli generate command even with --no-docker option. Signed-off-by: Matteo Silvestri --- .changeset/grumpy-pans-knock.md | 14 ++++++++++++++ .../techdocs-cli/e2e-tests/techdocs-cli.test.ts | 17 +++++++++++++++++ .../src/commands/generate/generate.ts | 13 ++++++++++--- .../src/stages/generate/techdocs.ts | 6 +++--- .../techdocs-node/src/stages/generate/types.ts | 2 +- 5 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 .changeset/grumpy-pans-knock.md diff --git a/.changeset/grumpy-pans-knock.md b/.changeset/grumpy-pans-knock.md new file mode 100644 index 0000000000..74e81e7bec --- /dev/null +++ b/.changeset/grumpy-pans-knock.md @@ -0,0 +1,14 @@ +--- +'@techdocs/cli': patch +'@backstage/plugin-techdocs-node': patch +--- + +fixing techdocs-cli Docker client creation + +Docker client does not need to be created when --no-docker +option is provided. + +If you had DOCKER_CERT_PATH environment variable defined +the Docker client was looking for certificates +and breaking techdocs-cli generate command even with --no-docker +option. diff --git a/packages/techdocs-cli/e2e-tests/techdocs-cli.test.ts b/packages/techdocs-cli/e2e-tests/techdocs-cli.test.ts index e19a8cea2f..15d420af2c 100644 --- a/packages/techdocs-cli/e2e-tests/techdocs-cli.test.ts +++ b/packages/techdocs-cli/e2e-tests/techdocs-cli.test.ts @@ -89,6 +89,23 @@ describe('end-to-end', () => { expect(proc.exit).toEqual(0); }); + it('can generate with DOCKER_* TLS variables and --no-docker option', async () => { + const env = { + DOCKER_HOST: 'tcp://localhost:2376', + DOCKER_TLS_CERTDIR: '/certs', + DOCKER_TLS_VERIFY: '1', + DOCKER_CERT_PATH: '/certs/client', + ...process.env, + }; + const proc = await executeCommand(entryPoint, ['generate', '--no-docker'], { + cwd, + timeout, + env, + }); + expect(proc.stdout).toContain('Successfully generated docs'); + expect(proc.exit).toEqual(0); + }); + it('can serve in mkdocs', async () => { const proc = await executeCommand( entryPoint, diff --git a/packages/techdocs-cli/src/commands/generate/generate.ts b/packages/techdocs-cli/src/commands/generate/generate.ts index 1e4ed220d9..874b904d86 100644 --- a/packages/techdocs-cli/src/commands/generate/generate.ts +++ b/packages/techdocs-cli/src/commands/generate/generate.ts @@ -22,7 +22,10 @@ import { TechdocsGenerator, ParsedLocationAnnotation, } from '@backstage/plugin-techdocs-node'; -import { DockerContainerRunner } from '@backstage/backend-common'; +import { + ContainerRunner, + DockerContainerRunner, +} from '@backstage/backend-common'; import { ConfigReader } from '@backstage/config'; import { convertTechDocsRefToLocationAnnotation, @@ -66,8 +69,12 @@ export default async function generate(opts: OptionValues) { }); // Docker client (conditionally) used by the generators, based on techdocs.generators config. - const dockerClient = new Docker(); - const containerRunner = new DockerContainerRunner({ dockerClient }); + let containerRunner: ContainerRunner | undefined; + + if (opts.docker) { + const dockerClient = new Docker(); + containerRunner = new DockerContainerRunner({ dockerClient }); + } let parsedLocationAnnotation = {} as ParsedLocationAnnotation; if (opts.techdocsRef) { diff --git a/plugins/techdocs-node/src/stages/generate/techdocs.ts b/plugins/techdocs-node/src/stages/generate/techdocs.ts index d80449d58c..252c3b2557 100644 --- a/plugins/techdocs-node/src/stages/generate/techdocs.ts +++ b/plugins/techdocs-node/src/stages/generate/techdocs.ts @@ -55,7 +55,7 @@ export class TechdocsGenerator implements GeneratorBase { */ public static readonly defaultDockerImage = 'spotify/techdocs:v1.1.0'; private readonly logger: Logger; - private readonly containerRunner: ContainerRunner; + private readonly containerRunner?: ContainerRunner; private readonly options: GeneratorConfig; private readonly scmIntegrations: ScmIntegrationRegistry; @@ -77,7 +77,7 @@ export class TechdocsGenerator implements GeneratorBase { constructor(options: { logger: Logger; - containerRunner: ContainerRunner; + containerRunner?: ContainerRunner; config: Config; scmIntegrations: ScmIntegrationRegistry; }) { @@ -143,7 +143,7 @@ export class TechdocsGenerator implements GeneratorBase { ); break; case 'docker': - await this.containerRunner.runContainer({ + await this.containerRunner!.runContainer({ imageName: this.options.dockerImage ?? TechdocsGenerator.defaultDockerImage, args: ['build', '-d', '/output'], diff --git a/plugins/techdocs-node/src/stages/generate/types.ts b/plugins/techdocs-node/src/stages/generate/types.ts index bdbdb1095d..2b2bbb21c9 100644 --- a/plugins/techdocs-node/src/stages/generate/types.ts +++ b/plugins/techdocs-node/src/stages/generate/types.ts @@ -28,7 +28,7 @@ export type GeneratorRunInType = 'docker' | 'local'; * @public */ export type GeneratorOptions = { - containerRunner: ContainerRunner; + containerRunner?: ContainerRunner; logger: Logger; }; From 5ce28340a9214862d4be53f5505ff0ba49e425ef Mon Sep 17 00:00:00 2001 From: Matteo Silvestri Date: Wed, 7 Sep 2022 17:34:54 +0200 Subject: [PATCH 002/143] update plugins/techdocs-node api-report.md Signed-off-by: Matteo Silvestri --- plugins/techdocs-node/api-report.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/techdocs-node/api-report.md b/plugins/techdocs-node/api-report.md index 0ac8c3eaae..e27b406478 100644 --- a/plugins/techdocs-node/api-report.md +++ b/plugins/techdocs-node/api-report.md @@ -42,7 +42,7 @@ export type GeneratorBuilder = { // @public export type GeneratorOptions = { - containerRunner: ContainerRunner; + containerRunner?: ContainerRunner; logger: Logger; }; @@ -213,7 +213,7 @@ export interface TechDocsDocument extends IndexableDocument { export class TechdocsGenerator implements GeneratorBase { constructor(options: { logger: Logger; - containerRunner: ContainerRunner; + containerRunner?: ContainerRunner; config: Config; scmIntegrations: ScmIntegrationRegistry; }); From e46f8893bbe32ea30139edb679235ae64c7f487f Mon Sep 17 00:00:00 2001 From: Christian Marker / Intility AS Date: Tue, 13 Sep 2022 00:03:24 +0200 Subject: [PATCH 003/143] feat: add link buttons to bottom of template card Signed-off-by: Christian Marker / Intility AS --- .../components/TemplateCard/TemplateCard.tsx | 79 ++++++++++++++++--- 1 file changed, 66 insertions(+), 13 deletions(-) diff --git a/plugins/scaffolder/src/components/TemplateCard/TemplateCard.tsx b/plugins/scaffolder/src/components/TemplateCard/TemplateCard.tsx index df46a119f2..60de5fef85 100644 --- a/plugins/scaffolder/src/components/TemplateCard/TemplateCard.tsx +++ b/plugins/scaffolder/src/components/TemplateCard/TemplateCard.tsx @@ -15,6 +15,7 @@ */ import { Entity, + EntityLink, parseEntityRef, RELATION_OWNED_BY, stringifyEntityRef, @@ -46,6 +47,7 @@ import { useTheme, } from '@material-ui/core'; import WarningIcon from '@material-ui/icons/Warning'; +import LanguageIcon from '@material-ui/icons/Language'; import React from 'react'; import { selectedTemplateRouteRef } from '../../routes'; @@ -54,7 +56,12 @@ import { ItemCardHeader, MarkdownContent, } from '@backstage/core-components'; -import { useApi, useRouteRef } from '@backstage/core-plugin-api'; +import { + IconComponent, + useApi, + useApp, + useRouteRef, +} from '@backstage/core-plugin-api'; const useStyles = makeStyles(theme => ({ cardHeader: { @@ -69,7 +76,6 @@ const useStyles = makeStyles(theme => ({ display: '-webkit-box', '-webkit-line-clamp': 10, '-webkit-box-orient': 'vertical', - paddingBottom: '0.8em', }, label: { color: theme.palette.text.secondary, @@ -80,6 +86,14 @@ const useStyles = makeStyles(theme => ({ lineHeight: 1, paddingBottom: '0.2rem', }, + linksLabel: { + padding: '0 16px', + }, + description: { + '& p': { + margin: '0px', + }, + }, leftButton: { marginRight: 'auto', }, @@ -92,6 +106,8 @@ const useStyles = makeStyles(theme => ({ }, })); +const MuiIcon = ({ icon: Icon }: { icon: IconComponent }) => ; + const useDeprecationStyles = makeStyles(theme => ({ deprecationIcon: { position: 'absolute', @@ -115,6 +131,7 @@ type TemplateProps = { title: string; type: string; name: string; + links: EntityLink[]; }; const getTemplateCardProps = ( @@ -127,6 +144,7 @@ const getTemplateCardProps = ( type: template.spec.type ?? '', description: template.metadata.description ?? '-', tags: (template.metadata?.tags as string[]) ?? [], + links: template.metadata.links ?? [], }; }; @@ -155,6 +173,7 @@ const DeprecationWarning = () => { }; export const TemplateCard = ({ template, deprecated }: TemplateCardProps) => { + const app = useApp(); const backstageTheme = useTheme(); const templateRoute = useRouteRef(selectedTemplateRouteRef); const templateProps = getTemplateCardProps(template); @@ -170,6 +189,9 @@ export const TemplateCard = ({ template, deprecated }: TemplateCardProps) => { const { name, namespace } = parseEntityRef(stringifyEntityRef(template)); const href = templateRoute({ templateName: name, namespace }); + const iconResolver = (key?: string): IconComponent => + key ? app.getSystemIcon(key) ?? LanguageIcon : LanguageIcon; + const scmIntegrationsApi = useApi(scmIntegrationsApiRef); const sourceLocation = getEntitySourceLocation(template, scmIntegrationsApi); @@ -184,12 +206,17 @@ export const TemplateCard = ({ template, deprecated }: TemplateCardProps) => { classes={{ root: classes.title }} /> - + Description - + @@ -198,7 +225,11 @@ export const TemplateCard = ({ template, deprecated }: TemplateCardProps) => { - + Tags {templateProps.tags?.map(tag => ( @@ -206,15 +237,37 @@ export const TemplateCard = ({ template, deprecated }: TemplateCardProps) => { ))} + + Links + - {sourceLocation && ( - - - - )} +
+ {sourceLocation && ( + + + + + + )} + {templateProps.links?.map((link, i) => ( + + + + + + ))} +