Skip to content

Commit 7aa0bb5

Browse files
committed
update index.ts for backend
1 parent a709778 commit 7aa0bb5

File tree

15 files changed

+1848
-225
lines changed

15 files changed

+1848
-225
lines changed

app-config.yaml

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
app:
2-
title: Scaffolded Backstage App
2+
title: CUAS Hub
33
baseUrl: http://localhost:3000
44

55
organization:
6-
name: My Company
6+
name: CUAS
77

88
backend:
99
baseUrl: http://localhost:7007
@@ -40,36 +40,19 @@ catalog:
4040
entityFilename: catalog-info.yaml
4141
pullRequestBranchName: backstage-integration
4242
rules:
43-
- allow: [Component, System, API, Resource, Location]
44-
locations:
45-
- type: file
46-
target: ../../examples/entities.yaml
47-
48-
- type: file
49-
target: ../../examples/template/template.yaml
50-
rules:
51-
- allow: [Template]
52-
53-
- type: file
54-
target: ../../examples/org.yaml
55-
rules:
56-
- allow: [User, Group]
57-
58-
- type: url
59-
target: https://github.com/backstage/software-templates/blob/main/scaffolder-templates/react-ssr-template/template.yaml
60-
rules:
61-
- allow: [Template]
62-
63-
- type: file
64-
target: ../../packages/backend/src/templates/initiate-deployment.yaml
65-
rules:
66-
- allow: [Template]
43+
- allow: [Component, System, API, User, Group, Resource, Location, Domain]
44+
locations: []
6745

6846
auth:
69-
# see https://backstage.io/docs/auth/ to learn about auth providers
7047
environment: development
7148
providers:
7249
google:
7350
development:
7451
clientId: ${GOOGLE_CLIENT_ID}
7552
clientSecret: ${GOOGLE_CLIENT_SECRET}
53+
signIn:
54+
resolvers:
55+
- resolver: emailLocalPartMatchingUserEntityName
56+
domain: code.berlin
57+
58+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# How to register a component and define service dependency and RTO
2+

examples/org.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ apiVersion: backstage.io/v1alpha1
44
kind: User
55
metadata:
66
name: guest
7+
namespace: default
78
spec:
89
memberOf: [guests]
910
---

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"node": "20 || 22"
77
},
88
"scripts": {
9-
"dev": "cross-env $(cat .env | egrep -v '#|^$' | xargs) && concurrently \"yarn start\" \"yarn start-backend\"",
9+
"dev": "yarn workspaces foreach -A --include backend --include app --parallel -v -i run start",
1010
"start": "yarn workspace app start",
1111
"start-backend": "yarn workspace backend start",
1212
"build:backend": "yarn workspace backend build",

packages/app/e2e-tests/app.test.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/*
2-
* Copyright 2020 The Backstage Authors
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
171
import { test, expect } from '@playwright/test';
182

193
test('App should render the welcome page', async ({ page }) => {

packages/app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
"@testing-library/react": "^14.0.0",
5959
"@testing-library/user-event": "^14.0.0",
6060
"@types/react-dom": "*",
61-
"cross-env": "^7.0.0"
61+
"cross-env": "^7.0.0",
62+
"jest-canvas-mock": "^2.5.2"
6263
},
6364
"browserslist": {
6465
"production": [

packages/backend/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,23 @@
1515
"clean": "backstage-cli package clean"
1616
},
1717
"dependencies": {
18-
"@backstage/backend-common": "^0.20.1",
18+
"@backstage/backend-common": "^0.25.0",
19+
"@backstage/backend-defaults": "^0.5.3",
20+
"@backstage/backend-plugin-api": "^1.0.2",
1921
"@backstage/backend-tasks": "^0.5.14",
2022
"@backstage/catalog-client": "^1.8.0",
2123
"@backstage/catalog-model": "^1.7.1",
2224
"@backstage/config": "^1.3.0",
2325
"@backstage/plugin-app-backend": "^0.4.2",
2426
"@backstage/plugin-auth-backend": "^0.24.0",
27+
"@backstage/plugin-auth-backend-module-github-provider": "^0.2.2",
28+
"@backstage/plugin-auth-backend-module-google-provider": "^0.2.2",
2529
"@backstage/plugin-auth-node": "^0.5.4",
2630
"@backstage/plugin-catalog-backend": "^1.28.0",
2731
"@backstage/plugin-catalog-backend-module-scaffolder-entity-model": "^0.2.2",
2832
"@backstage/plugin-kubernetes-backend": "^0.19.0",
33+
"@backstage/plugin-permission-backend": "^0.5.51",
34+
"@backstage/plugin-permission-backend-module-allow-all-policy": "^0.2.2",
2935
"@backstage/plugin-permission-common": "^0.8.2",
3036
"@backstage/plugin-permission-node": "^0.8.5",
3137
"@backstage/plugin-proxy-backend": "^0.5.8",
@@ -36,6 +42,7 @@
3642
"@backstage/plugin-search-backend-module-techdocs": "^0.3.3",
3743
"@backstage/plugin-search-backend-node": "^1.3.5",
3844
"@backstage/plugin-techdocs-backend": "^1.11.3",
45+
"@spotify/backstage-plugin-soundcheck-backend": "^0.17.9",
3946
"app": "link:../app",
4047
"dockerode": "^3.3.1",
4148
"dotenv": "^16.4.5",
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
2+
3+
/*
4+
import Router from 'express-promise-router';
5+
import {
6+
createServiceBuilder,
7+
loadBackendConfig,
8+
getRootLogger,
9+
useHotMemoize,
10+
notFoundHandler,
11+
CacheManager,
12+
DatabaseManager,
13+
HostDiscovery,
14+
UrlReaders,
15+
ServerTokenManager,
16+
} from '@backstage/backend-common';
17+
import { TaskScheduler } from '@backstage/backend-tasks';
18+
import { Config } from '@backstage/config';
19+
import app from './plugins/app';
20+
import auth from './plugins/auth';
21+
import catalog from './plugins/catalog';
22+
import scaffolder from './plugins/scaffolder';
23+
import proxy from './plugins/proxy';
24+
import techdocs from './plugins/techdocs';
25+
import search from './plugins/search';
26+
import { PluginEnvironment } from './types';
27+
import { ServerPermissionClient } from '@backstage/plugin-permission-node';
28+
import { DefaultIdentityClient } from '@backstage/plugin-auth-node';
29+
function makeCreateEnv(config: Config) {
30+
const root = getRootLogger();
31+
const reader = UrlReaders.default({ logger: root, config });
32+
const discovery = HostDiscovery.fromConfig(config);
33+
const cacheManager = CacheManager.fromConfig(config);
34+
const databaseManager = DatabaseManager.fromConfig(config, { logger: root });
35+
const tokenManager = ServerTokenManager.noop();
36+
const taskScheduler = TaskScheduler.fromConfig(config, { databaseManager });
37+
38+
const identity = DefaultIdentityClient.create({
39+
discovery,
40+
});
41+
const permissions = ServerPermissionClient.fromConfig(config, {
42+
discovery,
43+
tokenManager,
44+
});
45+
46+
root.info(`Created UrlReader ${reader}`);
47+
48+
return (plugin: string): PluginEnvironment => {
49+
const logger = root.child({ type: 'plugin', plugin });
50+
const database = databaseManager.forPlugin(plugin);
51+
const cache = cacheManager.forPlugin(plugin);
52+
const scheduler = taskScheduler.forPlugin(plugin);
53+
return {
54+
logger,
55+
database,
56+
cache,
57+
config,
58+
reader,
59+
discovery,
60+
tokenManager,
61+
scheduler,
62+
permissions,
63+
identity,
64+
};
65+
};
66+
}
67+
68+
async function main() {
69+
const config = await loadBackendConfig({
70+
argv: process.argv,
71+
logger: getRootLogger(),
72+
});
73+
const createEnv = makeCreateEnv(config);
74+
75+
const catalogEnv = useHotMemoize(module, () => createEnv('catalog'));
76+
const scaffolderEnv = useHotMemoize(module, () => createEnv('scaffolder'));
77+
const authEnv = useHotMemoize(module, () => createEnv('auth'));
78+
const proxyEnv = useHotMemoize(module, () => createEnv('proxy'));
79+
const techdocsEnv = useHotMemoize(module, () => createEnv('techdocs'));
80+
const searchEnv = useHotMemoize(module, () => createEnv('search'));
81+
const appEnv = useHotMemoize(module, () => createEnv('app'));
82+
83+
84+
const apiRouter = Router();
85+
apiRouter.use('/catalog', await catalog(catalogEnv));
86+
apiRouter.use('/scaffolder', await scaffolder(scaffolderEnv));
87+
apiRouter.use('/auth', await auth(authEnv));
88+
apiRouter.use('/techdocs', await techdocs(techdocsEnv));
89+
apiRouter.use('/proxy', await proxy(proxyEnv));
90+
apiRouter.use('/search', await search(searchEnv));
91+
92+
93+
// Add backends ABOVE this line; this 404 handler is the catch-all fallback
94+
apiRouter.use(notFoundHandler());
95+
96+
const service = createServiceBuilder(module)
97+
.loadConfig(config)
98+
.addRouter('/api', apiRouter)
99+
.addRouter('', await app(appEnv));
100+
101+
await service.start().catch(err => {
102+
console.log(err);
103+
process.exit(1);
104+
});
105+
}
106+
107+
module.hot?.accept();
108+
main().catch(error => {
109+
console.error('Backend failed to start up', error);
110+
process.exit(1);
111+
});
112+
*/

packages/backend/src/index.ts

Lines changed: 26 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,36 @@
1-
/*
2-
* Hi!
3-
*
4-
* Note that this is an EXAMPLE Backstage backend. Please check the README.
5-
*
6-
* Happy hacking!
7-
*/
1+
import { createBackend } from '@backstage/backend-defaults';
2+
// import { customGoogleAuth } from './plugins/plugins_helper/googleCustomAuth';
83

9-
import Router from 'express-promise-router';
10-
import {
11-
createServiceBuilder,
12-
loadBackendConfig,
13-
getRootLogger,
14-
useHotMemoize,
15-
notFoundHandler,
16-
CacheManager,
17-
DatabaseManager,
18-
HostDiscovery,
19-
UrlReaders,
20-
ServerTokenManager,
21-
} from '@backstage/backend-common';
22-
import { TaskScheduler } from '@backstage/backend-tasks';
23-
import { Config } from '@backstage/config';
24-
import app from './plugins/app';
25-
import auth from './plugins/auth';
26-
import catalog from './plugins/catalog';
27-
import scaffolder from './plugins/scaffolder';
28-
import proxy from './plugins/proxy';
29-
import techdocs from './plugins/techdocs';
30-
import search from './plugins/search';
31-
import { PluginEnvironment } from './types';
32-
import { ServerPermissionClient } from '@backstage/plugin-permission-node';
33-
import { DefaultIdentityClient } from '@backstage/plugin-auth-node';
4+
const backend = createBackend();
345

35-
function makeCreateEnv(config: Config) {
36-
const root = getRootLogger();
37-
const reader = UrlReaders.default({ logger: root, config });
38-
const discovery = HostDiscovery.fromConfig(config);
39-
const cacheManager = CacheManager.fromConfig(config);
40-
const databaseManager = DatabaseManager.fromConfig(config, { logger: root });
41-
const tokenManager = ServerTokenManager.noop();
42-
const taskScheduler = TaskScheduler.fromConfig(config, { databaseManager });
6+
backend.add(import('@backstage/plugin-app-backend'));
7+
// backend.add(import('@spotify/backstage-plugin-soundcheck-backend'));
8+
backend.add(import('@backstage/plugin-proxy-backend'))
9+
backend.add(import('@backstage/plugin-scaffolder-backend'));
10+
backend.add(import('@backstage/plugin-techdocs-backend'));
4311

44-
const identity = DefaultIdentityClient.create({
45-
discovery,
46-
});
47-
const permissions = ServerPermissionClient.fromConfig(config, {
48-
discovery,
49-
tokenManager,
50-
});
12+
// Add the auth backend
13+
backend.add(import('@backstage/plugin-auth-backend'));
14+
backend.add(import('@backstage/plugin-auth-backend-module-google-provider'));
15+
// backend.add(customGoogleAuth);
5116

52-
root.info(`Created UrlReader ${reader}`);
17+
// Add the catalog backend and the catalog entities
18+
backend.add(import('@backstage/plugin-catalog-backend'));
19+
backend.add(import('@backstage/plugin-catalog-backend-module-scaffolder-entity-model'),
20+
);
5321

54-
return (plugin: string): PluginEnvironment => {
55-
const logger = root.child({ type: 'plugin', plugin });
56-
const database = databaseManager.forPlugin(plugin);
57-
const cache = cacheManager.forPlugin(plugin);
58-
const scheduler = taskScheduler.forPlugin(plugin);
59-
return {
60-
logger,
61-
database,
62-
cache,
63-
config,
64-
reader,
65-
discovery,
66-
tokenManager,
67-
scheduler,
68-
permissions,
69-
identity,
70-
};
71-
};
72-
}
22+
backend.add(import('@backstage/plugin-permission-backend'));
23+
backend.add(
24+
import('@backstage/plugin-permission-backend-module-allow-all-policy'),
25+
);
7326

74-
async function main() {
75-
const config = await loadBackendConfig({
76-
argv: process.argv,
77-
logger: getRootLogger(),
78-
});
79-
const createEnv = makeCreateEnv(config);
27+
backend.add(import('@backstage/plugin-search-backend'));
28+
backend.add(import('@backstage/plugin-search-backend-module-pg'));
8029

81-
const catalogEnv = useHotMemoize(module, () => createEnv('catalog'));
82-
const scaffolderEnv = useHotMemoize(module, () => createEnv('scaffolder'));
83-
const authEnv = useHotMemoize(module, () => createEnv('auth'));
84-
const proxyEnv = useHotMemoize(module, () => createEnv('proxy'));
85-
const techdocsEnv = useHotMemoize(module, () => createEnv('techdocs'));
86-
const searchEnv = useHotMemoize(module, () => createEnv('search'));
87-
const appEnv = useHotMemoize(module, () => createEnv('app'));
30+
backend.add(import('@backstage/plugin-search-backend-module-catalog'));
31+
backend.add(import('@backstage/plugin-search-backend-module-techdocs'));
8832

33+
backend.add(import('@backstage/plugin-kubernetes-backend'));
8934

90-
const apiRouter = Router();
91-
apiRouter.use('/catalog', await catalog(catalogEnv));
92-
apiRouter.use('/scaffolder', await scaffolder(scaffolderEnv));
93-
apiRouter.use('/auth', await auth(authEnv));
94-
apiRouter.use('/techdocs', await techdocs(techdocsEnv));
95-
apiRouter.use('/proxy', await proxy(proxyEnv));
96-
apiRouter.use('/search', await search(searchEnv));
9735

98-
99-
// Add backends ABOVE this line; this 404 handler is the catch-all fallback
100-
apiRouter.use(notFoundHandler());
101-
102-
const service = createServiceBuilder(module)
103-
.loadConfig(config)
104-
.addRouter('/api', apiRouter)
105-
.addRouter('', await app(appEnv));
106-
107-
await service.start().catch(err => {
108-
console.log(err);
109-
process.exit(1);
110-
});
111-
}
112-
113-
module.hot?.accept();
114-
main().catch(error => {
115-
console.error('Backend failed to start up', error);
116-
process.exit(1);
117-
});
36+
backend.start();

0 commit comments

Comments
 (0)