-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate test app to new backend system (#4)
Signed-off-by: Alec Jacobs <charles.jacobs@segment.com>
- Loading branch information
1 parent
f497502
commit 199cf6d
Showing
14 changed files
with
72 additions
and
447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.