Skip to content

Commit 3c25af4

Browse files
authored
Merge pull request #11405 from ndeloof/issue_11392
Fix load .env from project directory when project file is set by COMPOSE_FILE
2 parents 8fdd45c + a8bd3b7 commit 3c25af4

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

cmd/compose/compose.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,10 @@ func (o *ProjectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.Proj
261261
append(po,
262262
cli.WithWorkingDirectory(o.ProjectDir),
263263
cli.WithOsEnv,
264-
cli.WithEnvFiles(o.EnvFiles...),
265-
cli.WithDotEnv,
266264
cli.WithConfigFileEnv,
267265
cli.WithDefaultConfigPath,
266+
cli.WithEnvFiles(o.EnvFiles...),
267+
cli.WithDotEnv,
268268
cli.WithDefaultProfiles(o.Profiles...),
269269
cli.WithName(o.ProjectName))...)
270270
}

pkg/e2e/compose_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,15 @@ func TestRemoveOrphaned(t *testing.T) {
313313
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/sentences/compose.yaml", "-p", projectName, "ps", "--format", "{{.Name}}")
314314
res.Assert(t, icmd.Expected{Out: fmt.Sprintf("%s-words-1", projectName)})
315315
}
316+
317+
func TestResolveDotEnv(t *testing.T) {
318+
c := NewCLI(t)
319+
320+
cmd := c.NewDockerComposeCmd(t, "config")
321+
cmd.Dir = filepath.Join(".", "fixtures", "dotenv")
322+
res := icmd.RunCmd(cmd)
323+
res.Assert(t, icmd.Expected{
324+
ExitCode: 0,
325+
Out: "image: backend:latest",
326+
})
327+
}

pkg/e2e/fixtures/dotenv/.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
COMPOSE_FILE="${COMPOSE_FILE:-development/compose.yaml}"
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
IMAGE_NAME="${IMAGE_NAME:-backend}"
2+
IMAGE_TAG="${IMAGE_TAG:-latest}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
backend:
3+
image: $IMAGE_NAME:$IMAGE_TAG

0 commit comments

Comments
 (0)