Skip to content

Parametrize database credentials via DB_* environment variables - #950

Open
eduardosmaniotto wants to merge 2 commits into
MUnique:masterfrom
eduardosmaniotto:chore/parametrize-db-credentials
Open

Parametrize database credentials via DB_* environment variables#950
eduardosmaniotto wants to merge 2 commits into
MUnique:masterfrom
eduardosmaniotto:chore/parametrize-db-credentials

Conversation

@eduardosmaniotto

Copy link
Copy Markdown
Contributor

Makes the postgres admin credentials configurable through DB_HOST,
DB_ADMIN_USER, DB_ADMIN_PW (+ DB_NAME for the database name) in
every deployment variant, instead of the hardcoded postgres/admin.

Why

The env override only worked on the all-in-one Startup code path, and even
there the compose files never passed the variables through
(POSTGRES_PASSWORD: admin was hardcoded and the app got no DB_ADMIN_PW).
The distributed Dapr setup ignored the variables completely
(secrets.json + provider had no env support).

Changes

  • New shared DatabaseConnectionStringHelper, used by both
    ConfigFileDatabaseConnectionStringProvider and
    SecretStoreDatabaseConnectionSettingsProvider
  • All compose files (all-in-one, all-in-one-traefik incl. prod,
    distributed) read DB_* with admin/postgres/openmu defaults
    and map them to POSTGRES_* for the database container
  • New deploy/*/.env.example templates; real .env* files gitignored
    (templates stay committable)
  • Docs: compose wiring + first-init caveat (docker.md,
    startup-parameters.md), env-based local dev flow (from-source.md,
    now Windows + Linux)

Backward compatibility

No action needed for existing installs: with no env set, everything
resolves to the previous defaults. POSTGRES_PASSWORD only seeds fresh
volumes, so changing it never alters an existing database (documented).

Testing

  • dotnet build Release (ci=true): EntityFramework, Dapr.Common,
    Startup, 0 errors
  • docker compose config passes for all 4 compose files
  • Verified default render (admin/postgres) and custom render
    (single DB_* source derives both sides), plus a live postgres
    container login with generated credentials

The postgres admin user/password was effectively hardcoded to
postgres/admin across the compose deployments. The all-in-one Startup
path already supported DB_HOST/DB_ADMIN_USER/DB_ADMIN_PW overrides, but
the compose files never passed them through and the distributed Dapr
secret store ignored them entirely.

- Add shared DatabaseConnectionStringHelper and use it in both the
  config-file and the Dapr secret-store connection string providers
- Wire DB_HOST/DB_ADMIN_USER/DB_ADMIN_PW/DB_NAME through all compose
  files (all-in-one, traefik, distributed), mapped to POSTGRES_* for
  the database container
- Add deploy/*/.env.example templates, gitignore real .env files
- Document compose wiring, first-init semantics and local dev setup

Defaults (postgres/admin/openmu) still apply when unset, so existing
installations keep working without changes.
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