diff --git a/.changeset/angry-clocks-exercise.md b/.changeset/angry-clocks-exercise.md new file mode 100644 index 0000000000..e7eb6ae1d9 --- /dev/null +++ b/.changeset/angry-clocks-exercise.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-nomad-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 d0fc53ff58..3e5b4f8057 100644 --- a/packages/backend-next/package.json +++ b/packages/backend-next/package.json @@ -41,6 +41,7 @@ "@backstage/plugin-kubernetes-backend": "workspace:^", "@backstage/plugin-lighthouse-backend": "workspace:^", "@backstage/plugin-linguist-backend": "workspace:^", + "@backstage/plugin-nomad-backend": "workspace:^", "@backstage/plugin-permission-backend": "workspace:^", "@backstage/plugin-permission-backend-module-allow-all-policy": "workspace:^", "@backstage/plugin-permission-common": "workspace:^", diff --git a/packages/backend-next/src/index.ts b/packages/backend-next/src/index.ts index 9fda69635b..1b4867c05e 100644 --- a/packages/backend-next/src/index.ts +++ b/packages/backend-next/src/index.ts @@ -33,6 +33,7 @@ backend.add(import('@backstage/plugin-kubernetes-backend/alpha')); backend.add(import('@backstage/plugin-lighthouse-backend')); backend.add(import('@backstage/plugin-linguist-backend')); backend.add(import('@backstage/plugin-playlist-backend')); +backend.add(import('@backstage/plugin-nomad-backend')); backend.add( import('@backstage/plugin-permission-backend-module-allow-all-policy'), ); diff --git a/plugins/nomad-backend/README.md b/plugins/nomad-backend/README.md index d06444809e..231f1ddccb 100644 --- a/plugins/nomad-backend/README.md +++ b/plugins/nomad-backend/README.md @@ -1,6 +1,20 @@ # @backstage/plugin-nomad-backend -A backend for [Nomad](https://www.nomadproject.io/), this plugin exposes a service with routes that are used by the `@backstage/plugin-nomad` plugin to query Job and Group information from a Nomad API. +A backend for [Nomad](https://www.nomadproject.io/), this plugin exposes a service with routes that are used by the `@backstage/plugin-nomad-backend` plugin to query Job and Group information from a Nomad API. + +## New Backend System + +The Nomad 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'; + const backend = createBackend(); + // ... other feature additions + backend.add(import('@backstage/plugin-nomad-backend')); + backend.start(); +``` ## Set Up diff --git a/plugins/nomad-backend/api-report.md b/plugins/nomad-backend/api-report.md index 5b56661e43..82bb823d2d 100644 --- a/plugins/nomad-backend/api-report.md +++ b/plugins/nomad-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 express from 'express'; import { Logger } from 'winston'; @@ -10,6 +11,10 @@ import { Logger } from 'winston'; // @public (undocumented) export function createRouter(options: RouterOptions): Promise; +// @public +const nomadPlugin: () => BackendFeature; +export default nomadPlugin; + // @public (undocumented) export interface RouterOptions { // (undocumented) diff --git a/plugins/nomad-backend/package.json b/plugins/nomad-backend/package.json index a9c86dc376..7873f846ba 100644 --- a/plugins/nomad-backend/package.json +++ b/plugins/nomad-backend/package.json @@ -29,6 +29,7 @@ }, "dependencies": { "@backstage/backend-common": "workspace:^", + "@backstage/backend-plugin-api": "workspace:^", "@backstage/config": "workspace:^", "@backstage/errors": "workspace:^", "@types/express": "*", diff --git a/plugins/nomad-backend/src/index.ts b/plugins/nomad-backend/src/index.ts index d2e8d61bad..21aa299d6d 100644 --- a/plugins/nomad-backend/src/index.ts +++ b/plugins/nomad-backend/src/index.ts @@ -14,3 +14,4 @@ * limitations under the License. */ export * from './service/router'; +export { nomadPlugin as default } from './plugin'; diff --git a/plugins/nomad-backend/src/plugin.test.ts b/plugins/nomad-backend/src/plugin.test.ts new file mode 100644 index 0000000000..6ed8d2b194 --- /dev/null +++ b/plugins/nomad-backend/src/plugin.test.ts @@ -0,0 +1,22 @@ +/* + * 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 { nomadPlugin } from './plugin'; + +describe('nomad', () => { + it('should export the nomad plugin', () => { + expect(nomadPlugin).toBeDefined(); + }); +}); diff --git a/plugins/nomad-backend/src/plugin.ts b/plugins/nomad-backend/src/plugin.ts new file mode 100644 index 0000000000..f3a43c4a91 --- /dev/null +++ b/plugins/nomad-backend/src/plugin.ts @@ -0,0 +1,52 @@ +/* + * 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 { createRouter } from './service/router'; + +/** + * Nomad backend plugin + * + * @public + */ +export const nomadPlugin = createBackendPlugin({ + pluginId: 'nomad', + register(env) { + env.registerInit({ + deps: { + logger: coreServices.logger, + config: coreServices.rootConfig, + httpRouter: coreServices.httpRouter, + }, + async init({ logger, config, httpRouter }) { + const winstonLogger = loggerToWinstonLogger(logger); + httpRouter.use( + await createRouter({ + /** + * Logger for logging purposes + */ + logger: winstonLogger, + config, + }), + ); + }, + }); + }, +}); diff --git a/yarn.lock b/yarn.lock index 9985eb94e8..b7987c9f3a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7982,6 +7982,7 @@ __metadata: resolution: "@backstage/plugin-nomad-backend@workspace:plugins/nomad-backend" dependencies: "@backstage/backend-common": "workspace:^" + "@backstage/backend-plugin-api": "workspace:^" "@backstage/cli": "workspace:^" "@backstage/config": "workspace:^" "@backstage/errors": "workspace:^" @@ -25625,6 +25626,7 @@ __metadata: "@backstage/plugin-kubernetes-backend": "workspace:^" "@backstage/plugin-lighthouse-backend": "workspace:^" "@backstage/plugin-linguist-backend": "workspace:^" + "@backstage/plugin-nomad-backend": "workspace:^" "@backstage/plugin-permission-backend": "workspace:^" "@backstage/plugin-permission-backend-module-allow-all-policy": "workspace:^" "@backstage/plugin-permission-common": "workspace:^"