Skip to content

Commit 80da471

Browse files
authored
Introduce new x2a workspace (#2134)
* Initial x2a commit Signed-off-by: Marek Libra <marek.libra@gmail.com> * Initial x2a BE a FE plugins Signed-off-by: Marek Libra <marek.libra@gmail.com> * Add dev environment Signed-off-by: Marek Libra <marek.libra@gmail.com> * Very basic structure Signed-off-by: Marek Libra <marek.libra@gmail.com> * prettier Signed-off-by: Marek Libra <marek.libra@gmail.com> * First client-server calls Signed-off-by: Marek Libra <marek.libra@gmail.com> * New migration page Signed-off-by: Marek Libra <marek.libra@gmail.com> * Add New migration wizard Signed-off-by: Marek Libra <marek.libra@gmail.com> * add @backstage/plugin-kubernetes-backend dev dependency Signed-off-by: Marek Libra <marek.libra@gmail.com> * Add backstage repo tools Signed-off-by: Marek Libra <marek.libra@gmail.com> * Add @backstage/backend-openapi-utils Signed-off-by: Marek Libra <marek.libra@gmail.com> * yarn.lock Signed-off-by: Marek Libra <marek.libra@gmail.com> * Use OpenApi Signed-off-by: Marek Libra <marek.libra@gmail.com> * Add database Signed-off-by: Marek Libra <marek.libra@gmail.com> * Rename ConvertorService to X2ADatabaseService Signed-off-by: Marek Libra <marek.libra@gmail.com> * Plugin and router integration tests Signed-off-by: Marek Libra <marek.libra@gmail.com> * Skeleton for KubeService Signed-off-by: Marek Libra <marek.libra@gmail.com> * Fix tests Signed-off-by: Marek Libra <marek.libra@gmail.com> * Adding README file Signed-off-by: Marek Libra <marek.libra@gmail.com> * api report Signed-off-by: Marek Libra <marek.libra@gmail.com> * Add release tags Signed-off-by: Marek Libra <marek.libra@gmail.com> * Add api-reports Signed-off-by: Marek Libra <marek.libra@gmail.com> * changeset Signed-off-by: Marek Libra <marek.libra@gmail.com> * Adding maintainers list * clean up * deps update and dedupe Signed-off-by: Marek Libra <marek.libra@gmail.com> * generated content to prettierignore * api reports * rebuild yarn.lock * backstage-cli repo fix * fixing tests for CI * Update @backstage/backend-defaults dependency * Add error handling to X2ADatabaseService * Add X2ADatabaseService.test.ts * Instantiate KubeService for the router * Align node.js version with RHDH * Unify yarn start with the rest of the repo * Test for non-existing getProjectId() * Align dependency versions with Backstage 1.45.3 * api reports * address SonarCloud findings * Add x2a workspace to .github/CODEOWNERS * Return 404 for deleteing non-existing project --------- Signed-off-by: Marek Libra <marek.libra@gmail.com>
1 parent 84628fe commit 80da471

86 files changed

Lines changed: 32394 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333
/workspaces/theme @redhat-developer/rhdh-ui @ciiay @logonoff
3434
/workspaces/translations @redhat-developer/rhdh-ui @ciiay @debsmita1 @karthikjeeyar
3535
/workspaces/konflux @rrosatti @sahil143 @testcara
36+
/workspaces/x2a @mareklibra @elai-shalev @eloycoto
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-x2a-backend': major
3+
'@red-hat-developer-hub/backstage-plugin-x2a-common': major
4+
'@red-hat-developer-hub/backstage-plugin-x2a': major
5+
---
6+
7+
Initial commit
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "public",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"privatePackages": {
11+
"tag": false,
12+
"version": false
13+
}
14+
}

workspaces/x2a/.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.git
2+
.yarn/cache
3+
.yarn/install-state.gz
4+
node_modules
5+
packages/*/src
6+
packages/*/node_modules
7+
plugins
8+
*.local.yaml

workspaces/x2a/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
playwright.config.ts

workspaces/x2a/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../../.eslintrc.cjs');

workspaces/x2a/.gitignore

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# macOS
2+
.DS_Store
3+
4+
# Logs
5+
logs
6+
*.log
7+
npm-debug.log*
8+
yarn-debug.log*
9+
yarn-error.log*
10+
lerna-debug.log*
11+
12+
# Coverage directory generated when running tests with coverage
13+
coverage
14+
15+
# Dependencies
16+
node_modules/
17+
18+
# Yarn 3 files
19+
.pnp.*
20+
.yarn/*
21+
!.yarn/patches
22+
!.yarn/plugins
23+
!.yarn/releases
24+
!.yarn/sdks
25+
!.yarn/versions
26+
27+
# Node version directives
28+
.nvmrc
29+
30+
# dotenv environment variables file
31+
.env
32+
.env.test
33+
34+
# Build output
35+
dist
36+
dist-types
37+
38+
# Temporary change files created by Vim
39+
*.swp
40+
41+
# MkDocs build output
42+
site
43+
44+
# Local configuration files
45+
*.local.yaml
46+
47+
# Sensitive credentials
48+
*-credentials.yaml
49+
50+
# vscode database functionality support files
51+
*.session.sql
52+
53+
# E2E test reports
54+
e2e-test-report/

workspaces/x2a/.prettierignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
dist
2+
dist-types
3+
coverage
4+
.vscode
5+
.eslintrc.js
6+
7+
generated
8+
report.api.md
9+

workspaces/x2a/README.md

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
# X2Ansible Backstage Plugin
2+
3+
This is a Backstage plugin workspace providing web UI for the [X2Ansible](https://github.com/x2ansible/x2a-convertor) project.
4+
5+
## Development Environment Setup
6+
7+
### Prerequisites
8+
9+
- Node.js >20
10+
- Yarn package manager
11+
- Kubernetes cluster access (optional, for Kubernetes features)
12+
13+
### Installation
14+
15+
1. Install dependencies:
16+
17+
```sh
18+
yarn install
19+
```
20+
21+
2. Start the development environment:
22+
23+
```sh
24+
yarn dev
25+
```
26+
27+
This command runs both the frontend and backend plugins in parallel. The frontend will be available at `http://localhost:3000` and the backend at `http://localhost:7007`.
28+
29+
## Adding New API Endpoints
30+
31+
To add a new API endpoint, follow these steps:
32+
33+
### 1. Update the OpenAPI Specification
34+
35+
Edit `plugins/x2a-backend/src/schema/openapi.yaml` to add your new endpoint definition. For example:
36+
37+
```yaml
38+
paths:
39+
/projects/{projectId}/status:
40+
get:
41+
summary: Returns the status of a project.
42+
parameters:
43+
- in: path
44+
name: projectId
45+
schema:
46+
type: string
47+
required: true
48+
responses:
49+
'200':
50+
description: Project status.
51+
content:
52+
application/json:
53+
schema:
54+
type: object
55+
properties:
56+
status:
57+
type: string
58+
```
59+
60+
### 2. Regenerate the API Code
61+
62+
After updating `openapi.yaml`, regenerate the server and client API code:
63+
64+
```sh
65+
yarn workspace @red-hat-developer-hub/backstage-plugin-x2a-backend openapi-generate
66+
```
67+
68+
This command:
69+
70+
- Generates TypeScript types and server-side code in `plugins/x2a-backend/src/schema/openapi/generated/`
71+
- Generates client-side code in `plugins/x2a-common/client/src/schema/openapi/generated/`
72+
73+
### 3. Implement the Endpoint Handler
74+
75+
**Note:** Always regenerate the API code before implementing new endpoints to ensure TypeScript types are up to date.
76+
77+
Add your endpoint implementation in `plugins/x2a-backend/src/router.ts`. Import the generated types and implement the handler:
78+
79+
```typescript
80+
import { ProjectStatusGet } from './schema/openapi';
81+
82+
router.get('/projects/:projectId/status', async (req, res) => {
83+
const endpoint = 'GET /projects/:projectId/status';
84+
const projectId = req.params.projectId;
85+
86+
// Your implementation here
87+
const status = await x2aDatabase.getProjectStatus({ projectId });
88+
89+
const response: ProjectStatusGet['response'] = status;
90+
res.json(response);
91+
});
92+
```
93+
94+
## Database Configuration
95+
96+
By default, the plugin uses SQLite with an in-memory database for local development. The database configuration is located in `app-config.yaml`:
97+
98+
```yaml
99+
backend:
100+
database:
101+
client: better-sqlite3
102+
connection: ':memory:'
103+
```
104+
105+
### Using a Plugin-Specific Database
106+
107+
To configure a separate database for the x2a plugin:
108+
109+
```yaml
110+
backend:
111+
database:
112+
client: better-sqlite3
113+
connection: ':memory:'
114+
plugin:
115+
x2a:
116+
connection:
117+
filename: ./data/x2a.db
118+
```
119+
120+
### Using Other Database Backends
121+
122+
The plugin uses Knex.js, which supports multiple database backends (PostgreSQL, MySQL, etc.). To use a different database:
123+
124+
1. Install the appropriate database client package (e.g., `pg` for PostgreSQL)
125+
2. Update `app-config.yaml`:
126+
127+
```yaml
128+
backend:
129+
database:
130+
client: pg
131+
connection:
132+
host: localhost
133+
port: 5432
134+
user: postgres
135+
password: ${POSTGRES_PASSWORD}
136+
database: x2a
137+
```
138+
139+
### Database Migrations
140+
141+
Database migrations are located in `plugins/x2a-backend/migrations/`. Migrations run automatically when the backend starts. To create a new migration:
142+
143+
1. Create a new file in `plugins/x2a-backend/migrations/` following the naming pattern: `YYYYMMDDHH_description.ts`
144+
2. Implement `up()` and `down()` functions:
145+
146+
```typescript
147+
import { Knex } from 'knex';
148+
149+
export async function up(knex: Knex): Promise<void> {
150+
await knex.schema.createTable('new_table', table => {
151+
table.uuid('id').primary();
152+
// ... other columns
153+
});
154+
}
155+
156+
export async function down(knex: Knex): Promise<void> {
157+
await knex.schema.dropTable('new_table');
158+
}
159+
```
160+
161+
## Kubernetes Connection Setup
162+
163+
The plugin uses the Kubernetes client library to interact with Kubernetes clusters.
164+
165+
By default, it loads configuration from your local `~/.kube/config` file.
166+
167+
Additional methods are planed to be implemented later.
168+
169+
### Local Development Setup
170+
171+
1. Ensure you have a valid Kubernetes configuration file at `~/.kube/config`
172+
2. The plugin will automatically detect and use this configuration
173+
174+
### Using a Custom Kubeconfig Location
175+
176+
Set the `KUBECONFIG` environment variable to point to your kubeconfig file:
177+
178+
```sh
179+
export KUBECONFIG=/path/to/your/kubeconfig
180+
yarn dev
181+
```
182+
183+
### In-Cluster Configuration
184+
185+
When running inside a Kubernetes cluster, the plugin will automatically fall back to in-cluster configuration if no local kubeconfig is found.
186+
187+
### Verifying Kubernetes Connection
188+
189+
The plugin's `KubeService` provides methods to interact with Kubernetes resources. Check the logs when starting the backend to see if the Kubernetes configuration was loaded successfully:
190+
191+
```
192+
Loaded Kubernetes configuration from ~/.kube/config
193+
```
194+
195+
## Additional Commands
196+
197+
- `yarn test` - Run tests
198+
- `yarn lint` - Run linter
199+
- `prettier:fix` - Fix by prettier
200+
- `yarn build:all` - Build all packages
201+
- `yarn clean` - Clean build artifacts
202+
203+
## Project Structure
204+
205+
- `plugins/x2a/` - Frontend plugin
206+
- `plugins/x2a-backend/` - Backend plugin
207+
- `src/schema/openapi.yaml` - OpenAPI specification
208+
- `src/schema/openapi/generated/` - Generated server-side API code
209+
- `src/router.ts` - API route handlers
210+
- `src/services/` - Business logic services
211+
- `migrations/` - Database migrations
212+
- `plugins/x2a-common/` - Shared code between frontend and backend
213+
- `client/src/schema/openapi/generated/` - Generated client-side API code

0 commit comments

Comments
 (0)