Skip to content

fix(compose): import service env_file variables instead of dropping them - #1878

Open
santhiprakash wants to merge 2 commits into
oblien:mainfrom
santhiprakash:fix/1854-compose-env-file-import
Open

santhiprakash wants to merge 2 commits into
oblien:mainfrom
santhiprakash:fix/1854-compose-env-file-import

Conversation

@santhiprakash

Copy link
Copy Markdown
Contributor

Summary

Compose import now reads each service's env_file: — string, list, and long-form {path, required, format} entries — resolves the paths against the compose file's directory, and merges the referenced dotenv/raw contents into the service environment below environment:, matching Compose's own precedence. Files that cannot be read surface as a non-blocking unsupported warning instead of vanishing silently.

Motivation

#1854: a service's env_file: was dropped in silence. parseComposeFile never read svc.env_file, and UNSUPPORTED_SERVICE_KEYS had no entry for it, so collectUnsupported stayed quiet — the exact failure mode #533 set out to prevent. The app then starts without DATABASE_URL, SECRET_KEY_BASE, etc., and nothing points at env_file as the reason. The issue sketches two directions (a minimal UNSUPPORTED_SERVICE_KEYS warning vs. actually reading the files); this implements the fuller one — the values arrive, and unreadable files still get the honest warning, so both failure modes are covered.

Verified still present on current main (e94cbb99b): env_file is absent from the parser and from UNSUPPORTED_SERVICE_KEYS (only envFileContent interpolation of the compose-adjacent .env exists).

Related issue

Fixes #1854.

Changes

  • packages/platform compose-parser.ts:
    • parseServiceEnvFiles + resolveServiceEnvFiles — normalize env_file declarations, interpolate the path, resolve it against composeDirectory (the compose file's directory, like Compose itself), and parse contents as dotenv (default) or literal KEY=VALUE lines (format: raw).
    • Values merge below environment: — later files override earlier ones, explicit environment: values win.
    • A file that cannot be read lands on unsupported as a non-blocking warning naming the service and path; required: false entries stay silent, matching Compose. Absolute/~/..-above-root paths and malformed entries are reported rather than dropped.
    • composeEnvFilePaths — exported helper returning the resolved repo-relative paths a compose file names, so callers know exactly what to fetch.
    • ComposeParseOptions gains composeDirectory and envFileContents; hasEnvironmentDeclaration now also counts env_file so snapshot-safe sync paths treat the merged env correctly.
  • packages/platform prepare.service.ts:
    • readComposeEnvFileContents fetches each declared path through the same ProjectReader used for the compose file (local and Git-backed sources behave identically); resolveFromReader passes the map into toProjectInfo → parseComposeFile.
    • Callers that parse without a reader (migration, docker-inspect) still get the unsupported warning rather than silence.
  • Tests:
    • apps/api/test/lib/compose-parser.test.ts — 10 cases: merge order and environment: precedence, composeDirectory resolution, later-file override, required: false opt-out, unreadable-file warning (non-blocking), no-reader warning, out-of-repo paths, path interpolation, dotenv-vs-raw format, and literal-value handling.
    • apps/api/test/modules/deployments/prepare.service.test.ts — end-to-end through resolveProjectInfo on a real temp tree: deploy/api.env is read relative to deploy/docker-compose.yaml, environment: still wins, and the missing ./missing.env is reported.

Verification

$ cd apps/api && bunx vitest run test/lib/compose-parser.test.ts test/modules/deployments/prepare.service.test.ts
      Test Files  2 passed (2)
      Tests  236 passed (236)

$ cd packages/platform && bunx tsc --noEmit   # clean
$ cd apps/api && bunx tsc --noEmit            # clean (lint script)

$ cd packages/platform && bunx vitest run src/engine/modules/deployments/compose-review.test.ts src/engine/modules/deployments/compose/build-service-dns.test.ts
      Tests  22 passed (22)

Sabotage check (RED): with compose-parser.ts + prepare.service.ts reverted to upstream/main, all 10 new env_file parser tests fail (e.g. environment stays {}, no env_file warning); restoring the fix turns them green.

bunx prettier agrees with every line this PR adds. Several touched files already fail prettier --check on upstream main (pre-existing drift), so bun format was not run over them — the diff is kept byte-scoped with no unrelated reformatting.

Screenshots

N/A — parser/import-path change, no UI surface.

Checklist

  • One change per PR — one bug, or one agreed feature, with nothing unrelated bundled in
  • The diff is scoped — no reformatting or lint fixes on lines I wasn't otherwise changing
  • A test fails without this change and passes with it (or I explained above why there isn't one)
  • Relevant test suites, typechecks, and changed-line formatting pass locally
  • I understand every line of this diff and can explain it in review

A service's `env_file:` was silently ignored on import: the parser never
read `svc.env_file` and `UNSUPPORTED_SERVICE_KEYS` had no entry for it,
so the declared variables never reached the service and nothing was
reported — the exact silent-drop failure mode oblien#533 set out to prevent.

Parse `env_file` in string and list form (including long-form
`{path, required, format}` entries), resolve each path against the
compose file's directory like Compose itself, and merge the referenced
dotenv/raw contents into the service environment BELOW `environment:` —
later files override earlier ones, explicit `environment:` values win.
The import reader now fetches each declared file through the same
ProjectReader used for the compose file, so local and Git-backed
sources behave identically.

A file that cannot be read surfaces as a non-blocking `unsupported`
warning naming the service and path; `required: false` entries stay
silent, matching Compose. Callers that parse without a reader (the
migration and docker-inspect paths) still get the warning rather than
silence.

Closes oblien#1854
@santhiprakash
santhiprakash force-pushed the fix/1854-compose-env-file-import branch from 9fcf5df to 595cad4 Compare November 23, 2026 20:12
@santhiprakash
santhiprakash force-pushed the fix/1854-compose-env-file-import branch from 27a304b to 168e8d4 Compare November 30, 2026 04:22
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.

Compose import silently ignores a service's env_file

2 participants