diff --git a/.changeset/pretty-falcons-drive.md b/.changeset/pretty-falcons-drive.md new file mode 100644 index 0000000000..7178307cfc --- /dev/null +++ b/.changeset/pretty-falcons-drive.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-adr-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 f8fa51eebc..5f22291274 100644 --- a/packages/backend-next/package.json +++ b/packages/backend-next/package.json @@ -27,6 +27,7 @@ "dependencies": { "@backstage/backend-defaults": "workspace:^", "@backstage/backend-tasks": "workspace:^", + "@backstage/plugin-adr-backend": "workspace:^", "@backstage/plugin-app-backend": "workspace:^", "@backstage/plugin-auth-node": "workspace:^", "@backstage/plugin-azure-devops-backend": "workspace:^", diff --git a/packages/backend-next/src/index.ts b/packages/backend-next/src/index.ts index 7f21b23a85..e03e03af38 100644 --- a/packages/backend-next/src/index.ts +++ b/packages/backend-next/src/index.ts @@ -37,6 +37,7 @@ 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'; +import { adrPlugin } from '@backstage/plugin-adr-backend'; const backend = createBackend(); @@ -73,6 +74,8 @@ backend.add( // Todo backend.add(todoPlugin()); +backend.add(adrPlugin()); + // Techdocs backend.add(techdocsPlugin()); diff --git a/plugins/adr-backend/README.md b/plugins/adr-backend/README.md index 4ffa9c63eb..6ce2f13ebf 100644 --- a/plugins/adr-backend/README.md +++ b/plugins/adr-backend/README.md @@ -58,6 +58,24 @@ async function main() { 4. Now run `yarn start-backend` from the repo root +### New Backend System + +The ADR 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 { adrPlugin } from '@backstage/plugin-adr-backend'; + const backend = createBackend(); + ++ backend.add(adrPlugin()); + +// ... other feature additions + + backend.start(); +``` + ## Indexing ADR documents for search Before you are able to start indexing ADR documents to search, you need to go through the [search getting started guide](https://backstage.io/docs/features/search/getting-started). diff --git a/plugins/adr-backend/api-report.md b/plugins/adr-backend/api-report.md index d5645ad3a7..2fd22ef9cd 100644 --- a/plugins/adr-backend/api-report.md +++ b/plugins/adr-backend/api-report.md @@ -7,6 +7,7 @@ import { AdrDocument } from '@backstage/plugin-adr-common'; import { AdrFilePathFilterFn } from '@backstage/plugin-adr-common'; +import { BackendFeature } from '@backstage/backend-plugin-api'; import { CacheClient } from '@backstage/backend-common'; import { CatalogApi } from '@backstage/catalog-client'; import { Config } from '@backstage/config'; @@ -43,6 +44,9 @@ export type AdrParserContext = { path: string; }; +// @public +export const adrPlugin: () => BackendFeature; + // @public (undocumented) export type AdrRouterOptions = { reader: UrlReader; diff --git a/plugins/adr-backend/package.json b/plugins/adr-backend/package.json index ec60ae7fa6..5ae23e71f1 100644 --- a/plugins/adr-backend/package.json +++ b/plugins/adr-backend/package.json @@ -29,6 +29,7 @@ }, "dependencies": { "@backstage/backend-common": "workspace:^", + "@backstage/backend-plugin-api": "workspace:^", "@backstage/catalog-client": "workspace:^", "@backstage/catalog-model": "workspace:^", "@backstage/config": "workspace:^", diff --git a/plugins/adr-backend/src/index.ts b/plugins/adr-backend/src/index.ts index 89c88ab3e7..eeaf6b4cd0 100644 --- a/plugins/adr-backend/src/index.ts +++ b/plugins/adr-backend/src/index.ts @@ -22,3 +22,4 @@ export * from './search'; export * from './service'; +export { adrPlugin } from './plugin'; diff --git a/plugins/adr-backend/src/plugin.ts b/plugins/adr-backend/src/plugin.ts new file mode 100644 index 0000000000..f926ade6be --- /dev/null +++ b/plugins/adr-backend/src/plugin.ts @@ -0,0 +1,49 @@ +/* + * 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'; + +/** + * ADR backend plugin + * + * @public + */ +export const adrPlugin = createBackendPlugin({ + pluginId: 'adr', + register(env) { + env.registerInit({ + deps: { + logger: coreServices.logger, + reader: coreServices.urlReader, + cache: coreServices.cache, + httpRouter: coreServices.httpRouter, + }, + async init({ httpRouter, logger, reader, cache }) { + httpRouter.use( + await createRouter({ + logger: loggerToWinstonLogger(logger), + reader, + cacheClient: cache, + }), + ); + }, + }); + }, +}); diff --git a/yarn.lock b/yarn.lock index 90d518eebf..5d23ec86e2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4576,6 +4576,7 @@ __metadata: resolution: "@backstage/plugin-adr-backend@workspace:plugins/adr-backend" dependencies: "@backstage/backend-common": "workspace:^" + "@backstage/backend-plugin-api": "workspace:^" "@backstage/catalog-client": "workspace:^" "@backstage/catalog-model": "workspace:^" "@backstage/cli": "workspace:^" @@ -24964,6 +24965,7 @@ __metadata: "@backstage/backend-defaults": "workspace:^" "@backstage/backend-tasks": "workspace:^" "@backstage/cli": "workspace:^" + "@backstage/plugin-adr-backend": "workspace:^" "@backstage/plugin-app-backend": "workspace:^" "@backstage/plugin-auth-node": "workspace:^" "@backstage/plugin-azure-devops-backend": "workspace:^"