-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate our project to use the new backend system (#94)
* WIP. Refactor the backend to use the new backend system. #88 Signed-off-by: cmoulliard <[email protected]> * The following property "private" has been remeoved by yarn 4.x. from phe plugins package.json Signed-off-by: cmoulliard <[email protected]> * Fix issue reported within #88 such as violation error. Switch to a more recent version of yarn, add signin page which is needed to use guest auth provider Signed-off-by: cmoulliard <[email protected]> * Enable corepack to allow to use yarn >= 1.x Signed-off-by: cmoulliard <[email protected]> * Enable corepack to allow to use yarn >= 1.x within build-k8s-image job too Signed-off-by: cmoulliard <[email protected]> * Use the command corepack enable before to install the packages Signed-off-by: cmoulliard <[email protected]> * Move corepack enable task to the correct place Signed-off-by: cmoulliard <[email protected]> * Use corepack prepare yarn@stable --activate to set the proper package manager as we still got job errors Signed-off-by: cmoulliard <[email protected]> * Try to use the hack documented here: actions/setup-node#899 Signed-off-by: cmoulliard <[email protected]> * Add missing yarn.lock file Signed-off-by: cmoulliard <[email protected]> * Use --immutable-cache as --prefer-offline --frozen-lockfile are deprecated Signed-off-by: cmoulliard <[email protected]> * Replace --immutable-cache with --immutable Signed-off-by: cmoulliard <[email protected]> --------- Signed-off-by: cmoulliard <[email protected]>
- Loading branch information
1 parent
8fad4b0
commit 0b049e3
Showing
26 changed files
with
36,712 additions
and
28,885 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodeLinker: node-modules |
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 |
---|---|---|
|
@@ -56,5 +56,6 @@ | |
"*.{json,md}": [ | ||
"prettier --write" | ||
] | ||
} | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
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
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,43 @@ | ||
/* | ||
* Hi! | ||
* | ||
* Note that this is an EXAMPLE Backstage backend. Please check the README. | ||
* | ||
* Happy hacking! | ||
*/ | ||
|
||
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 argocd from './plugins/argocd'; | ||
|
||
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 argocdEnv = useHotMemoize(module, () => createEnv('argocd')); | ||
|
||
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('/argocd', await argocd(argocdEnv)); | ||
|
||
// 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-auth-backend')); | ||
backend.add(import('@backstage/plugin-auth-backend-module-guest-provider')); | ||
|
||
backend.add(import('@backstage/plugin-app-backend/alpha')); | ||
backend.add(import('@backstage/plugin-catalog-backend-module-unprocessed')); | ||
backend.add( | ||
import('@backstage/plugin-catalog-backend-module-scaffolder-entity-model'), | ||
); | ||
backend.add(import('@backstage/plugin-catalog-backend/alpha')); | ||
|
||
backend.add(import('@backstage/plugin-permission-backend/alpha')); | ||
backend.add(import('@backstage/plugin-proxy-backend/alpha')); | ||
backend.add(import('@backstage/plugin-scaffolder-backend/alpha')); | ||
backend.add(import('@backstage/plugin-scaffolder-backend-module-github')); | ||
backend.add(import('@backstage/plugin-search-backend-module-catalog/alpha')); | ||
backend.add(import('@backstage/plugin-search-backend-module-techdocs/alpha')); | ||
backend.add(import('@backstage/plugin-search-backend/alpha')); | ||
backend.add(import('@backstage/plugin-techdocs-backend/alpha')); | ||
backend.add(import('@backstage/plugin-notifications-backend')); | ||
backend.add(import('@backstage/plugin-kubernetes-backend/alpha')); | ||
|
||
backend.add(import('@backstage/plugin-permission-backend-module-allow-all-policy')); | ||
|
||
// Argocd | ||
backend.add(import('./plugins/argocd-backend/index')) | ||
backend.add(import('./plugins/argocd-actions/index')) | ||
|
||
// Qshift | ||
backend.add(import('./plugins/qshift-actions/index')) | ||
|
||
// TODO: Section to be reviewed to add/remove plugins | ||
// //backend.add(import('@backstage/plugin-signals-backend')); | ||
// backend.add(import('@backstage/plugin-catalog-backend-module-backstage-openapi')); | ||
// backend.add(import('@backstage/plugin-search-backend-module-explore/alpha')); | ||
// backend.add(import('@backstage/plugin-permission-backend/alpha')); | ||
|
||
// TODO: To be added in a separate PR: backend.add(import('@backstage/plugin-devtools-backend')); | ||
// TODO: Add the github auth provider as janus-idp is using it | ||
|
||
backend.start() |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { scaffolderBackendModuleArgocd as default } from './plugin'; |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { | ||
coreServices, | ||
createBackendModule, | ||
} from '@backstage/backend-plugin-api'; | ||
import { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha'; | ||
import { createArgoCdResources } from '@roadiehq/scaffolder-backend-argocd'; | ||
import { loggerToWinstonLogger } from '@backstage/backend-common'; | ||
|
||
export const scaffolderBackendModuleArgocd = createBackendModule({ | ||
moduleId: 'scaffolder-backend-module-argocd', | ||
pluginId: 'scaffolder', | ||
register(env) { | ||
env.registerInit({ | ||
deps: { | ||
scaffolder: scaffolderActionsExtensionPoint, | ||
config: coreServices.rootConfig, | ||
logger: coreServices.logger, | ||
}, | ||
async init({ scaffolder, config, logger }) { | ||
scaffolder.addActions( | ||
createArgoCdResources(config, loggerToWinstonLogger(logger)), | ||
); | ||
}, | ||
}); | ||
}, | ||
}); |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { argocdPlugin as default } from './plugin'; |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { loggerToWinstonLogger } from '@backstage/backend-common'; | ||
import { | ||
coreServices, | ||
createBackendPlugin, | ||
} from '@backstage/backend-plugin-api'; | ||
import { createRouter } from '@roadiehq/backstage-plugin-argo-cd-backend'; | ||
|
||
export const argocdPlugin = createBackendPlugin({ | ||
pluginId: 'argocd', | ||
register(env) { | ||
env.registerInit({ | ||
deps: { | ||
config: coreServices.rootConfig, | ||
logger: coreServices.logger, | ||
http: coreServices.httpRouter, | ||
}, | ||
async init({ config, logger, http }) { | ||
http.use( | ||
await createRouter({ | ||
logger: loggerToWinstonLogger(logger), | ||
config, | ||
}), | ||
); | ||
}, | ||
}); | ||
}, | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.