Skip to content

Commit a8bd3b7

Browse files
committed
Fix load .env from project directory when project file is set by COMPOSE_FILE
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent bef8785 commit a8bd3b7

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

cmd/compose/compose.go

Lines changed: 2 additions & 2 deletions
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

Lines changed: 12 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
COMPOSE_FILE="${COMPOSE_FILE:-development/compose.yaml}"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
IMAGE_NAME="${IMAGE_NAME:-backend}"
2+
IMAGE_TAG="${IMAGE_TAG:-latest}"
Lines changed: 3 additions & 0 deletions
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)