Skip to content

Commit 05a5fc0

Browse files
authored
feat: action create backend, organization, project, workspace (#2)
2 parents a2b0353 + 7181f03 commit 05a5fc0

30 files changed

+3289
-56
lines changed

.changeset/slick-ghosts-retire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'backend': patch
3+
---
4+
5+
add package @kusionstack/plugin-scaffolder-backend-module-kusion.

.changeset/tricky-files-smash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@kusionstack/plugin-scaffolder-backend-module-kusion': minor
3+
---
4+
5+
add create action for backend, organization, project, and workspace.

app-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ catalog:
9494
rules:
9595
- allow: [User, Group]
9696

97+
- type: file
98+
target: ../../examples/template/scaffolder.yaml
99+
rules:
100+
- allow: [Template]
101+
97102
## Uncomment these lines to add more example data
98103
# - type: url
99104
# target: https://github.com/backstage/backstage/blob/master/packages/catalog-model/examples/all.yaml
@@ -111,3 +116,7 @@ kubernetes:
111116
permission:
112117
# setting this to `false` will disable permissions
113118
enabled: true
119+
120+
# kusion
121+
kusion:
122+
baseUrl: ${KUSION_BASE_URL}

examples/template/scaffolder.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
apiVersion: scaffolder.backstage.io/v1beta3
2+
kind: Template
3+
metadata:
4+
name: create-kusion-backend
5+
title: Create Kusion Backend
6+
description: Template to create a new Kusion Backend.
7+
spec:
8+
owner: KusionStack
9+
type: service
10+
11+
parameters:
12+
- title: Backend Information
13+
required:
14+
- name
15+
- backendType
16+
properties:
17+
name:
18+
title: Backend Name
19+
type: string
20+
description: The name of the backend to create.
21+
pattern: ^[a-zA-Z0-9_-]+$
22+
23+
description:
24+
title: Backend Description
25+
type: string
26+
description: A description for the backend.
27+
backendType:
28+
title: Backend Type
29+
type: string
30+
description: The type of backend (e.g., local, s3, etc).
31+
enum:
32+
- local
33+
- oss
34+
- s3
35+
- google
36+
markdown:
37+
type: 'null' # Needs to be quoted
38+
description: |
39+
### ❗ **Important**: Please fill in the backend configs according to the backend type.
40+
* [Kusion Backend concepts](https://www.kusionstack.io/docs/concepts/backend/overview)
41+
backendConfigs:
42+
title: Backend Configs
43+
type: object
44+
additionalProperties:
45+
type: string
46+
description: Key-value pairs for backend configuration.
47+
48+
steps:
49+
- id: createBackend
50+
name: Create Backend
51+
action: kusion:backend:create
52+
input:
53+
name: ${{ parameters.name }}
54+
description: ${{ parameters.description }}
55+
backendConfig:
56+
type: ${{ parameters.backendType }}
57+
configs: ${{ parameters.backendConfigs }}
58+
59+
output:
60+
text:
61+
- title: Information
62+
content: |
63+
* success: ${{ steps.createBackend.output.success }}
64+
* message: ${{ steps.createBackend.output.message }}
65+
* data: ${{ steps.createBackend.output.data }}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"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",
12+
"build:api-reports": "yarn build:api-reports:only --tsc",
13+
"build:api-reports:only": "LANG=en_US.UTF-8 NODE_OPTIONS=--max-old-space-size=8192 backstage-repo-tools api-reports --sql-reports --allow-warnings 'plugins/*' -o ae-undocumented,ae-wrong-input-file-type --validate-release-tags",
1214
"build:backend": "yarn workspace backend build",
1315
"build:all": "backstage-cli repo build --all",
1416
"build-image": "yarn workspace backend build-image",
@@ -33,6 +35,7 @@
3335
"devDependencies": {
3436
"@backstage/cli": "^0.29.0",
3537
"@backstage/e2e-test-utils": "^0.1.1",
38+
"@backstage/repo-tools": "^0.13.2",
3639
"@changesets/cli": "^2.29.4",
3740
"@octokit/rest": "^21.1.1",
3841
"@playwright/test": "^1.32.3",

packages/backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@backstage/plugin-search-backend-module-techdocs": "^0.3.2",
4040
"@backstage/plugin-search-backend-node": "^1.3.5",
4141
"@backstage/plugin-techdocs-backend": "^1.11.2",
42+
"@kusionstack/plugin-scaffolder-backend-module-kusion": "^0.0.0",
4243
"app": "link:../app",
4344
"better-sqlite3": "^9.0.0",
4445
"node-gyp": "^10.0.0",

packages/backend/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ backend.add(import('@backstage/plugin-search-backend-module-techdocs'));
5151
// kubernetes
5252
backend.add(import('@backstage/plugin-kubernetes-backend'));
5353

54+
// kusion
55+
backend.add(import('@kusionstack/plugin-scaffolder-backend-module-kusion'));
56+
5457
backend.start();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Backstage Scaffolder Backend Module for Kusion
2+
3+
## Overview
4+
5+
This plugin integrates [KusionStack](https://github.com/KusionStack/kusion) with Backstage's scaffolder backend, enabling you to create and manage Kusion backends directly from Backstage templates.
6+
7+
---
8+
9+
## Prerequisites
10+
11+
- A running [Kusion Server](https://github.com/KusionStack/kusion)
12+
- A Backstage instance (see [Backstage documentation](https://backstage.io/docs/getting-started/))
13+
14+
---
15+
16+
## Installation
17+
18+
From your Backstage root directory, install the plugin:
19+
20+
```bash
21+
yarn add --cwd packages/backend @kusionstack/plugin-scaffolder-backend-module-kusion
22+
```
23+
24+
---
25+
26+
## Configuration
27+
28+
Add the following configuration to your `app-config.yaml` to specify the Kusion server endpoint:
29+
30+
```yaml
31+
backend:
32+
kusion:
33+
baseUrl: 'http://localhost:3000' # Replace with your Kusion server URL
34+
```
35+
36+
---
37+
38+
## Backend Integration
39+
40+
Import and register the plugin in your Backstage backend:
41+
42+
Edit `packages/backend/src/index.ts`:
43+
44+
```typescript
45+
// Import and register the Kusion scaffolder backend module
46+
backend.add(import('@kusionstack/plugin-scaffolder-backend-module-kusion'));
47+
```
48+
49+
---
50+
51+
## Usage Example
52+
53+
### Kusion Backend Creation Template.
54+
55+
`kusion:backend:create`
56+
57+
```yaml
58+
apiVersion: scaffolder.backstage.io/v1beta3
59+
kind: Template
60+
metadata:
61+
name: create-kusion-backend
62+
title: Create Kusion Backend
63+
description: Template to create a new Kusion Backend.
64+
spec:
65+
owner: KusionStack
66+
type: service
67+
steps:
68+
- id: createBackend
69+
name: Create Backend
70+
action: kusion:backend:create
71+
input:
72+
name: ${{ parameters.name }}
73+
description: ${{ parameters.description }}
74+
backendConfig:
75+
type: ${{ parameters.backendType }}
76+
configs: ${{ parameters.backendConfigs }}
77+
78+
output:
79+
text:
80+
- title: Information
81+
content: |
82+
* success: ${{ steps.createBackend.output.success }}
83+
* message: ${{ steps.createBackend.output.message }}
84+
* data: ${{ steps.createBackend.output.data }}
85+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: backstage.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: backstage-plugin-scaffolder-backend-module-kusion
5+
title: '@kusionstack/plugin-scaffolder-backend-module-kusion'
6+
description: The kusion backend module for the scaffolder plugin provide by KusionStack team
7+
spec:
8+
lifecycle: experimental
9+
type: backstage-backend-plugin-module
10+
owner: maintainers

0 commit comments

Comments
 (0)