fix: Load env_files from top-level include during project interpolation #13543
+154
−3
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
Fixes #13540
Fixes an issue where environment variables defined in a top-level
include.env_filewere not available for interpolation within theenv_fileof included services.The Issue
When a top-level
compose.yamlincludes another file and provides anenv_filefor that include, those variables should be available for interpolation in the included services.subprojwithenv_file: values.env(VAR=1). Sub-project service usesenv_filewith${VAR?}.required variable VAR is missing a value.The Fix
I updated the CLI
loader.goto explicitly pre-process top-levelincludedirectives:collectIncludeEnvFilesto parse and resolve localenv_filepaths from includes.cli.WithEnvFiles.Implementation Note
I implemented this as a pre-load step in the CLI rather than modifying the recursive loading logic in
compose-go. This ensures the environment is correctly "primed" for interpolation with minimal risk of regression to the core engine.Testing
TestLoadProject_IncludeEnvFileInterpolationinloader_test.goto verify the fix deterministically.pkg/e2e/fixtures/include-envfile-interpolation/and verified withTestIncludeEnvFileInterpolation.Verification
Validated locally with
go test ./pkg/compose -run TestLoadProject_IncludeEnvFileInterpolation.