Skip to content

Commit

Permalink
Migrate our project to use the new backend system (#94)
Browse files Browse the repository at this point in the history
* 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
cmoulliard authored May 22, 2024
1 parent 8fad4b0 commit 0b049e3
Show file tree
Hide file tree
Showing 26 changed files with 36,712 additions and 28,885 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/build-push-backstage-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,23 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

- run: corepack enable

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: yarn

- name: Setup local Turbo cache
uses: dtinth/setup-github-actions-caching-for-turbo@v1

- name: Install dependencies
run: yarn --prefer-offline --frozen-lockfile
run: |
yarn --immutable
- name: Build backstage
run: |
Expand Down Expand Up @@ -74,17 +80,23 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

- run: corepack enable

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: yarn

- name: Setup local Turbo cache
uses: dtinth/setup-github-actions-caching-for-turbo@v1

- name: Install dependencies
run: yarn --prefer-offline --frozen-lockfile
run: |
yarn --immutable
- name: Build backstage
run: |
Expand Down
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@
"*.{json,md}": [
"prettier --write"
]
}
},
"packageManager": "[email protected]"
}
4 changes: 2 additions & 2 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"@janus-idp/backstage-plugin-topology": "^1.18.2",
"@material-ui/core": "^4.12.2",
"@material-ui/icons": "^4.9.1",
"@qshift/plugin-quarkus": "^0.1.28",
"@qshift/plugin-quarkus-console": "^0.1.28",
"@qshift/plugin-quarkus": "workspace:^",
"@qshift/plugin-quarkus-console": "workspace:^",
"@roadiehq/backstage-plugin-argo-cd": "2.4.1",
"history": "^5.0.0",
"react": "^18.0.2",
Expand Down
12 changes: 11 additions & 1 deletion packages/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ 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 { CatalogGraphPage } from '@backstage/plugin-catalog-graph';
Expand All @@ -43,6 +46,13 @@ import {QuarkusConsolePage} from "@qshift/plugin-quarkus-console";

const app = createApp({
apis,
components: {
SignInPage: props => {
return (
<SignInPage {...props} providers={['guest']} />
);
},
},
bindRoutes({ bind }) {
bind(catalogPlugin.externalRoutes, {
createComponent: scaffolderPlugin.routes.root,
Expand Down
16 changes: 12 additions & 4 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,39 @@
},
"dependencies": {
"@backstage/backend-common": "^0.22.0",
"@backstage/backend-defaults": "^0.2.18",
"@backstage/backend-tasks": "^0.5.23",
"@backstage/catalog-client": "^1.6.5",
"@backstage/catalog-model": "^1.5.0",
"@backstage/config": "^1.2.0",
"@backstage/integration": "^1.11.0",
"@backstage/plugin-app-backend": "^0.3.67",
"@backstage/plugin-auth-backend": "^0.22.5",
"@backstage/plugin-auth-backend-module-guest-provider": "^0.1.4",
"@backstage/plugin-auth-node": "^0.4.13",
"@backstage/plugin-catalog-backend": "^1.22.0",
"@backstage/plugin-catalog-backend-module-backstage-openapi": "^0.2.1",
"@backstage/plugin-catalog-backend-module-scaffolder-entity-model": "^0.1.16",
"@backstage/plugin-catalog-backend-module-unprocessed": "^0.4.5",
"@backstage/plugin-kubernetes-backend": "^0.17.1",
"@backstage/plugin-notifications-backend": "^0.2.1",
"@backstage/plugin-permission-backend": "^0.5.42",
"@backstage/plugin-permission-backend-module-allow-all-policy": "^0.1.15",
"@backstage/plugin-permission-common": "^0.7.13",
"@backstage/plugin-permission-node": "^0.7.29",
"@backstage/plugin-proxy-backend": "^0.4.16",
"@backstage/plugin-scaffolder-backend": "^1.22.7",
"@backstage/plugin-search-backend": "^1.5.9",
"@backstage/plugin-search-backend-module-catalog": "^0.1.24",
"@backstage/plugin-search-backend-module-explore": "^0.1.24",
"@backstage/plugin-search-backend-module-pg": "^0.5.27",
"@backstage/plugin-search-backend-module-techdocs": "^0.1.23",
"@backstage/plugin-search-backend-node": "^1.2.23",
"@backstage/plugin-techdocs-backend": "^1.10.5",
"@qshift/plugin-maven-backend": "^0.1.28",
"@qshift/plugin-quarkus-backend": "^0.1.28",
"@roadiehq/backstage-plugin-argo-cd-backend": "^2.14.0",
"@roadiehq/scaffolder-backend-argocd": "^1.1.19",
"@qshift/plugin-maven-backend": "workspace:^",
"@qshift/plugin-quarkus-backend": "workspace:^",
"@roadiehq/backstage-plugin-argo-cd-backend": "^3.0.2",
"@roadiehq/scaffolder-backend-argocd": "^1.1.27",
"app": "link:../app",
"better-sqlite3": "^9.0.0",
"dockerode": "^3.3.1",
Expand Down
161 changes: 43 additions & 118 deletions packages/backend/src/index.ts
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()
14 changes: 0 additions & 14 deletions packages/backend/src/plugins/app.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/backend/src/plugins/argocd-actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { scaffolderBackendModuleArgocd as default } from './plugin';
26 changes: 26 additions & 0 deletions packages/backend/src/plugins/argocd-actions/plugin.ts
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)),
);
},
});
},
});
1 change: 1 addition & 0 deletions packages/backend/src/plugins/argocd-backend/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { argocdPlugin as default } from './plugin';
27 changes: 27 additions & 0 deletions packages/backend/src/plugins/argocd-backend/plugin.ts
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,
}),
);
},
});
},
});
9 changes: 0 additions & 9 deletions packages/backend/src/plugins/argocd.ts

This file was deleted.

Loading

0 comments on commit 0b049e3

Please sign in to comment.