PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
Context
See proposal.md for the motivation. The current state that shapes the approach:
Dockerfile:197copies the developer.env.exampleto/.env, andDockerfile:198strips onlyDATABASE_DSNfrom it. The comment atDockerfile:189-196explains the copy as a source of defaults, but no production setting depends on it (see the table below).backend/internal/config/config.go:145callsgodotenv.Loadand exits the process when the file is missing. The image keeps a file only to satisfy this call.godotenv.Loaddoes not overwrite a variable that already exists, even with an empty value.unsetEmptyEnvVars(config.go:298) then removes empty variables, so the code sees them as unset. That is whySMTP_USER=worked as a workaround while a missingSMTP_USERpicked up the baked test login.backend/internal/util/logger/settings.go:244loads the same file and already ignores a missing one.backend/internal/features/email/di.goderives the security mode from the port only whenSMTP_SECURITYis empty.smtp_transport.openSessionskips authentication when either the username or the password is empty. Both defaults are correct, and the baked file is what bypassed them.docker/start.sh:147decides the frontend's "mail configured" flag from the real environment, while the backend reads the merged one. With no SMTP variables set, the two disagree today.- The frontend stage at
Dockerfile:14-18looks forfrontend/.env.production.example, which was deleted in 082f8f9c.COPY frontend/ ./carries any localfrontend/.env,frontend/.env.local,frontend/.env.productionorfrontend/.env.production.localinto the build, because the.env.localand.env.developmententries in.dockerignorematch only at the root. Vite reads those files inpnpm build, andfrontend/src/constants.ts:32-43falls back toimport.meta.env.VITE_*for the OAuth client IDs, the mail flag and the Turnstile key, so their values would be baked into the bundle.
What production reads from the baked file today, and what replaces it:
| Variable | Replacement after the change |
|---|---|
ENV_MODE |
ENV ENV_MODE=production in the Dockerfile already wins |
DATABASE_DSN |
already stripped; start.sh publishes the embedded one |
LOG_LEVEL, LOG_FILE_IS_ENABLED |
the code defaults (info, enabled) equal the baked values |
SHOW_DB_INSTALLATION_VERIFICATION_LOGS |
config.go sets true when empty, equal to the baked value |
SMTP_* |
unset; this is the fix |
TEST_*, GOOSE_*, DEV_DB_*, WAL_BACKUP_*, DATABASE_URL, VITE_* |
not read by the production binary; migrations take their DSN from the config (backend/cmd/main.go:502-503) |
OAuth, Turnstile, DATABASUS_URL, OPEN_TELEMETRY_* |
empty in the file, so nothing changes |
Goals / Non-Goals
Goals:
- The image contains no environment file at all, so no future addition to
.env.examplecan reach production. - A developer's local
.envfiles never enter a Docker build context. - Startup without an environment file succeeds and says so in the log.
Non-Goals:
- Changing the precedence between the process environment, the published embedded DSN and the file.
- Making
logger/settings.goandconfig.goshare one loader. They load the same file for different reasons at different times, and merging them is a separate refactor.
Decisions
Remove the file from the image instead of shipping an empty or production-only one
The Dockerfile drops the COPY and the sed line, and the backend stops requiring the file.
Alternatives rejected:
- An empty
/.env(RUN touch /.env). This is a one-line fix, but it keeps the slot open. The next person who needs a default would put it there, and we would be back to values that bypass the code defaults. - A separate
docker/.env.productionwith production values. Every value it could hold already exists as a code default or a DockerfileENV. A second source of defaults would drift from the first. The previousbackend/.env.production.exampledid exactly that and carried a development database password. - Stripping
SMTP_*withsed. This fixes the symptom for one prefix and leaves every other development value in the image.
Make the file optional in config.go; a missing required variable stays fatal
Before calling godotenv.Load, config.go checks whether the file exists. A missing file logs at info level that no environment file was loaded, and startup continues. A file that exists but cannot be read or parsed stays fatal, because silently ignoring a broken file would hide a misconfiguration. The existing required-field checks keep catching a development checkout that has no .env.
The existence check and the load go into a small helper that returns whether the file was loaded and any error. That makes it testable without running loadEnvVariables, which exits the process on failure.
Alternatives rejected:
- Fatal in development, optional in production. The mode comes from
ENV_MODE, which the file itself may set, so the decision would depend on the thing being loaded. The missing-variable checks already give a developer a precise message. - Ignoring every load error, the way
logger/settings.godoes. A malformed file would then disappear silently from the configuration.
Exclude every .env file from the build context and delete the dead frontend block
.dockerignore gets **/.env and **/.env.*, which replace the root-only .env.local and .env.development entries. The root .env.example no longer needs to be in the context once the copy is gone, so no exception is needed for it. Dockerfile:14-18 is deleted. The frontend build reads VITE_APP_VERSION from the ENV at Dockerfile:8, and runtime flags come from runtime-config.js, which start.sh generates. The frontend build needs no file.
Alternatives rejected:
- Keep the block and only add the ignore rule. The block would still refer to a file that does not exist.
- Exclude only
**/.env. Vite also reads.env.local,.env.productionand.env.production.local, so local values would still reach the bundle.
Pin the behavior with Go tests, not an image test
Tests in config_test.go cover the helper: a missing file, a file that loads, a file that does not override a variable already set, even to an empty value, and a malformed file. A test in features/email covers a host and port with no credentials and no security mode, which must give starttls. A transport test against the existing fake SMTP server sends with empty credentials over STARTTLS and asserts that the delivery succeeds and no AUTH command is issued. The tests run the binary's real loading path, so they would catch a code-level regression.
Alternative rejected: a CI step that runs the built image and asserts that /.env does not exist. It would catch a re-added COPY, but it costs an image build per run, and the proposal scopes it out. A Dockerfile comment at the former copy site records why there is no environment file, which is the cheaper guard.
Constraints from module rules
- Root
AGENTS.md: keep Dockerfiles free of secrets. The baked file carried development passwords, so removing it also satisfies this rule. - Root
AGENTS.md: no unrequested backward compatibility. Nothing replaces the baked file, and the BREAKING note in the proposal states what operators lose. backend/AGENTS.md: never log secrets. The new log line names only the file path and whether it was loaded.- No ADR in
adr/covers configuration loading, so this change does not conflict with an accepted decision.
Risks / Trade-offs
- [An operator unknowingly relied on a baked SMTP value, for example a working relay that accepted the test login] → The relay would have needed to accept
[email protected]/password, which is implausible. The release notes name the change, and the logged SMTP failure points at the missing variable. - [Someone re-adds a
COPYof an env file to the Dockerfile] → The Dockerfile comment explains why there is none, and the review hooks see the diff. A CI image check stays out of scope by decision. - [A developer runs the backend without
.envand sees an unfamiliar error] → The info line saying no environment file was loaded comes right before the configuration error. A manual run from a directory without.envand with an empty environment loggedDATABASE_DSN is emptyand exited with status 1. - [An operator mounts their own file at
/.env] → It keeps working, because the backend still loads the file when it exists.
Migration Plan
Nothing to migrate in data. Operators upgrading an image that relied on a baked value set that variable explicitly. Rolling back means reverting the commit; no state depends on it.