# Environment Strategy Source of truth: `src/Program.cs` + `src/Database/DatabaseMigrator.cs` + `.woodpecker/build-arm.yml`. ## Environments Branch-driven from CI: | Branch | Image tag | Intended environment | |--------|-----------|----------------------| | `dev` | `dev-arm` | Development (shared) | | `stage` | `stage-arm` | Pre-production | | `main` | `main-arm` | Production | The service binary is identical across environments — all variation is **runtime configuration via env vars** (no per-environment build flags). ## Configuration sources (priority order, per `Program.cs`) 1. `Environment.GetEnvironmentVariable("KEY")`. 2. ASP.NET Core `IConfiguration` (`builder.Configuration["KEY"]`) — covers `appsettings.json`, command-line args, etc. 3. **No hard-coded fallback for security-sensitive values.** `DATABASE_URL`, `JWT_ISSUER`, `JWT_AUDIENCE`, `JWT_JWKS_URL`, and (in `Production`) a non-empty `CorsConfig:AllowedOrigins` are required; missing values cause startup to fail fast via `ConfigurationResolver.ResolveRequiredOrThrow` / `CorsConfigurationValidator.EnsureSafeForEnvironment`. ## Required environment variables | Variable | Purpose | Default | Production action | |----------|---------|---------|---------------------| | `DATABASE_URL` | Postgres connection (URL or LinqToDB conn string) | — (required, fail-fast) | **MUST set** | | `JWT_ISSUER` | Expected `iss` claim; must match admin's `JwtConfig:Issuer` | — (required, fail-fast) | **MUST set** | | `JWT_AUDIENCE` | Expected `aud` claim; must match admin's `JwtConfig:Audience` | — (required, fail-fast) | **MUST set** | | `JWT_JWKS_URL` | Admin's JWKS endpoint (HTTPS) | — (required, fail-fast) | `https://admin.azaion.com/.well-known/jwks.json` | | `CorsConfig__AllowedOrigins__0` | First allowed CORS origin (array via `__N` indices) | — | **MUST set** (or `CorsConfig__AllowAnyOrigin=true`) in Production | | `CorsConfig__AllowAnyOrigin` | Opt-in to permissive CORS (non-production only) | `false` | Leave `false` in Production | | `RABBITMQ_HOST` | Stream host | `127.0.0.1` | Override | | `RABBITMQ_STREAM_PORT` | Stream port | `5552` | Override if non-default | | `RABBITMQ_PRODUCER_USER` | Stream user | `azaion_producer` | Override | | `RABBITMQ_PRODUCER_PASS` | Stream password | `producer_pass` | Override | | `RABBITMQ_STREAM_NAME` | Stream name | `azaion-annotations` | Usually keep (suite contract) | `JWT_SECRET` was removed in this cycle — annotations no longer mints HS256 tokens; admin is the sole token issuer (ES256). ## URL format conversion `Program.cs` accepts `DATABASE_URL` either as a Linq2DB connection string or as a `postgresql://user:pass@host:port/db` URL. The `ConvertPostgresUrl` helper rewrites the URL form into LinqToDB conn-string form. This means operators can use either ENV-style URLs (kubectl/Postgres operator output) or `Host=...` directly. ## DB-driven configuration Several runtime concerns are stored in **database tables**, not env: - **Filesystem roots** — `directory_settings` (defaults `/data/...`). Updated via `PUT /settings/directories`; **must trigger** `PathResolver.Reset` for the change to take effect (Flow F7). - **System settings** — `system_settings` (`generate_annotated_image`, `silent_detection`, thumbnail dimensions). - **User settings** — `user_settings` (per UI session prefs). Operators changing filesystem layout in production need an `ADM` JWT and the right cluster connectivity, **not** a redeploy. ## Filesystem mounts The container expects `/data/` (or whatever `directory_settings` points at) to be a **writable persistent mount**: - `/data/images` — annotation full images - `/data/labels` — YOLO `.txt` files - `/data/thumbnails` — thumbnails - `/data/results` — annotated images (when `generate_annotated_image=true`) - `/data/videos` — media uploads - `/data/gps_sat`, `/data/gps_route` — GPS overlays Without these mounts, every annotation-create / media-upload flow returns 500 from `ErrorHandlingMiddleware` (FS write fails). ## Config drift between environments Today, environment-specific config is held wherever the deployment platform places env vars (Helm values / Kustomize overlays / Compose files in `_infra/`). This repo intentionally does not commit per-environment values; the only environment-aware file in-repo is `.woodpecker/build-arm.yml`. ## Open items - No `appsettings.Production.json` — all env-specific config is operator-supplied. - `Swagger UI` is mounted in all environments (ADR-005); production exposure must be controlled at the perimeter.