diff --git a/.changeset/popular-crabs-deny.md b/.changeset/popular-crabs-deny.md new file mode 100644 index 0000000000..28b8062d48 --- /dev/null +++ b/.changeset/popular-crabs-deny.md @@ -0,0 +1,7 @@ +--- +'@backstage/plugin-azure-devops-backend': patch +'@backstage/plugin-devtools-backend': patch +'@backstage/plugin-linguist-backend': patch +--- + +Added alpha 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 04dc3e2cf3..b8e363177b 100644 --- a/packages/backend-next/package.json +++ b/packages/backend-next/package.json @@ -26,13 +26,17 @@ }, "dependencies": { "@backstage/backend-defaults": "workspace:^", + "@backstage/backend-tasks": "workspace:^", "@backstage/plugin-app-backend": "workspace:^", "@backstage/plugin-auth-node": "workspace:^", + "@backstage/plugin-azure-devops-backend": "workspace:^", "@backstage/plugin-badges-backend": "workspace:^", "@backstage/plugin-catalog-backend": "workspace:^", "@backstage/plugin-catalog-backend-module-unprocessed": "workspace:^", + "@backstage/plugin-devtools-backend": "workspace:^", "@backstage/plugin-entity-feedback-backend": "workspace:^", "@backstage/plugin-kubernetes-backend": "workspace:^", + "@backstage/plugin-linguist-backend": "workspace:^", "@backstage/plugin-permission-backend": "workspace:^", "@backstage/plugin-permission-common": "workspace:^", "@backstage/plugin-permission-node": "workspace:^", diff --git a/packages/backend-next/src/index.ts b/packages/backend-next/src/index.ts index 60b5315ab0..7f21b23a85 100644 --- a/packages/backend-next/src/index.ts +++ b/packages/backend-next/src/index.ts @@ -33,6 +33,10 @@ import { todoPlugin } from '@backstage/plugin-todo-backend'; import { entityFeedbackPlugin } from '@backstage/plugin-entity-feedback-backend'; import { catalogModuleUnprocessedEntities } from '@backstage/plugin-catalog-backend-module-unprocessed'; import { badgesPlugin } from '@backstage/plugin-badges-backend'; +import { azureDevOpsPlugin } from '@backstage/plugin-azure-devops-backend'; +import { linguistPlugin } from '@backstage/plugin-linguist-backend'; +import { devtoolsPlugin } from '@backstage/plugin-devtools-backend'; +import { TaskScheduleDefinition } from '@backstage/backend-tasks'; const backend = createBackend(); @@ -41,9 +45,31 @@ backend.add(appPlugin({ appPackageName: 'example-app' })); // Badges backend.add(badgesPlugin()); +// Azure DevOps +backend.add(azureDevOpsPlugin()); + +// DevTools +backend.add(devtoolsPlugin()); + // Entity Feedback backend.add(entityFeedbackPlugin()); +// Linguist +const linguistSchedule: TaskScheduleDefinition = { + frequency: { minutes: 2 }, + timeout: { minutes: 15 }, + initialDelay: { seconds: 15 }, +}; + +backend.add( + linguistPlugin({ + schedule: linguistSchedule, + age: { days: 30 }, + batchSize: 2, + useSourceLocation: false, + }), +); + // Todo backend.add(todoPlugin()); diff --git a/plugins/azure-devops-backend/README.md b/plugins/azure-devops-backend/README.md index ba2a847c0a..e892b84dd1 100644 --- a/plugins/azure-devops-backend/README.md +++ b/plugins/azure-devops-backend/README.md @@ -70,6 +70,25 @@ Here's how to get the backend up and running: 4. Now run `yarn start-backend` from the repo root 5. Finally open `http://localhost:7007/api/azure-devops/health` in a browser and it should return `{"status":"ok"}` +#### New Backend System + +The Azure DevOps 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 { azureDevOpsPlugin } from '@backstage/plugin-azure-devops-backend'; + + const backend = createBackend(); + + // ... other feature additions + ++ backend.add(azureDevOpsPlugin()); + + backend.start(); +``` + ## Links - [Frontend part of the plugin](https://github.com/backstage/backstage/tree/master/plugins/azure-devops) diff --git a/plugins/azure-devops-backend/api-report.md b/plugins/azure-devops-backend/api-report.md index 900b3c3d12..a2a43cd6af 100644 --- a/plugins/azure-devops-backend/api-report.md +++ b/plugins/azure-devops-backend/api-report.md @@ -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 { Build } from 'azure-devops-node-api/interfaces/BuildInterfaces'; import { BuildDefinitionReference } from 'azure-devops-node-api/interfaces/BuildInterfaces'; import { BuildRun } from '@backstage/plugin-azure-devops-common'; @@ -94,6 +95,9 @@ export class AzureDevOpsApi { }): Promise; } +// @public +export const azureDevOpsPlugin: () => BackendFeature; + // @public (undocumented) export function createRouter(options: RouterOptions): Promise; @@ -108,6 +112,4 @@ export interface RouterOptions { // (undocumented) reader: UrlReader; } - -// (No @packageDocumentation comment for this package) ``` diff --git a/plugins/azure-devops-backend/package.json b/plugins/azure-devops-backend/package.json index 00af05df92..08411a3079 100644 --- a/plugins/azure-devops-backend/package.json +++ b/plugins/azure-devops-backend/package.json @@ -23,6 +23,7 @@ }, "dependencies": { "@backstage/backend-common": "workspace:^", + "@backstage/backend-plugin-api": "workspace:^", "@backstage/config": "workspace:^", "@backstage/plugin-azure-devops-common": "workspace:^", "@types/express": "^4.17.6", diff --git a/plugins/azure-devops-backend/src/index.ts b/plugins/azure-devops-backend/src/index.ts index 6977d3580f..c0b1276acf 100644 --- a/plugins/azure-devops-backend/src/index.ts +++ b/plugins/azure-devops-backend/src/index.ts @@ -13,5 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +/** + * Azure DevOps backend plugin that contains the API for retrieving builds, pull requests, etc. which is used by the Azure DevOps frontend plugin. + * + * @packageDocumentation + */ + export { AzureDevOpsApi } from './api'; export * from './service/router'; +export { azureDevOpsPlugin } from './plugin'; diff --git a/plugins/azure-devops-backend/src/plugin.ts b/plugins/azure-devops-backend/src/plugin.ts new file mode 100644 index 0000000000..808bdfa248 --- /dev/null +++ b/plugins/azure-devops-backend/src/plugin.ts @@ -0,0 +1,50 @@ +/* + * 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 { + coreServices, + createBackendPlugin, +} from '@backstage/backend-plugin-api'; +import { createRouter } from './service/router'; + +/** + * Azure DevOps backend plugin + * + * @public + */ +export const azureDevOpsPlugin = createBackendPlugin({ + pluginId: 'azure-devops', + register(env) { + env.registerInit({ + deps: { + config: coreServices.config, + logger: coreServices.logger, + reader: coreServices.urlReader, + httpRouter: coreServices.httpRouter, + }, + async init({ config, logger, reader, httpRouter }) { + httpRouter.use( + await createRouter({ + config, + logger: loggerToWinstonLogger(logger), + reader, + }), + ); + }, + }); + }, +}); diff --git a/plugins/devtools-backend/README.md b/plugins/devtools-backend/README.md index 7304ce33d7..528e864783 100644 --- a/plugins/devtools-backend/README.md +++ b/plugins/devtools-backend/README.md @@ -49,7 +49,26 @@ Here's how to get the DevTools Backend up and running: 4. Now run `yarn start-backend` from the repo root 5. Finally open `http://localhost:7007/api/devtools/health` in a browser and it should return `{"status":"ok"}` +### New Backend System + +The DevTools 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 { devtoolsPlugin } from '@backstage/plugin-devtools-backend'; + + const backend = createBackend(); + + // ... other feature additions + ++ backend.add(devtoolsPlugin()); + + backend.start(); +``` + ## Links -- [Frontend part of the plugin](../devtools/README.md) +- [Frontend part of the plugin](https://github.com/backstage/backstage/tree/master/plugins/devtools) - [The Backstage homepage](https://backstage.io) diff --git a/plugins/devtools-backend/api-report.md b/plugins/devtools-backend/api-report.md index e28f0697ab..dc51fc8387 100644 --- a/plugins/devtools-backend/api-report.md +++ b/plugins/devtools-backend/api-report.md @@ -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 { Config } from '@backstage/config'; import { ConfigInfo } from '@backstage/plugin-devtools-common'; import { DevToolsInfo } from '@backstage/plugin-devtools-common'; @@ -25,6 +26,9 @@ export class DevToolsBackendApi { listInfo(): Promise; } +// @public +export const devtoolsPlugin: () => BackendFeature; + // @public (undocumented) export interface RouterOptions { // (undocumented) diff --git a/plugins/devtools-backend/package.json b/plugins/devtools-backend/package.json index ba8529e650..388eccfa9e 100644 --- a/plugins/devtools-backend/package.json +++ b/plugins/devtools-backend/package.json @@ -23,6 +23,7 @@ }, "dependencies": { "@backstage/backend-common": "workspace:^", + "@backstage/backend-plugin-api": "workspace:^", "@backstage/cli-common": "workspace:^", "@backstage/config": "workspace:^", "@backstage/config-loader": "workspace:^", diff --git a/plugins/devtools-backend/src/index.ts b/plugins/devtools-backend/src/index.ts index e1545e0022..57c1739c34 100644 --- a/plugins/devtools-backend/src/index.ts +++ b/plugins/devtools-backend/src/index.ts @@ -22,3 +22,4 @@ export { DevToolsBackendApi } from './api'; export * from './service/router'; +export { devtoolsPlugin } from './plugin'; diff --git a/plugins/devtools-backend/src/plugin.ts b/plugins/devtools-backend/src/plugin.ts new file mode 100644 index 0000000000..01e03e3609 --- /dev/null +++ b/plugins/devtools-backend/src/plugin.ts @@ -0,0 +1,50 @@ +/* + * 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 { + coreServices, + createBackendPlugin, +} from '@backstage/backend-plugin-api'; +import { createRouter } from './service/router'; + +/** + * DevTools backend plugin + * + * @public + */ +export const devtoolsPlugin = createBackendPlugin({ + pluginId: 'devtools', + register(env) { + env.registerInit({ + deps: { + config: coreServices.config, + logger: coreServices.logger, + permissions: coreServices.permissions, + httpRouter: coreServices.httpRouter, + }, + async init({ config, logger, permissions, httpRouter }) { + httpRouter.use( + await createRouter({ + config, + logger: loggerToWinstonLogger(logger), + permissions, + }), + ); + }, + }); + }, +}); diff --git a/plugins/linguist-backend/README.md b/plugins/linguist-backend/README.md index 6cfd3800b6..6e2a20cf2d 100644 --- a/plugins/linguist-backend/README.md +++ b/plugins/linguist-backend/README.md @@ -56,6 +56,38 @@ Here's how to get the backend up and running: 4. Now run `yarn start-backend` from the repo root 5. Finally open `http://localhost:7007/api/linguist/health` in a browser and it should return `{"status":"ok"}` +#### New Backend System + +The Linguist 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 { linguistPlugin } from '@backstage/plugin-linguist-backend'; + + const backend = createBackend(); + + // ... other feature additions + ++ const linguistSchedule: TaskScheduleDefinition = { ++ frequency: { minutes: 2 }, ++ timeout: { minutes: 15 }, ++ initialDelay: { seconds: 15 }, ++ }; + ++ backend.add( ++ linguistPlugin({ ++ schedule: linguistSchedule, ++ age: { days: 30 }, ++ batchSize: 2, ++ useSourceLocation: false, ++ }), ++ ); + + backend.start(); +``` + ## Plugin Option The Linguist backend has various plugin options that you can provide to the `createRouter` function in your `packages/backend/src/plugins/linguist.ts` file that will allow you to configure various aspects of how it works. The following sections go into the details of these options @@ -114,5 +146,5 @@ return createRouter( ## Links -- [Frontend part of the plugin](../linguist/README.md) +- [Frontend part of the plugin](https://github.com/backstage/backstage/tree/master/plugins/linguist) - [The Backstage homepage](https://backstage.io) diff --git a/plugins/linguist-backend/api-report.md b/plugins/linguist-backend/api-report.md index 294d569ff7..cd2c9cb3f3 100644 --- a/plugins/linguist-backend/api-report.md +++ b/plugins/linguist-backend/api-report.md @@ -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 express from 'express'; import { HumanDuration } from '@backstage/types'; import { Languages } from '@backstage/plugin-linguist-common'; @@ -28,6 +29,25 @@ export interface LinguistBackendApi { processEntities(): Promise; } +// @public +export const linguistPlugin: (options: LinguistPluginOptions) => BackendFeature; + +// @public +export interface LinguistPluginOptions { + // (undocumented) + age?: HumanDuration; + // (undocumented) + batchSize?: number; + // (undocumented) + kind?: string[]; + // (undocumented) + linguistJsOptions?: Record; + // (undocumented) + schedule?: TaskScheduleDefinition; + // (undocumented) + useSourceLocation?: boolean; +} + // @public (undocumented) export interface PluginOptions { // (undocumented) @@ -61,6 +81,4 @@ export interface RouterOptions { // (undocumented) tokenManager: TokenManager; } - -// (No @packageDocumentation comment for this package) ``` diff --git a/plugins/linguist-backend/package.json b/plugins/linguist-backend/package.json index e4eaeb337a..0239b241d3 100644 --- a/plugins/linguist-backend/package.json +++ b/plugins/linguist-backend/package.json @@ -23,6 +23,7 @@ }, "dependencies": { "@backstage/backend-common": "workspace:^", + "@backstage/backend-plugin-api": "workspace:^", "@backstage/backend-tasks": "workspace:^", "@backstage/catalog-client": "workspace:^", "@backstage/catalog-model": "workspace:^", diff --git a/plugins/linguist-backend/src/index.ts b/plugins/linguist-backend/src/index.ts index 37ecf2d47f..6ac1c3770a 100644 --- a/plugins/linguist-backend/src/index.ts +++ b/plugins/linguist-backend/src/index.ts @@ -14,5 +14,13 @@ * limitations under the License. */ +/** + * Linguist backend plugin that contains the API for generating and retrieving language breakdown which is used by the Linguist frontend plugin. + * + * @packageDocumentation + */ + export * from './service/router'; export type { LinguistBackendApi } from './api'; +export { linguistPlugin } from './plugin'; +export type { LinguistPluginOptions } from './plugin'; diff --git a/plugins/linguist-backend/src/plugin.ts b/plugins/linguist-backend/src/plugin.ts new file mode 100644 index 0000000000..f655d6a1f4 --- /dev/null +++ b/plugins/linguist-backend/src/plugin.ts @@ -0,0 +1,87 @@ +/* + * 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 { + coreServices, + createBackendPlugin, +} from '@backstage/backend-plugin-api'; +import { createRouter } from './service/router'; +import { TaskScheduleDefinition } from '@backstage/backend-tasks'; +import { HumanDuration } from '@backstage/types'; + +/** + * Options for Linguist backend plugin + * + * @public + */ +export interface LinguistPluginOptions { + schedule?: TaskScheduleDefinition; + age?: HumanDuration; + batchSize?: number; + useSourceLocation?: boolean; + linguistJsOptions?: Record; + kind?: string[]; +} + +/** + * Linguist backend plugin + * + * @public + */ +export const linguistPlugin = createBackendPlugin( + (options: LinguistPluginOptions) => ({ + pluginId: 'linguist', + register(env) { + env.registerInit({ + deps: { + logger: coreServices.logger, + reader: coreServices.urlReader, + database: coreServices.database, + discovery: coreServices.discovery, + scheduler: coreServices.scheduler, + tokenManager: coreServices.tokenManager, + httpRouter: coreServices.httpRouter, + }, + async init({ + logger, + reader, + database, + discovery, + scheduler, + tokenManager, + httpRouter, + }) { + httpRouter.use( + await createRouter( + { + ...options, + }, + { + logger: loggerToWinstonLogger(logger), + reader, + database, + discovery, + scheduler, + tokenManager, + }, + ), + ); + }, + }); + }, + }), +); diff --git a/yarn.lock b/yarn.lock index 79561514f7..bb795ca564 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5011,6 +5011,7 @@ __metadata: resolution: "@backstage/plugin-azure-devops-backend@workspace:plugins/azure-devops-backend" dependencies: "@backstage/backend-common": "workspace:^" + "@backstage/backend-plugin-api": "workspace:^" "@backstage/cli": "workspace:^" "@backstage/config": "workspace:^" "@backstage/plugin-azure-devops-common": "workspace:^" @@ -6353,6 +6354,7 @@ __metadata: resolution: "@backstage/plugin-devtools-backend@workspace:plugins/devtools-backend" dependencies: "@backstage/backend-common": "workspace:^" + "@backstage/backend-plugin-api": "workspace:^" "@backstage/cli": "workspace:^" "@backstage/cli-common": "workspace:^" "@backstage/config": "workspace:^" @@ -7723,6 +7725,7 @@ __metadata: resolution: "@backstage/plugin-linguist-backend@workspace:plugins/linguist-backend" dependencies: "@backstage/backend-common": "workspace:^" + "@backstage/backend-plugin-api": "workspace:^" "@backstage/backend-tasks": "workspace:^" "@backstage/backend-test-utils": "workspace:^" "@backstage/catalog-client": "workspace:^" @@ -24925,14 +24928,18 @@ __metadata: resolution: "example-backend-next@workspace:packages/backend-next" dependencies: "@backstage/backend-defaults": "workspace:^" + "@backstage/backend-tasks": "workspace:^" "@backstage/cli": "workspace:^" "@backstage/plugin-app-backend": "workspace:^" "@backstage/plugin-auth-node": "workspace:^" + "@backstage/plugin-azure-devops-backend": "workspace:^" "@backstage/plugin-badges-backend": "workspace:^" "@backstage/plugin-catalog-backend": "workspace:^" "@backstage/plugin-catalog-backend-module-unprocessed": "workspace:^" + "@backstage/plugin-devtools-backend": "workspace:^" "@backstage/plugin-entity-feedback-backend": "workspace:^" "@backstage/plugin-kubernetes-backend": "workspace:^" + "@backstage/plugin-linguist-backend": "workspace:^" "@backstage/plugin-permission-backend": "workspace:^" "@backstage/plugin-permission-common": "workspace:^" "@backstage/plugin-permission-node": "workspace:^"