Skip to content

Conversation

@MaheshThakur9152
Copy link
Contributor

@MaheshThakur9152 MaheshThakur9152 commented Jan 22, 2026

Summary
Fixes #13540
Fixes an issue where environment variables defined in a top-level include.env_file were not available for interpolation within the env_file of included services.

The Issue
When a top-level compose.yaml includes another file and provides an env_file for that include, those variables should be available for interpolation in the included services.

  • Example: Top-level includes subproj with env_file: values.env (VAR=1). Sub-project service uses env_file with ${VAR?}.
  • Before: Fails with required variable VAR is missing a value.
  • After: Resolves correctly.

The Fix
I updated the CLI loader.go to explicitly pre-process top-level include directives:

  1. Added collectIncludeEnvFiles to parse and resolve local env_file paths from includes.
  2. Injected these files into the project load options via 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

  • Unit Test: Added TestLoadProject_IncludeEnvFileInterpolation in loader_test.go to verify the fix deterministically.
  • E2E: Added a regression fixture in pkg/e2e/fixtures/include-envfile-interpolation/ and verified with TestIncludeEnvFileInterpolation.

Verification
Validated locally with go test ./pkg/compose -run TestLoadProject_IncludeEnvFileInterpolation.

@MaheshThakur9152 MaheshThakur9152 requested a review from a team as a code owner January 22, 2026 12:19
Signed-off-by: Mahesh Thakur <maheshthakur9152@gmail.com>
@MaheshThakur9152 MaheshThakur9152 force-pushed the fix/include-env-interpolation branch from f5294de to 8329151 Compare January 22, 2026 12:21
Copy link
Contributor

@ndeloof ndeloof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix is wrong.
env file resolution for a sub-project used as include should take place in compose-go

@MaheshThakur9152
Copy link
Contributor Author

fix is wrong. env file resolution for a sub-project used as include should take place in compose-go

Thanks for the review @ndeloof.
I suspected this might be the case. I implemented it in the CLI loader as a 'shim' to avoid modifying the recursive loading logic in compose-go initially.
I am happy to move this fix upstream. I will take a look at compose-spec/compose-go to implement the env file resolution within the include loader there. I'll close this once I have that PR ready.

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.

[BUG] Variables not interpolated in env_file in included subproject

2 participants