Repository navigation
fix(compose): import service env_file variables instead of dropping them - #1878
Open
santhiprakash wants to merge 2 commits into
Open
santhiprakash wants to merge 2 commits into
santhiprakash wants to merge 2 commits into
Conversation
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
force-pushed
the
fix/1854-compose-env-file-import
branch
from
November 23, 2026 20:12
9fcf5df to
595cad4
Compare
santhiprakash
force-pushed
the
fix/1854-compose-env-file-import
branch
from
November 30, 2026 04:22
27a304b to
168e8d4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 belowenvironment:, matching Compose's own precedence. Files that cannot be read surface as a non-blockingunsupportedwarning instead of vanishing silently.Motivation
#1854: a service's
env_file:was dropped in silence.parseComposeFilenever readsvc.env_file, andUNSUPPORTED_SERVICE_KEYShad no entry for it, socollectUnsupportedstayed quiet — the exact failure mode #533 set out to prevent. The app then starts withoutDATABASE_URL,SECRET_KEY_BASE, etc., and nothing points atenv_fileas the reason. The issue sketches two directions (a minimalUNSUPPORTED_SERVICE_KEYSwarning 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_fileis absent from the parser and fromUNSUPPORTED_SERVICE_KEYS(onlyenvFileContentinterpolation of the compose-adjacent.envexists).Related issue
Fixes #1854.
Changes
packages/platformcompose-parser.ts:parseServiceEnvFiles+resolveServiceEnvFiles— normalizeenv_filedeclarations, interpolate the path, resolve it againstcomposeDirectory(the compose file's directory, like Compose itself), and parse contents as dotenv (default) or literalKEY=VALUElines (format: raw).environment:— later files override earlier ones, explicitenvironment:values win.unsupportedas a non-blocking warning naming the service and path;required: falseentries 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.ComposeParseOptionsgainscomposeDirectoryandenvFileContents;hasEnvironmentDeclarationnow also countsenv_fileso snapshot-safe sync paths treat the merged env correctly.packages/platformprepare.service.ts:readComposeEnvFileContentsfetches each declared path through the sameProjectReaderused for the compose file (local and Git-backed sources behave identically);resolveFromReaderpasses the map intotoProjectInfo→parseComposeFile.unsupportedwarning rather than silence.apps/api/test/lib/compose-parser.test.ts— 10 cases: merge order andenvironment:precedence,composeDirectoryresolution, later-file override,required: falseopt-out, unreadable-file warning (non-blocking), no-reader warning, out-of-repo paths, path interpolation, dotenv-vs-rawformat, and literal-value handling.apps/api/test/modules/deployments/prepare.service.test.ts— end-to-end throughresolveProjectInfoon a real temp tree:deploy/api.envis read relative todeploy/docker-compose.yaml,environment:still wins, and the missing./missing.envis reported.Verification
Sabotage check (RED): with
compose-parser.ts+prepare.service.tsreverted toupstream/main, all 10 newenv_fileparser tests fail (e.g.environmentstays{}, noenv_filewarning); restoring the fix turns them green.bunx prettieragrees with every line this PR adds. Several touched files already failprettier --checkon upstreammain(pre-existing drift), sobun formatwas 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