Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade to new backend system #17

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/blue-jars-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@dweber019/backstage-plugin-api-docs-module-wsdl-backend': patch
'@dweber019/backstage-plugin-accentuate-backend': patch
'@dweber019/backstage-plugin-endoflife-backend': patch
'@dweber019/backstage-plugin-relations-backend': patch
'@dweber019/backstage-plugin-accentuate': patch
'@dweber019/backstage-plugin-endoflife': patch
---

Update to new backend system.
4 changes: 3 additions & 1 deletion app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ techdocs:

auth:
# see https://backstage.io/docs/auth/ to learn about auth providers
providers: {}
providers:
# See https://backstage.io/docs/auth/guest/provider
guest: {}

scaffolder:
# see https://backstage.io/docs/features/software-templates/configuration for software template options
Expand Down
9 changes: 8 additions & 1 deletion packages/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ import { entityPage } from './components/catalog/EntityPage';
import { searchPage } from './components/search/SearchPage';
import { Root } from './components/Root';

import { AlertDisplay, OAuthRequestDialog } from '@backstage/core-components';
import {
AlertDisplay,
OAuthRequestDialog,
SignInPage,
} from '@backstage/core-components';
import { createApp } from '@backstage/app-defaults';
import { AppRouter, FlatRoutes } from '@backstage/core-app-api';
import { RelationsCatalogGraphPage } from '@dweber019/backstage-plugin-relations';
Expand All @@ -68,6 +72,9 @@ const app = createApp({
catalogIndex: catalogPlugin.routes.catalogIndex,
});
},
components: {
SignInPage: props => <SignInPage {...props} auto providers={['guest']} />,
},
});

const routes = (
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@
},
"dependencies": {
"@backstage/backend-common": "^0.21.7",
"@backstage/backend-defaults": "^0.2.17",
"@backstage/backend-tasks": "^0.5.22",
"@backstage/catalog-client": "^1.6.4",
"@backstage/catalog-model": "^1.4.5",
"@backstage/config": "^1.2.0",
"@backstage/plugin-app-backend": "^0.3.65",
"@backstage/plugin-auth-backend": "^0.22.4",
"@backstage/plugin-auth-backend-module-guest-provider": "^0.1.3",
"@backstage/plugin-auth-node": "^0.4.12",
"@backstage/plugin-catalog-backend": "^1.21.1",
"@backstage/plugin-catalog-backend-module-scaffolder-entity-model": "^0.1.15",
"@backstage/plugin-permission-backend": "^0.5.41",
"@backstage/plugin-permission-backend-module-allow-all-policy": "^0.1.14",
"@backstage/plugin-permission-common": "^0.7.13",
"@backstage/plugin-permission-node": "^0.7.28",
"@backstage/plugin-proxy-backend": "^0.4.15",
Expand Down
121 changes: 121 additions & 0 deletions packages/backend/src/index-old.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import Router from 'express-promise-router';
import {
createServiceBuilder,
loadBackendConfig,
getRootLogger,
useHotMemoize,
notFoundHandler,
CacheManager,
DatabaseManager,
HostDiscovery,
UrlReaders,
ServerTokenManager,
} from '@backstage/backend-common';
import { TaskScheduler } from '@backstage/backend-tasks';
import { Config } from '@backstage/config';
import app from './plugins/app';
import auth from './plugins/auth';
import catalog from './plugins/catalog';
import scaffolder from './plugins/scaffolder';
import proxy from './plugins/proxy';
import techdocs from './plugins/techdocs';
import search from './plugins/search';
import { PluginEnvironment } from './types';
import { ServerPermissionClient } from '@backstage/plugin-permission-node';
import { DefaultIdentityClient } from '@backstage/plugin-auth-node';
import apiDocsModuleWsdlDoc from './plugins/apiDocsModuleWsdl';
import endOfLife from './plugins/endoflife';
import accentuate from './plugins/accentuate';

function makeCreateEnv(config: Config) {
const root = getRootLogger();
const reader = UrlReaders.default({ logger: root, config });
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,
});

root.info(`Created UrlReader ${reader}`);

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,
reader,
discovery,
tokenManager,
scheduler,
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 apiDocsModuleWsdlDocEnv = useHotMemoize(module, () =>
createEnv('apiDocsModuleWsdl'),
);
const endOfLifeEnv = useHotMemoize(module, () => createEnv('endoflife'));
const accentuateEnv = useHotMemoize(module, () => createEnv('accentuate'));

const apiRouter = Router();
apiRouter.use('/catalog', await catalog(catalogEnv, accentuateEnv));
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(
'/api-docs-module-wsdl',
await apiDocsModuleWsdlDoc(apiDocsModuleWsdlDocEnv),
);
apiRouter.use('/endoflife', await endOfLife(endOfLifeEnv));
apiRouter.use('/accentuate', await accentuate(accentuateEnv));

// 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);
});
172 changes: 44 additions & 128 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,129 +1,45 @@
/*
* Hi!
*
* Note that this is an EXAMPLE Backstage backend. Please check the README.
*
* Happy hacking!
*/

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

function makeCreateEnv(config: Config) {
const root = getRootLogger();
const reader = UrlReaders.default({ logger: root, config });
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,
});

root.info(`Created UrlReader ${reader}`);

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,
reader,
discovery,
tokenManager,
scheduler,
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 apiDocsModuleWsdlDocEnv = useHotMemoize(module, () =>
createEnv('apiDocsModuleWsdl'),
);
const endOfLifeEnv = useHotMemoize(module, () => createEnv('endoflife'));
const accentuateEnv = useHotMemoize(module, () => createEnv('accentuate'));

const apiRouter = Router();
apiRouter.use('/catalog', await catalog(catalogEnv, accentuateEnv));
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(
'/api-docs-module-wsdl',
await apiDocsModuleWsdlDoc(apiDocsModuleWsdlDocEnv),
);
apiRouter.use('/endoflife', await endOfLife(endOfLifeEnv));
apiRouter.use('/accentuate', await accentuate(accentuateEnv));

// 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);
});
accentuatePlugin,
catalogModuleAccentuateProcessor,
} from '@dweber019/backstage-plugin-accentuate-backend';

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'),
);
// permission plugin
backend.add(import('@backstage/plugin-permission-backend/alpha'));
backend.add(
import('@backstage/plugin-permission-backend-module-allow-all-policy'),
);
// search plugin
backend.add(import('@backstage/plugin-search-backend/alpha'));
backend.add(import('@backstage/plugin-search-backend-module-catalog/alpha'));
backend.add(import('@backstage/plugin-search-backend-module-techdocs/alpha'));

// api-docs-module-wsdl-backend plugin
backend.add(import('@dweber019/backstage-plugin-api-docs-module-wsdl-backend'));

// endoflife-backend plugin
backend.add(import('@dweber019/backstage-plugin-endoflife-backend'));

// relations-backend plugin
backend.add(import('@dweber019/backstage-plugin-relations-backend'));

// accentuate-backend plugin
backend.add(accentuatePlugin);
backend.add(catalogModuleAccentuateProcessor);

backend.start();
2 changes: 1 addition & 1 deletion packages/backend/src/plugins/apiDocsModuleWsdl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import { PluginEnvironment } from '../types';
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
return await createRouter({ logger: env.logger, discovery: env.discovery, tokenManager: env.tokenManager });
return await createRouter(env);
}
16 changes: 9 additions & 7 deletions plugins/accentuate-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,19 @@ The backend plugin has support for the [new backend system](https://backstage.io

In your `packages/backend/src/index.ts` make the following changes:

```diff

+ import { accentuatePlugin, catalogModuleAccentuateProcessor } from '@dweber019/backstage-plugin-accentuate-backend';
const backend = createBackend();
```ts
import {
accentuatePlugin,
catalogModuleAccentuateProcessor,
} from '@dweber019/backstage-plugin-accentuate-backend';
const backend = createBackend();

+ backend.add(accentuatePlugin());
+ backend.add(catalogModuleAccentuateProcessor());
backend.add(accentuatePlugin);
backend.add(catalogModuleAccentuateProcessor);

// ... other feature additions

backend.start();
backend.start();
```

> This was not tested and is here for reference
Loading
Loading