Commit 72b0b42c authored by Christos Tranoris's avatar Christos Tranoris
Browse files

fixes for helm

parent e7728bbe
Loading
Loading
Loading
Loading
+43
Changes for .changelog/20261013_0020_subpath-hosting-and-harbor-ci.md: 43 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Runtime base path (subpath hosting) + Harbor CI pipeline

**Date:** 2026-10-13

## Why
The Chronos Helm chart (`org.etsi.osl.chronos.deploy`) serves the UI at `{rootUrl}/chronos/` on the OpenSlice host. Until now the UI assumed it lived at `/`:
- `/config.js`, `/vite.svg` and `/assets/*` were absolute paths.
- `BrowserRouter` had no basename.
- The Keycloak redirect URI was `origin + '/'`.

## What changed
- **`vite.config.ts`:** `base: './'`, so asset URLs are relative.
- **`index.html`:**
  - Added a `<base href="/" />` placeholder.
  - `config.js` and `vite.svg` are now referenced relatively.
- **`docker-entrypoint.sh`:**
  - Reads the new `CHRONOS_BASE_PATH` (default `/`) and normalizes it to `/x/`.
  - Rewrites `<base href>` in `index.html`.
  - Writes `VITE_BASE_PATH` into `window.__CHRONOS_CONFIG__`.
  - `CHRONOS_HTML_ROOT` overrides the html directory, which is useful for testing.
- **`src/config.ts`:** new `appConfig.basePath`, taken from optional `VITE_BASE_PATH` and normalized by the exported `normalizeBasePath`.
  - `src/vite-env.d.ts` declares the env var.
- **`src/main.tsx`:**
  - `BrowserRouter basename` is the base path without its trailing slash, so both `/chronos` and `/chronos/` match.
  - Keycloak `redirectUri` is `origin + basePath`.
- **`createKeycloakAuthAdapter(kc, redirectUri?)`:** new optional redirect URI. It is used for the login redirect, and the default is unchanged.
- **`.gitlab-ci.yml` (new):** on a Git tag, Kaniko builds the Dockerfile and pushes `${HARBOR_REGISTRY}/${HARBOR_PROJECT}/org.etsi.osl.chronos.ui:{tag,latest}`. It is the same as the backend pipeline minus the Maven stage.
- **Docs:**
  - `.env.example` gains `VITE_BASE_PATH`.
  - The operations guide gains the env-table row, a new section 3b on serving under a subpath, and updated redirect-URI notes.

The default behaviour (served at `/`) is unchanged, and nginx needs no change because the ingress strips the prefix.

## Verification
- `npm run typecheck` is clean, and eslint is clean on the touched files.
- `src/config.test.ts` passes 16 tests (new basePath default/override tests and a `normalizeBasePath` table).
- `src/adapters` passes 331 tests.
- `vite build` output has relative `./assets/*` URLs.
- Running the entrypoint against `dist/index.html` with `/chronos/`, `chronos`, an empty value and `/a/b` gives the correct `<base href>` and `VITE_BASE_PATH`, and re-running the script rewrites it again.
- **Pre-existing failures, unchanged by this work** (confirmed on a stashed baseline):
  - `npm run lint` reports 107 errors.
  - `test:coverage` has 5 timeouts, in BlackoutFormDialog, BlackoutsPage and CalendarsPage.
- **Not verified:** `docker build` and a browser round-trip behind ingress, since there was no Docker or cluster locally.
+25 −3
Changes for .changelog/guides/operations-guide.md: 25 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ rather than silently misbehaving.
| `VITE_KEYCLOAK_REALM` | Yes | `chronos` | Realm name. |
| `VITE_KEYCLOAK_CLIENT_ID` | Yes | `chronos-ui` | **Public** client id. |
| `VITE_TENANT_TIMEZONE` | No | `Europe/Athens` | IANA zone for display. Defaults to `UTC`. |
| `VITE_BASE_PATH` | No | `/chronos/` | URL path the app is served under. Defaults to `/`. In the Docker image set `CHRONOS_BASE_PATH` instead (see 3b). |

## 3. Build and serve (plain static hosting)

@@ -102,7 +103,7 @@ docker run -d -p 8080:80 \

### How runtime injection works

1. `index.html` loads `/config.js` **before** the app bundle.
1. `index.html` loads `config.js` (relative to `<base href>`) **before** the app bundle.
2. In the image, `config.js` starts as an empty placeholder; the nginx
   entrypoint (`/docker-entrypoint.d/40-chronos-config.sh`) rewrites it from the
   container's `VITE_*` env vars at start-up, defining `window.__CHRONOS_CONFIG__`.
@@ -119,6 +120,27 @@ long-term.
> build intentionally does not gate on types so a type error can't block
> producing a deployable artifact.

## 3b. Serving under a subpath (e.g. `/chronos/` on the OpenSlice host)

The bundle uses relative asset URLs (Vite `base: './'`), and `index.html`
carries a `<base href="/">` placeholder. To serve the app under a path prefix,
set `CHRONOS_BASE_PATH` on the container:

```bash
docker run -d -p 8080:80 -e CHRONOS_BASE_PATH=/chronos/ ... chronos-ui:latest
```

The entrypoint normalizes the value (leading and trailing slash), rewrites
`<base href>` in `index.html`, and writes it as `VITE_BASE_PATH` into
`config.js`. The app then uses it as the router basename and the Keycloak
redirect URI.

nginx still serves from `/`, so the reverse proxy in front must **strip the
prefix**. With ingress-nginx this is `rewrite-target`. The Helm chart in
`org.etsi.osl.chronos.deploy` sets this up: the UI is served at `{rootUrl}/chronos/`
and the API at `{rootUrl}/chronos-api`. Behind a prefix, `VITE_API_BASE_URL` must
be an **absolute** URL.

## 4. Keycloak client setup

Register a **public** client (no client secret — this is a browser SPA using
@@ -128,8 +150,8 @@ PKCE):
- **Access type:** public
- **Standard flow (authorization code):** enabled
- **PKCE:** S256 (the UI requests `pkceMethod: 'S256'`)
- **Valid redirect URIs:** the app origin, e.g. `https://chronos-ui.example.org/`
  (the UI uses `window.location.origin + '/'` as the redirect URI)
- **Valid redirect URIs:** the app URL, e.g. `https://chronos-ui.example.org/` or `https://openslice.example.org/chronos/*` under a subpath
  (the UI uses `window.location.origin + basePath` as the redirect URI)
- **Web origins:** the app origin (for CORS on token/userinfo)
- **Post-logout redirect URI:** the app origin

+1
Changes for .changelog/index.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -94,3 +94,4 @@
| 2026-07-20 21:50 | [Activity view: display `type` and `holdExpiry`](20260720_2150_activity_reservation_type_hold_expiry.md) | Refreshed contract from live backend; new ReservationType domain union + codec decode; Type column, hold-expiry chips, detail rows and calendar markers for tentative holds; also fixes pre-existing schema.d.ts drift; 697 tests passing |
| 2026-07-21 00:08 | [Activity view: cancel reservations and holds](20260721_0008_activity_cancel_reservations.md) | New CancelReservationButton (icon + button variants) wired into the Activity table and detail page; routes to DELETE /reservations/{id} or /reservations/holds/{holdId} by reservation type; capability-gated, state-aware, ConfirmDialog + ProblemDetailAlert; 706 tests passing |
| 2026-07-21 17:00 | [Activity view: `correlationId`](20260721_1700_activity_correlation_id.md) | Refreshed contract from live backend (correlationId on ReservationView + activity query param, new /reservations/cancel schemas); domain + codec + gateway wiring; Correlation ID column and filter on ActivityPage, detail row on ReservationDetailPage; 710 tests |
| 2026-10-13 00:20 | [Runtime base path + Harbor CI](20261013_0020_subpath-hosting-and-harbor-ci.md) | The UI can be served under a path prefix (`CHRONOS_BASE_PATH`, e.g. `/chronos/`) for the Helm chart in `org.etsi.osl.chronos.deploy`: relative assets, a `<base href>` rewritten at container start, router basename and Keycloak redirect from `appConfig.basePath`. New `.gitlab-ci.yml` pushes the image to Harbor on tags. Default `/` unchanged; config and adapter tests pass |
+5
Changes for .env.example: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -9,3 +9,8 @@ VITE_KEYCLOAK_CLIENT_ID=chronos-ui
# Build-time tenant timezone (optional, defaults to UTC)
# Must be a valid IANA timezone string, e.g. "Europe/Athens"
VITE_TENANT_TIMEZONE=UTC

# URL path the app is served under (optional, defaults to "/"), e.g. "/chronos/"
# behind the OpenSlice ingress. In the Docker image set CHRONOS_BASE_PATH
# instead; the entrypoint rewrites <base href> and fills this value.
VITE_BASE_PATH=/
+44
Changes for .gitlab-ci.yml: 44 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Builds and pushes a Docker image to Harbor whenever a Git tag is pushed.
# The tag name becomes the image tag, e.g. pushing tag "v1.4.0" publishes
# ${HARBOR_REGISTRY}/${HARBOR_PROJECT}/org.etsi.osl.chronos.ui:v1.4.0 (and :latest).
#
# The Dockerfile builds the SPA itself (npm ci + vite build) and bakes in no
# environment-specific values, so the image is configured at runtime
# (VITE_* and CHRONOS_BASE_PATH env vars, see docker-entrypoint.sh).
#
# Required CI/CD variables (set once at the `openslice` group level so every
# repo in the group inherits them — Settings > CI/CD > Variables):
#   HARBOR_REGISTRY      e.g. "harbor.intranet.pnet"
#   HARBOR_PROJECT        e.g. "osl-staging"       (Harbor project/namespace)
#   HARBOR_ROBOT_USER      Harbor robot account, e.g. "robot$osl-staging+gitlab-ci"
#   HARBOR_ROBOT_TOKEN     the robot account's token
# Mark HARBOR_ROBOT_USER and HARBOR_ROBOT_TOKEN as "Protected" + "Masked", and
# protect the tag pattern you release with (Settings > Repository > Protected
# tags) so the variables are only ever exposed to a tag pipeline.
#
# harbor.intranet.pnet currently serves plain HTTP only (no TLS listener on
# 443), so the push below runs with Kaniko's --insecure flag. That means the
# robot account credentials and image layers cross the network unencrypted —
# acceptable only because this stays on the trusted intranet segment. Drop
# --insecure once Harbor is put behind TLS.

stages:
  - package

docker_build_push:
  stage: package
  image:
    name: gcr.io/kaniko-project/executor:v1.23.2-debug
    entrypoint: [""]
  rules:
    - if: '$CI_COMMIT_TAG'
  script:
    - echo "Building and pushing ${CI_PROJECT_NAME}:${CI_COMMIT_TAG}"
    - >-
      echo "{\"auths\":{\"${HARBOR_REGISTRY}\":{\"auth\":\"$(printf '%s:%s' "${HARBOR_ROBOT_USER}" "${HARBOR_ROBOT_TOKEN}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor
      --context "${CI_PROJECT_DIR}"
      --dockerfile "${CI_PROJECT_DIR}/Dockerfile"
      --destination "${HARBOR_REGISTRY}/${HARBOR_PROJECT}/${CI_PROJECT_NAME}:${CI_COMMIT_TAG}"
      --destination "${HARBOR_REGISTRY}/${HARBOR_PROJECT}/${CI_PROJECT_NAME}:latest"
      --insecure
Loading