Skip to content

Commit

Permalink
feat(awards): support new backend system (#61)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The awards-backend plugin will no longer be able to run on the old plugin system.
See the [migration guide](https://backstage.io/docs/backend-system/building-backends/migrating/) for more info.
  • Loading branch information
zhammer authored Aug 25, 2024
1 parent 7deea4e commit 20667b2
Show file tree
Hide file tree
Showing 25 changed files with 393 additions and 709 deletions.
2 changes: 1 addition & 1 deletion app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ techdocs:
auth:
environment: development
providers:
'dummy-auth': {}
guest: {}

catalog:
rules:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"concurrently": "^8.0.0",
"conventional-changelog-conventionalcommits": "^6.1.0",
"lerna": "^7.3.0",
"node-gyp": "^9.0.0",
"node-gyp": "^10.0.0",
"prettier": "^2.3.2",
"prettier-plugin-organize-imports": "^3.2.4",
"typescript": "~5.2.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { AppRouter, FlatRoutes } from '@backstage/core-app-api';
import {
AlertDisplay,
OAuthRequestDialog,
ProxiedSignInPage,
SignInPage,
} from '@backstage/core-components';
import { catalogEntityCreatePermission } from '@backstage/plugin-catalog-common/alpha';
import { CatalogGraphPage } from '@backstage/plugin-catalog-graph';
Expand All @@ -41,7 +41,7 @@ import { AwardsPage } from '@seatgeek/backstage-plugin-awards';
const app = createApp({
apis,
components: {
SignInPage: props => <ProxiedSignInPage {...props} provider="dummy-auth" />,
SignInPage: props => <SignInPage {...props} auto providers={['guest']} />,
},
bindRoutes({ bind }) {
bind(catalogPlugin.externalRoutes, {
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@
},
"dependencies": {
"@backstage/backend-common": "^0.24.0",
"@backstage/backend-defaults": "^0.4.3",
"@backstage/backend-tasks": "^0.6.0",
"@backstage/catalog-client": "^1.6.6",
"@backstage/catalog-model": "^1.6.0",
"@backstage/config": "^1.2.0",
"@backstage/plugin-app-backend": "^0.3.72",
"@backstage/plugin-auth-backend": "^0.22.10",
"@backstage/plugin-auth-backend-module-guest-provider": "^0.1.9",
"@backstage/plugin-auth-node": "^0.5.0",
"@backstage/plugin-catalog-backend": "^1.25.0",
"@backstage/plugin-catalog-backend-module-logs": "^0.0.2",
"@backstage/plugin-catalog-backend-module-scaffolder-entity-model": "^0.1.21",
"@backstage/plugin-permission-backend": "^0.5.47",
"@backstage/plugin-permission-backend-module-allow-all-policy": "^0.1.20",
"@backstage/plugin-permission-common": "^0.8.1",
"@backstage/plugin-permission-node": "^0.8.1",
"@backstage/plugin-proxy-backend": "^0.5.4",
Expand Down
154 changes: 40 additions & 114 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,114 +1,40 @@
/*
* Hi!
*
* Note that this is an EXAMPLE Backstage backend. Please check the README.
*
* Happy hacking!
*/

import {
CacheManager,
DatabaseManager,
HostDiscovery,
ServerTokenManager,
createServiceBuilder,
getRootLogger,
loadBackendConfig,
notFoundHandler,
useHotMemoize,
} from '@backstage/backend-common';
import { TaskScheduler } from '@backstage/backend-tasks';
import { Config } from '@backstage/config';
import { DefaultIdentityClient } from '@backstage/plugin-auth-node';
import { ServerPermissionClient } from '@backstage/plugin-permission-node';
import Router from 'express-promise-router';
import app from './plugins/app';
import auth from './plugins/auth';
import awards from './plugins/awards';
import catalog from './plugins/catalog';
import proxy from './plugins/proxy';
import scaffolder from './plugins/scaffolder';
import search from './plugins/search';
import techdocs from './plugins/techdocs';
import { PluginEnvironment } from './types';

function makeCreateEnv(config: Config) {
const root = getRootLogger();
const discovery = HostDiscovery.fromConfig(config);
const cacheManager = CacheManager.fromConfig(config);
const databaseManager = DatabaseManager.fromConfig(config, { logger: root });
const tokenManager = ServerTokenManager.noop();
const taskScheduler = TaskScheduler.fromConfig(config, { databaseManager });

const identity = DefaultIdentityClient.create({
discovery,
});
const permissions = ServerPermissionClient.fromConfig(config, {
discovery,
tokenManager,
});

return (plugin: string): PluginEnvironment => {
const logger = root.child({ type: 'plugin', plugin });
const database = databaseManager.forPlugin(plugin);
const cache = cacheManager.forPlugin(plugin);
const scheduler = taskScheduler.forPlugin(plugin);
return {
logger,
database,
cache,
config,
discovery,
tokenManager,
scheduler,
reader: undefined as any,
permissions,
identity,
};
};
}

async function main() {
const config = await loadBackendConfig({
argv: process.argv,
logger: getRootLogger(),
});
const createEnv = makeCreateEnv(config);

const catalogEnv = useHotMemoize(module, () => createEnv('catalog'));
const scaffolderEnv = useHotMemoize(module, () => createEnv('scaffolder'));
const authEnv = useHotMemoize(module, () => createEnv('auth'));
const proxyEnv = useHotMemoize(module, () => createEnv('proxy'));
const techdocsEnv = useHotMemoize(module, () => createEnv('techdocs'));
const searchEnv = useHotMemoize(module, () => createEnv('search'));
const appEnv = useHotMemoize(module, () => createEnv('app'));
const awardsEnv = useHotMemoize(module, () => createEnv('awards'));

const apiRouter = Router();
apiRouter.use('/catalog', await catalog(catalogEnv));
apiRouter.use('/scaffolder', await scaffolder(scaffolderEnv));
apiRouter.use('/auth', await auth(authEnv));
apiRouter.use('/techdocs', await techdocs(techdocsEnv));
apiRouter.use('/proxy', await proxy(proxyEnv));
apiRouter.use('/search', await search(searchEnv));
apiRouter.use('/awards', await awards(awardsEnv));

// Add backends ABOVE this line; this 404 handler is the catch-all fallback
apiRouter.use(notFoundHandler());

const service = createServiceBuilder(module)
.loadConfig(config)
.addRouter('/api', apiRouter)
.addRouter('', await app(appEnv));

await service.start().catch(err => {
console.log(err);
process.exit(1);
});
}

module.hot?.accept();
main().catch(error => {
console.error('Backend failed to start up', error);
process.exit(1);
});
import { createBackend } from '@backstage/backend-defaults';

const backend = createBackend();

backend.add(import('@backstage/plugin-app-backend/alpha'));
backend.add(import('@backstage/plugin-proxy-backend/alpha'));
backend.add(import('@backstage/plugin-scaffolder-backend/alpha'));
backend.add(import('@backstage/plugin-techdocs-backend/alpha'));

// auth plugin
backend.add(import('@backstage/plugin-auth-backend'));
// See https://backstage.io/docs/backend-system/building-backends/migrating#the-auth-plugin
backend.add(import('@backstage/plugin-auth-backend-module-guest-provider'));
// See https://backstage.io/docs/auth/guest/provider

// catalog plugin
backend.add(import('@backstage/plugin-catalog-backend/alpha'));
backend.add(
import('@backstage/plugin-catalog-backend-module-scaffolder-entity-model'),
);

// See https://backstage.io/docs/features/software-catalog/configuration#subscribing-to-catalog-errors
backend.add(import('@backstage/plugin-catalog-backend-module-logs'));

// permission plugin
backend.add(import('@backstage/plugin-permission-backend/alpha'));
// See https://backstage.io/docs/permissions/getting-started for how to create your own permission policy
backend.add(
import('@backstage/plugin-permission-backend-module-allow-all-policy'),
);

// search plugin
backend.add(import('@backstage/plugin-search-backend/alpha'));

// search collators
backend.add(import('@backstage/plugin-search-backend-module-catalog/alpha'));
backend.add(import('@backstage/plugin-search-backend-module-techdocs/alpha'));

backend.add(import('@seatgeek/backstage-plugin-awards-backend'));
backend.start();
14 changes: 0 additions & 14 deletions packages/backend/src/plugins/app.ts

This file was deleted.

107 changes: 0 additions & 107 deletions packages/backend/src/plugins/auth.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/backend/src/plugins/awards.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/backend/src/plugins/catalog.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/backend/src/plugins/proxy.ts

This file was deleted.

Loading

0 comments on commit 20667b2

Please sign in to comment.