added support to Lighthouse for new backend

Signed-off-by: Jonathan Roebuck <jroebuck@spotify.com>
This commit is contained in:
Jonathan Roebuck
2023-07-10 16:00:31 +01:00
parent ba3b7d1782
commit 402749b005
10 changed files with 91 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-lighthouse-backend': patch
---
Added support for the [new backend system](https://backstage.io/docs/backend-system/)
+1
View File
@@ -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:^",
+4
View File
@@ -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());
+17
View File
@@ -58,6 +58,23 @@ 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:
+4
View File
@@ -3,6 +3,7 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { BackendFeature } from '@backstage/backend-plugin-api';
import { CatalogClient } from '@backstage/catalog-client';
import { Config } from '@backstage/config';
import { Logger } from 'winston';
@@ -28,5 +29,8 @@ export function createScheduler(
options: CreateLighthouseSchedulerOptions,
): Promise<void>;
// @public
export const lighthousePlugin: () => BackendFeature;
// (No @packageDocumentation comment for this package)
```
+1
View File
@@ -39,6 +39,7 @@
},
"dependencies": {
"@backstage/backend-common": "workspace:^",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/backend-tasks": "workspace:^",
"@backstage/catalog-client": "workspace:^",
"@backstage/catalog-model": "workspace:^",
+2 -1
View File
@@ -14,4 +14,5 @@
* limitations under the License.
*/
export * from './service/plugin';
export * from './service/createScheduler';
export { lighthousePlugin } from './plugin';
+55
View File
@@ -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 { CatalogClient } from '@backstage/catalog-client';
import { createScheduler } from './service/createScheduler';
/**
* Lighthouse backend plugin
*
* @public
*/
export const lighthousePlugin = createBackendPlugin({
pluginId: 'lighthouse',
register(env) {
env.registerInit({
deps: {
config: coreServices.config,
discovery: coreServices.discovery,
logger: coreServices.logger,
scheduler: coreServices.scheduler,
tokenManager: coreServices.tokenManager,
},
async init({ config, discovery, logger, scheduler, tokenManager }) {
const winstonLogger = loggerToWinstonLogger(logger);
const catalogClient = new CatalogClient({ discoveryApi: discovery });
await createScheduler({
catalogClient,
config,
logger: winstonLogger,
scheduler,
tokenManager,
});
},
});
},
});
+2
View File
@@ -7688,6 +7688,7 @@ __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:^"
@@ -24977,6 +24978,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:^"