Skip to content

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

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

hariharanweb wants to merge 2 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

  • Compose built the UI for /docs-pipeline/, but the image only serves /knowledge-provider/. It now builds for /knowledge-provider/.
  • scripts/export-prod-images.sh no longer bakes in the production Keycloak values; set them as container env per deployment.
  • 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

- 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>
@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!

- .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>
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