diff --git a/.changeset/pretty-jeans-smell.md b/.changeset/pretty-jeans-smell.md new file mode 100644 index 0000000000..9092a53deb --- /dev/null +++ b/.changeset/pretty-jeans-smell.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-lighthouse-backend': patch +--- + +Added support for the [new backend system](https://backstage.io/docs/backend-system/) diff --git a/packages/backend-next/package.json b/packages/backend-next/package.json index e33db57f00..a0ff5b6384 100644 --- a/packages/backend-next/package.json +++ b/packages/backend-next/package.json @@ -37,6 +37,7 @@ "@backstage/plugin-devtools-backend": "workspace:^", "@backstage/plugin-entity-feedback-backend": "workspace:^", "@backstage/plugin-kubernetes-backend": "workspace:^", + "@backstage/plugin-lighthouse-backend": "workspace:^", "@backstage/plugin-linguist-backend": "workspace:^", "@backstage/plugin-permission-backend": "workspace:^", "@backstage/plugin-permission-common": "workspace:^", diff --git a/packages/backend-next/src/index.ts b/packages/backend-next/src/index.ts index e03e03af38..fa7561e211 100644 --- a/packages/backend-next/src/index.ts +++ b/packages/backend-next/src/index.ts @@ -38,6 +38,7 @@ import { linguistPlugin } from '@backstage/plugin-linguist-backend'; import { devtoolsPlugin } from '@backstage/plugin-devtools-backend'; import { TaskScheduleDefinition } from '@backstage/backend-tasks'; import { adrPlugin } from '@backstage/plugin-adr-backend'; +import { lighthousePlugin } from '@backstage/plugin-lighthouse-backend'; const backend = createBackend(); @@ -94,6 +95,9 @@ backend.add(searchModuleExploreCollator()); // Kubernetes backend.add(kubernetesPlugin()); +// Lighthouse +backend.add(lighthousePlugin()); + // Permissions backend.add(permissionPlugin()); backend.add(permissionModuleAllowAllPolicy()); diff --git a/plugins/lighthouse-backend/README.md b/plugins/lighthouse-backend/README.md index 2c648754b3..28845d3c73 100644 --- a/plugins/lighthouse-backend/README.md +++ b/plugins/lighthouse-backend/README.md @@ -58,6 +58,21 @@ export default async function createPlugin(env: PluginEnvironment) { + await lighthouse(lighthouseEnv) ``` +#### New Backend System + +The Lighthouse backend plugin has support for the [new backend system](https://backstage.io/docs/backend-system/), here's how you can set that up: + +In your `packages/backend/src/index.ts` make the following changes: + +```diff + import { createBackend } from '@backstage/backend-defaults'; ++ import { lighthousePlugin } from '@backstage/plugin-lighthouse-backend'; + const backend = createBackend(); + // ... other feature additions ++ backend.add(lighthousePlugin()); + backend.start(); +``` + ## Configuration You can define how often and when the scheduler should run the audits: diff --git a/plugins/lighthouse-backend/api-report.md b/plugins/lighthouse-backend/api-report.md index b8c028f3dc..5d9d948cf4 100644 --- a/plugins/lighthouse-backend/api-report.md +++ b/plugins/lighthouse-backend/api-report.md @@ -3,7 +3,8 @@ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts -import { CatalogClient } from '@backstage/catalog-client'; +import { BackendFeature } from '@backstage/backend-plugin-api'; +import { CatalogApi } from '@backstage/catalog-client'; import { Config } from '@backstage/config'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; @@ -12,7 +13,7 @@ import { TokenManager } from '@backstage/backend-common'; // @public (undocumented) export interface CreateLighthouseSchedulerOptions { // (undocumented) - catalogClient: CatalogClient; + catalogClient: CatalogApi; // (undocumented) config: Config; // (undocumented) @@ -28,5 +29,8 @@ export function createScheduler( options: CreateLighthouseSchedulerOptions, ): Promise; +// @public +export const lighthousePlugin: () => BackendFeature; + // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/lighthouse-backend/package.json b/plugins/lighthouse-backend/package.json index 03a5c6e0fc..07e24f2984 100644 --- a/plugins/lighthouse-backend/package.json +++ b/plugins/lighthouse-backend/package.json @@ -39,10 +39,12 @@ }, "dependencies": { "@backstage/backend-common": "workspace:^", + "@backstage/backend-plugin-api": "workspace:^", "@backstage/backend-tasks": "workspace:^", "@backstage/catalog-client": "workspace:^", "@backstage/catalog-model": "workspace:^", "@backstage/config": "workspace:^", + "@backstage/plugin-catalog-node": "workspace:^", "@backstage/plugin-lighthouse-common": "workspace:^", "@backstage/types": "workspace:^", "winston": "^3.2.1" diff --git a/plugins/lighthouse-backend/src/index.ts b/plugins/lighthouse-backend/src/index.ts index ee878b9214..5773beed56 100644 --- a/plugins/lighthouse-backend/src/index.ts +++ b/plugins/lighthouse-backend/src/index.ts @@ -14,4 +14,5 @@ * limitations under the License. */ -export * from './service/plugin'; +export * from './service/createScheduler'; +export { lighthousePlugin } from './plugin'; diff --git a/plugins/lighthouse-backend/src/plugin.ts b/plugins/lighthouse-backend/src/plugin.ts new file mode 100644 index 0000000000..7acbd45634 --- /dev/null +++ b/plugins/lighthouse-backend/src/plugin.ts @@ -0,0 +1,55 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { loggerToWinstonLogger } from '@backstage/backend-common'; +import { + createBackendPlugin, + coreServices, +} from '@backstage/backend-plugin-api'; +import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha'; + +import { createScheduler } from './service/createScheduler'; + +/** + * Lighthouse backend plugin + * + * @public + */ +export const lighthousePlugin = createBackendPlugin({ + pluginId: 'lighthouse', + register(env) { + env.registerInit({ + deps: { + catalogClient: catalogServiceRef, + config: coreServices.config, + logger: coreServices.logger, + scheduler: coreServices.scheduler, + tokenManager: coreServices.tokenManager, + }, + async init({ catalogClient, config, logger, scheduler, tokenManager }) { + const winstonLogger = loggerToWinstonLogger(logger); + + await createScheduler({ + catalogClient, + config, + logger: winstonLogger, + scheduler, + tokenManager, + }); + }, + }); + }, +}); diff --git a/plugins/lighthouse-backend/src/service/plugin.ts b/plugins/lighthouse-backend/src/service/createScheduler.ts similarity index 97% rename from plugins/lighthouse-backend/src/service/plugin.ts rename to plugins/lighthouse-backend/src/service/createScheduler.ts index 089f20f4ed..498e459a09 100644 --- a/plugins/lighthouse-backend/src/service/plugin.ts +++ b/plugins/lighthouse-backend/src/service/createScheduler.ts @@ -16,10 +16,7 @@ import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; -import { - CATALOG_FILTER_EXISTS, - CatalogClient, -} from '@backstage/catalog-client'; +import { CATALOG_FILTER_EXISTS, CatalogApi } from '@backstage/catalog-client'; import { Config } from '@backstage/config'; import { LighthouseRestApi } from '@backstage/plugin-lighthouse-common'; import { stringifyEntityRef } from '@backstage/catalog-model'; @@ -31,7 +28,7 @@ export interface CreateLighthouseSchedulerOptions { logger: Logger; config: Config; scheduler?: PluginTaskScheduler; - catalogClient: CatalogClient; + catalogClient: CatalogApi; tokenManager: TokenManager; } diff --git a/yarn.lock b/yarn.lock index 52a770e2b8..42dad513bc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7688,11 +7688,13 @@ __metadata: resolution: "@backstage/plugin-lighthouse-backend@workspace:plugins/lighthouse-backend" dependencies: "@backstage/backend-common": "workspace:^" + "@backstage/backend-plugin-api": "workspace:^" "@backstage/backend-tasks": "workspace:^" "@backstage/catalog-client": "workspace:^" "@backstage/catalog-model": "workspace:^" "@backstage/cli": "workspace:^" "@backstage/config": "workspace:^" + "@backstage/plugin-catalog-node": "workspace:^" "@backstage/plugin-lighthouse-common": "workspace:^" "@backstage/types": "workspace:^" winston: ^3.2.1 @@ -24977,6 +24979,7 @@ __metadata: "@backstage/plugin-devtools-backend": "workspace:^" "@backstage/plugin-entity-feedback-backend": "workspace:^" "@backstage/plugin-kubernetes-backend": "workspace:^" + "@backstage/plugin-lighthouse-backend": "workspace:^" "@backstage/plugin-linguist-backend": "workspace:^" "@backstage/plugin-permission-backend": "workspace:^" "@backstage/plugin-permission-common": "workspace:^"