diff --git a/autobuild-docs/setup/backend/running-backend-containers.md b/autobuild-docs/setup/backend/running-containers.md similarity index 53% rename from autobuild-docs/setup/backend/running-backend-containers.md rename to autobuild-docs/setup/backend/running-containers.md index 1e529dc9..cc7def2a 100644 --- a/autobuild-docs/setup/backend/running-backend-containers.md +++ b/autobuild-docs/setup/backend/running-containers.md @@ -1,30 +1,39 @@ -# Run backend containers +# Run containers -## App stack only +## Full stack (app + UI) -From project root, build and start the application and database: +From project root, build and start the full application stack — backend, database, Keycloak, feature flags, and the UI: ```bash -docker build -t pipeline-app . -docker compose --env-file .env.local up -d +docker compose --env-file .env.local up --build -d ``` +This spins up all services defined in `docker-compose.yml` including `pipeline-ui` (served at http://localhost:3000). + ## App stack + monitoring -Starts the app stack together with the full monitoring stack (Grafana, Loki, Prometheus, Alloy). All services start in dependency order automatically: +Runs the full stack (as above) and adds the monitoring stack (Grafana, Loki, Prometheus, Alloy) on top of it: ```bash -docker build -t pipeline-app . docker compose --env-file .env.local \ -f docker-compose.yml \ -f monitoring/docker-compose-monitoring.yml \ -f monitoring/docker-compose-monitoring-integration.yml \ - up -d + up --build -d ``` Monitoring UIs available at: -- Grafana: http://localhost:3000 +- Grafana: http://localhost:3001 - Alloy: http://localhost:12345 - Prometheus: http://localhost:9090 +## UI with mock API (no backend) + +Runs only the UI and a Prism mock server — no database, Keycloak, or backend required: +```bash +docker compose -f docker-compose-mock.yml up --build -d +``` + +The UI is served at http://localhost:3000. API calls are handled by the Prism mock at http://localhost:4010, driven by the OpenAPI spec. Authentication uses a local mock user instead of Keycloak. + ## Stopping ```bash diff --git a/autobuild-docs/setup/dev-env-setup.md b/autobuild-docs/setup/dev-env-setup.md index 41e3f17d..006f5501 100644 --- a/autobuild-docs/setup/dev-env-setup.md +++ b/autobuild-docs/setup/dev-env-setup.md @@ -13,7 +13,7 @@ Ensure you have atleast JAVA 17, Node 22 and Apache Maven 3.9 installed and conf npm ci ``` See [Local Backend Execution](./backend/local-backend-execution.md) for running the application locally. -See [Running Backend Container](./backend/running-backend-containers.md) for running containerized backend with db. +See [Running Containers](./backend/running-containers.md) for running the full containerized stack. For the ease of local development install [VS Code](https://code.visualstudio.com/) and the following extensions, 1. [JAVA Extension Pack](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) diff --git a/docker-compose.yml b/docker-compose.yml index ae88a3d8..c2e690c3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,12 +9,14 @@ networks: services: mysql-db: image: mysql:8.0 + profiles: + - full container_name: mysql-db environment: - MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} + MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-} MYSQL_DATABASE: pipeline - MYSQL_USER: ${DB_USERNAME} - MYSQL_PASSWORD: ${DB_PASSWORD} + MYSQL_USER: ${DB_USERNAME:-} + MYSQL_PASSWORD: ${DB_PASSWORD:-} ports: - "3306:3306" volumes: @@ -28,14 +30,16 @@ services: retries: 10 auth-service: image: quay.io/keycloak/keycloak:26.2.5 + profiles: + - full container_name: auth-service environment: KEYCLOAK_ADMIN: admin KEYCLOAK_ADMIN_PASSWORD: admin - KC_DB: ${DB} - KC_DB_URL: ${DB_URL} - KC_DB_USERNAME: ${DB_USERNAME} - KC_DB_PASSWORD: ${DB_PASSWORD} + KC_DB: ${DB:-} + KC_DB_URL: ${DB_URL:-} + KC_DB_USERNAME: ${DB_USERNAME:-} + KC_DB_PASSWORD: ${DB_PASSWORD:-} KC_HOSTNAME: http://localhost:8180 KC_HOSTNAME_STRICT: false KC_HEALTH_ENABLED: true @@ -59,6 +63,8 @@ services: condition: service_healthy flagd: image: ghcr.io/open-feature/flagd:latest + profiles: + - full container_name: flagd command: start --uri file:./etc/flagd/feature-flags.json volumes: @@ -71,13 +77,15 @@ services: build: context: . dockerfile: pipeline/Dockerfile + profiles: + - full image: pipeline-app container_name: pipeline-app environment: SPRING_PROFILES_ACTIVE: demo - DB_URL: ${DB_URL} - DB_USER: ${DB_USERNAME} - DB_PASSWORD: ${DB_PASSWORD} + DB_URL: ${DB_URL:-} + DB_USER: ${DB_USERNAME:-} + DB_PASSWORD: ${DB_PASSWORD:-} AUTH_HOST: auth-service AUTH_PORT: 8080 OTEL_SERVICE_NAME: pipeline-app @@ -96,6 +104,18 @@ services: condition: service_healthy flagd: condition: service_started + mock-api: + image: stoplight/prism:5 + profiles: + - mock + command: mock /spec/pipeline-service.yaml -h 0.0.0.0 --dynamic --multiprocess=false + volumes: + - ./apis/openapi-spec/pipeline-service.yaml:/spec/pipeline-service.yaml + ports: + - "4010:4010" + networks: + - app + pipeline-ui: build: context: . @@ -106,11 +126,28 @@ services: VITE_KC_URL: http://localhost:8180 VITE_KC_REALM: SpringBootRealm VITE_KC_CLIENTID: pipeline-app + profiles: + - full image: pipeline-ui ports: - - "3000:3000" + - "3001:3000" networks: - app depends_on: pipeline-app: condition: service_started + + pipeline-ui-mock: + build: + context: . + dockerfile: pipeline-ui/Dockerfile + args: + ENV_FILE: .env.local-with-mock + profiles: + - mock + ports: + - "3001:3000" + networks: + - app + depends_on: + - mock-api diff --git a/monitoring/docker-compose-monitoring.yml b/monitoring/docker-compose-monitoring.yml index 073a1e73..74108e55 100644 --- a/monitoring/docker-compose-monitoring.yml +++ b/monitoring/docker-compose-monitoring.yml @@ -65,7 +65,7 @@ services: - GF_AUTH_BASIC_ENABLED=false - GF_INSTALL_PLUGINS=grafana-lokiexplore-app ports: - - 3000:3000/tcp + - 3001:3000/tcp volumes: - ${MONITORING_STACK_DIR:-.}/grafana/datasource.yml:/etc/grafana/provisioning/datasources/datasources.yml - grafana_data:/var/lib/grafana diff --git a/pipeline-ui/.dockerignore b/pipeline-ui/.dockerignore index b1ef71cb..c18a0397 100644 --- a/pipeline-ui/.dockerignore +++ b/pipeline-ui/.dockerignore @@ -2,6 +2,8 @@ node_modules/ dist/ coverage/ .env.* +!.env.local-e2e +!.env.local-with-mock test/ *.md .git diff --git a/pipeline-ui/.env.local b/pipeline-ui/.env.local deleted file mode 100644 index c75efeaf..00000000 --- a/pipeline-ui/.env.local +++ /dev/null @@ -1,5 +0,0 @@ -VITE_API_BASE_URL=http://pipeline-app:8080/api/v1 -VITE_IDP=keycloak -VITE_KC_URL=http://auth-service:8080 -VITE_KC_REALM=SpringBootRealm -VITE_KC_CLIENTID=pipeline-app diff --git a/pipeline-ui/.env.local-e2e b/pipeline-ui/.env.local-e2e index 3399d1ec..05fb9267 100644 --- a/pipeline-ui/.env.local-e2e +++ b/pipeline-ui/.env.local-e2e @@ -3,4 +3,10 @@ VITE_API_BASE_URL=http://localhost:8080/api/v1 VITE_IDP=keycloak VITE_KC_URL=http://localhost:8180 VITE_KC_REALM=SpringBootRealm -VITE_KC_CLIENTID=pipeline-app \ No newline at end of file +VITE_KC_CLIENTID=pipeline-app + +DB=mysql +DB_URL=jdbc:mysql://mysql-db:3306/pipeline?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC +DB_USERNAME=testuser +DB_PASSWORD=testpass +DB_ROOT_PASSWORD=root \ No newline at end of file diff --git a/pipeline-ui/.env.local-with-mock b/pipeline-ui/.env.local-with-mock index 6a1812af..64fc3ee9 100644 --- a/pipeline-ui/.env.local-with-mock +++ b/pipeline-ui/.env.local-with-mock @@ -1,4 +1,5 @@ VITE_ENV=local VITE_API_BASE_URL=http://127.0.0.1:4010 +VITE_IDP=mock VITE_MOCK_USER=dummy VITE_MOCK_USER_EMAIL=dummy@dummy.com \ No newline at end of file diff --git a/pipeline-ui/.nvmrc b/pipeline-ui/.nvmrc new file mode 100644 index 00000000..2bd5a0a9 --- /dev/null +++ b/pipeline-ui/.nvmrc @@ -0,0 +1 @@ +22 diff --git a/pipeline-ui/Dockerfile b/pipeline-ui/Dockerfile index 7887a595..c5c2dedc 100644 --- a/pipeline-ui/Dockerfile +++ b/pipeline-ui/Dockerfile @@ -15,6 +15,11 @@ COPY pipeline-ui/tailwind.config.js pipeline-ui/postcss.config.js ./ COPY pipeline-ui/openapitools.json . COPY apis/openapi-spec /apis/openapi-spec RUN npm run generate:client-code +# Copy all env files so they are available as an optional override. +# Pass --build-arg ENV_FILE=.env.local-e2e to use a specific env file; +# omit it to fall back to the defaults below. +COPY pipeline-ui/.env* ./ +ARG ENV_FILE ARG VITE_API_BASE_URL=http://localhost:8080/api/v1 ARG VITE_IDP=keycloak ARG VITE_KC_URL=http://localhost:8180 @@ -25,7 +30,10 @@ ENV VITE_IDP=${VITE_IDP} ENV VITE_KC_URL=${VITE_KC_URL} ENV VITE_KC_REALM=${VITE_KC_REALM} ENV VITE_KC_CLIENTID=${VITE_KC_CLIENTID} -RUN npm run build +RUN if [ -n "$ENV_FILE" ] && [ -f "$ENV_FILE" ]; then \ + grep -v '^#' "$ENV_FILE" | grep -v '^VITE_ENV' > /tmp/.env.filtered; \ + set -a && . /tmp/.env.filtered && set +a && rm /tmp/.env.filtered; \ + fi && npm run build # # Serve stage diff --git a/pipeline-ui/README.md b/pipeline-ui/README.md index 4dcad1f9..ad1332d1 100644 --- a/pipeline-ui/README.md +++ b/pipeline-ui/README.md @@ -1,72 +1,50 @@ -# React + TypeScript + Vite +# Pipeline UI -This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. +React + TypeScript + Vite frontend for the AutoBuild pipeline service. -Currently, two official plugins are available: +## Prerequisites -- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh -- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh +- Node.js 22 (see [.nvmrc](.nvmrc)) +- npm -## React Compiler +## Getting Started -The React Compiler is currently not compatible with SWC. See [this issue](https://github.com/vitejs/vite-plugin-react/issues/428) for tracking the progress. +> **Prerequisite:** Java must be installed — the API client generator (`openapi-generator-cli`) requires a JVM to run. -## Expanding the ESLint configuration +```bash +npm install +npm run generate:clean-client-code +``` -If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules: +## Running Locally -```js -export default defineConfig([ - globalIgnores(['dist']), - { - files: ['**/*.{ts,tsx}'], - extends: [ - // Other configs... +| Command | Description | +|---|---| +| `npm run local-e2e` | Vite dev server using `.env.local-e2e` (connects to real local backend + Keycloak) | +| `npm run local-with-mock` | Vite dev server with mocked API (no backend required) | +| `npm run production` | Build + preview with production settings | - // Remove tseslint.configs.recommended and replace with this - tseslint.configs.recommendedTypeChecked, - // Alternatively, use this for stricter rules - tseslint.configs.strictTypeChecked, - // Optionally, add this for stylistic rules - tseslint.configs.stylisticTypeChecked, +## Environment Files - // Other configs... - ], - languageOptions: { - parserOptions: { - project: ['./tsconfig.node.json', './tsconfig.app.json'], - tsconfigRootDir: import.meta.dirname, - }, - // other options... - }, - }, -]) -``` +| File | Mode | Purpose | +|---|---|---| +| `.env.local-e2e` | `local-e2e` | Local end-to-end testing against a locally running backend and Keycloak | +| `.env.local-with-mock` | `local-with-mock` | Local development with a mocked OpenAPI server (no real backend) | -You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules: +## ESLint -```js -// eslint.config.js -import reactX from 'eslint-plugin-react-x' -import reactDom from 'eslint-plugin-react-dom' +For type-aware lint rules in production applications, update `eslint.config.js` to extend `tseslint.configs.recommendedTypeChecked` and set `parserOptions.project`: +```js export default defineConfig([ - globalIgnores(['dist']), { files: ['**/*.{ts,tsx}'], - extends: [ - // Other configs... - // Enable lint rules for React - reactX.configs['recommended-typescript'], - // Enable lint rules for React DOM - reactDom.configs.recommended, - ], + extends: [tseslint.configs.recommendedTypeChecked], languageOptions: { parserOptions: { project: ['./tsconfig.node.json', './tsconfig.app.json'], tsconfigRootDir: import.meta.dirname, }, - // other options... }, }, ])