Skip to content

feat: read UI API and auth config at container start [#236] - #50

Open
hariharanweb wants to merge 3 commits into
mainfrom
feat/236-ui-runtime-config
Open

hariharanweb wants to merge 3 commits into
mainfrom
feat/236-ui-runtime-config

Conversation

@hariharanweb

@hariharanweb hariharanweb commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Part of OpenAgriNet/engineering-tracker#236 (deploying KP to K8s): one UI image for every environment, configured with env vars instead of rebuilds.

What changes

  • At container start, /docker-entrypoint.d/40-runtime-config.sh renders /knowledge-provider/config.js (window.__ENV__) from container env. If a config.js is mounted (e.g. a ConfigMap), it is kept as is.
  • ui/src/runtimeEnv.js getEnv() reads window.__ENV__ first, then the build-time VITE_* value. config.js and auth/keycloak.js read through it.
  • Runtime vars: API_BASE, AUTH_ENABLED, KEYCLOAK_URL, KEYCLOAK_REALM, KEYCLOAK_CLIENT_ID, KEYCLOAK_IDP_HINT, DOCUMENT_VALIDITY_ENABLED. VITE_BASE stays a build arg.
  • nginx serves config.js with Cache-Control: no-store.
  • Local npm run dev is unchanged (ui/public/config.js is an empty window.__ENV__).

Behaviour changes to note

  • The UI's public path is now /knowledge-provider/ everywhere: compose, .env.example, ui/.env.example, deploy/nginx-docs-pipeline.snippet.conf and scripts/deploy-compose.sh. The image only serves that path (since 7c1b780). The API path /docs-pipeline-api/ is unchanged.

Before deploying to the shared registry host

  • Its live nginx still routes /docs-pipeline/; it must route /knowledge-provider/ → 127.0.0.1:3011/knowledge-provider/ (see the updated snippet).
  • Set VITE_BASE=/knowledge-provider/ and DOCS_PIPELINE_UI_URL=…/knowledge-provider in that host's .env.
  • Add <host>/knowledge-provider/login and <host>/knowledge-provider/auth/sso-callback to the Keycloak client's Valid Redirect URIs.
  • scripts/export-prod-images.sh no longer bakes in the production Keycloak values; set them as container env per deployment.
  • Image defaults keep fix(ui): point the prod build at Keycloak on its own origin, /auth #49's intent as runtime defaults: AUTH_ENABLED=true, KEYCLOAK_URL=/auth (same origin), KEYCLOAK_REALM=docs-pipeline, KEYCLOAK_CLIENT_ID=docs-pipeline-ui.
  • DOCUMENT_VALIDITY_ENABLED defaults to true, matching the previous Dockerfile.prod default.
  • .env.example / ui/.env.example mark which UI vars are runtime and which are build-time; VITE_DOCUMENT_VALIDITY_ENABLED added to the root example.

Docs: docs/ADR/0008-ui-config-at-container-start.md, ENV.md.

Testing

  • npm test: 29 passed, including new runtimeEnv tests. npm run build and eslint clean.
  • Built the image, ran with -e API_BASE=/env-a-api -e AUTH_ENABLED=true: the served config.js had those values and Cache-Control: no-store; the startup log shows 40-runtime-config.sh running after nginx's own scripts.
  • Inside the container: a provided config.js is kept, a generated one is regenerated with new env, and a directory at the target path exits 1. Not tested with a real -v mount.
  • docker compose -f docker-compose.yml config shows the new env on ui.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

hariharanweb and others added 2 commits November 16, 2026 14:43
- config.js (window.__ENV__) rendered from container env by
  /docker-entrypoint.d/40-runtime-config.sh; a mounted config.js is kept
- UI reads window.__ENV__ first, falls back to build-time VITE_* values
- API_BASE, AUTH_ENABLED, KEYCLOAK_*, DOCUMENT_VALIDITY_ENABLED are runtime;
  VITE_BASE stays a build arg
- compose builds for /knowledge-provider/, matching what the image serves
- ADR 0008 and ENV.md document the runtime vars

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- .env.example: API/auth/Keycloak/validity are runtime (restart ui);
  VITE_BASE stays a build arg; add VITE_DOCUMENT_VALIDITY_ENABLED
- ui/.env.example: note the production image takes these as container env

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hariharanweb
hariharanweb force-pushed the feat/236-ui-runtime-config branch from 9f39f1c to 5b5fb5c Compare November 16, 2026 09:16
The image only serves /knowledge-provider/ (since 7c1b780), so the
shared-host nginx snippet, .env examples and deploy script now use that
path instead of /docs-pipeline/. API path unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant