@@ -231,6 +231,48 @@ services:
231231 assert .Equal (t , p .Services ["included" ].Image , "alpine" )
232232}
233233
234+ func TestIncludeEnvFileInterpolation (t * testing.T ) {
235+ fileName := "compose.yml"
236+ tmpdir := t .TempDir ()
237+ // top-level include with env_file
238+ yaml := `
239+ include:
240+ - path: ./subproj/subcompose.yml
241+ env_file:
242+ - ./values.env
243+ `
244+ createFile (t , tmpdir , yaml , fileName )
245+
246+ yaml = `
247+ services:
248+ app:
249+ env_file: subvalues.env
250+ image: helloworld
251+ `
252+ createFileSubDir (t , tmpdir , "subproj" , yaml , "subcompose.yml" )
253+
254+ // env file inside included project references VAR from top-level include env_file
255+ createFileSubDir (t , tmpdir , "subproj" , "MYVAR=${VAR?}" , "subvalues.env" )
256+ createFile (t , tmpdir , "VAR=1" , "values.env" )
257+
258+ p , err := LoadWithContext (context .TODO (), types.ConfigDetails {
259+ WorkingDir : tmpdir ,
260+ ConfigFiles : []types.ConfigFile {{
261+ Filename : filepath .Join (tmpdir , fileName ),
262+ }},
263+ Environment : nil ,
264+ }, func (options * Options ) {
265+ options .SkipNormalization = true
266+ options .ResolvePaths = true
267+ options .SetProjectName ("project" , true )
268+ })
269+ assert .NilError (t , err )
270+ app := p .Services ["app" ]
271+ // After resolution, MYVAR should be present and equal to 1
272+ assert .Check (t , app .Environment ["MYVAR" ] != nil )
273+ assert .Equal (t , * app .Environment ["MYVAR" ], "1" )
274+ }
275+
234276func createFile (t * testing.T , rootDir , content , fileName string ) string {
235277 path := filepath .Join (rootDir , fileName )
236278 assert .NilError (t , os .WriteFile (path , []byte (content ), 0o600 ))
0 commit comments