Skip to content

Commit

Permalink
chore: migrate test app to new backend system (#4)
Browse files Browse the repository at this point in the history
Signed-off-by: Alec Jacobs <charles.jacobs@segment.com>
  • Loading branch information
alecjacobs5401 committed Apr 5, 2024
1 parent f497502 commit 199cf6d
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 447 deletions.
3 changes: 2 additions & 1 deletion app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ techdocs:

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

scaffolder:
github:
Expand Down
19 changes: 7 additions & 12 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,25 @@
"build-image": "docker build ../.. -f Dockerfile --tag backstage"
},
"dependencies": {
"@backstage/backend-common": "^0.21.6",
"@backstage/backend-tasks": "^0.5.21",
"@backstage/catalog-client": "^1.6.3",
"@backstage/catalog-model": "^1.4.5",
"@backstage/config": "^1.2.0",
"@backstage/backend-defaults": "^0.2.16",
"@backstage/backend-plugin-api": "^0.6.16",
"@backstage/plugin-app-backend": "^0.3.64",
"@backstage/plugin-auth-backend": "^0.22.3",
"@backstage/plugin-auth-node": "^0.4.11",
"@backstage/plugin-auth-backend-module-guest-provider": "^0.1.2",
"@backstage/plugin-catalog-backend": "^1.21.0",
"@backstage/plugin-permission-common": "^0.7.13",
"@backstage/plugin-permission-node": "^0.7.27",
"@backstage/plugin-catalog-backend-module-scaffolder-entity-model": "^0.1.14",
"@backstage/plugin-proxy-backend": "^0.4.14",
"@backstage/plugin-scaffolder-backend": "^1.22.3",
"@backstage/plugin-search-backend": "^1.5.6",
"@backstage/plugin-search-backend-module-pg": "^0.5.25",
"@backstage/plugin-search-backend-node": "^1.2.20",
"@backstage/plugin-search-backend-module-catalog": "^0.1.21",
"@backstage/plugin-search-backend-module-techdocs": "^0.1.21",
"@backstage/plugin-techdocs-backend": "^1.10.3",
"app": "link:../app",
"@segment/backstage-plugin-proxy-sigv4-backend": "link:../../plugins/proxy-sigv4-backend",
"app": "link:../app",
"better-sqlite3": "^8.0.0",
"dockerode": "^3.3.1",
"express": "^4.17.1",
"express-promise-router": "^4.1.0",
"pg": "^8.3.0",
"winston": "^3.2.1"
},
"devDependencies": {
Expand Down
5 changes: 1 addition & 4 deletions packages/backend/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { PluginEnvironment } from './types';

describe('test', () => {
it('unbreaks the test runner', () => {
const unbreaker = {} as PluginEnvironment;
expect(unbreaker).toBeTruthy();
expect(true).toBeTruthy();
});
});
133 changes: 25 additions & 108 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,118 +1,35 @@
/*
* Hi!
*
* Note that this is an EXAMPLE Backstage backend. Please check the README.
*
* Happy hacking!
*/
import { createBackend } from '@backstage/backend-defaults';

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 proxySigV4 from './plugins/proxy-sigv4';
import { PluginEnvironment } from './types';
import { ServerPermissionClient } from '@backstage/plugin-permission-node';
import { DefaultIdentityClient } from '@backstage/plugin-auth-node';
const backend = createBackend();

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 });
// app plugin installation
backend.add(import('@backstage/plugin-app-backend/alpha'));

const identity = DefaultIdentityClient.create({
discovery,
});
const permissions = ServerPermissionClient.fromConfig(config, {
discovery,
tokenManager,
});
// proxy plugin installation
backend.add(import('@backstage/plugin-proxy-backend/alpha'));

root.info(`Created UrlReader ${reader}`);
// techdocs plugin installation
backend.add(import('@backstage/plugin-techdocs-backend/alpha'));

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,
};
};
}
// catalog plugin installation
backend.add(import('@backstage/plugin-catalog-backend/alpha'));
backend.add(
import('@backstage/plugin-catalog-backend-module-scaffolder-entity-model'),
);

async function main() {
const config = await loadBackendConfig({
argv: process.argv,
logger: getRootLogger(),
});
const createEnv = makeCreateEnv(config);
// scaffolder plugin installation
backend.add(import('@backstage/plugin-scaffolder-backend/alpha'));

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 proxySigvV4Env = useHotMemoize(module, () => createEnv('proxy-sigv4'));
const techdocsEnv = useHotMemoize(module, () => createEnv('techdocs'));
const searchEnv = useHotMemoize(module, () => createEnv('search'));
const appEnv = useHotMemoize(module, () => createEnv('app'));
// auth plugin installation
backend.add(import('@backstage/plugin-auth-backend'));
backend.add(import('@backstage/plugin-auth-backend-module-guest-provider'));

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('/proxy-sigv4', await proxySigV4(proxySigvV4Env));
apiRouter.use('/search', await search(searchEnv));
// search plugin installation
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'));

// Add backends ABOVE this line; this 404 handler is the catch-all fallback
apiRouter.use(notFoundHandler());
// proxy-sigv4 plugin installation
backend.add(import('@segment/backstage-plugin-proxy-sigv4-backend'));

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);
});
backend.start();
14 changes: 0 additions & 14 deletions packages/backend/src/plugins/app.ts

This file was deleted.

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

This file was deleted.

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

This file was deleted.

12 changes: 0 additions & 12 deletions packages/backend/src/plugins/proxy-sigv4.ts

This file was deleted.

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

This file was deleted.

22 changes: 0 additions & 22 deletions packages/backend/src/plugins/scaffolder.ts

This file was deleted.

Loading

0 comments on commit 199cf6d

Please sign in to comment.