Introduce Lighthouse Backend with Scheduling of Audits

Signed-off-by: Dominik Pfaffenbauer <dominik@pfaffenbauer.at>
This commit is contained in:
Dominik Pfaffenbauer
2023-01-19 08:59:01 +01:00
parent 49ea9cf086
commit eef62546ce
43 changed files with 1367 additions and 190 deletions
+70
View File
@@ -0,0 +1,70 @@
# Lighthouse Backend
Lighthouse Backend allows you to run scheduled lighthouse Tests for each Website with the annotation `lighthouse.com/website-url`.
## Setup
1. Install the plugin using:
```bash
# From your Backstage root directory
yarn add --cwd packages/backend @backstage/lighthouse-backend
```
2. Create a `lighthouse.ts` file inside `packages/backend/src/plugins/`:
```typescript
import { Router } from 'express';
import { create } from '@backstage/plugin-lighthouse-backend';
import { PluginEnvironment } from '../types';
import { CatalogClient } from '@backstage/catalog-client';
export default async function createPlugin(env: PluginEnvironment) {
const { logger, scheduler, config } = env;
const catalogClient = new CatalogClient({
discoveryApi: env.discovery,
});
await create({ logger, scheduler, config, catalogClient });
}
```
3. Modify your `packages/backend/src/index.ts` to include:
```diff
...
import { Config } from '@backstage/config';
import app from './plugins/app';
+import lighthouse from './plugins/lighthouse';
import scaffolder from './plugins/scaffolder';
...
async function main() {
...
const authEnv = useHotMemoize(module, () => createEnv('auth'));
+ const lighthouseEnv = useHotMemoize(module, () => createEnv('lighthouse'));
const proxyEnv = useHotMemoize(module, () => createEnv('proxy'));
...
const apiRouter = Router();
apiRouter.use('/catalog', await catalog(catalogEnv));
apiRouter.use('/scaffolder', await scaffolder(scaffolderEnv));
+ await lighthouse(lighthouseEnv)
```
## Configuration
You can define how often and when the scheduler should run the audits:
```yaml
lighthouse:
schedule:
days: 1
```