Skip to content

Commit

Permalink
Merge pull request #11405 from ndeloof/issue_11392
Browse files Browse the repository at this point in the history
Fix load .env from project directory when project file is set by COMPOSE_FILE
  • Loading branch information
glours committed Jan 31, 2024
2 parents 8fdd45c + a8bd3b7 commit 3c25af4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ func (o *ProjectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.Proj
append(po,
cli.WithWorkingDirectory(o.ProjectDir),
cli.WithOsEnv,
cli.WithEnvFiles(o.EnvFiles...),
cli.WithDotEnv,
cli.WithConfigFileEnv,
cli.WithDefaultConfigPath,
cli.WithEnvFiles(o.EnvFiles...),
cli.WithDotEnv,
cli.WithDefaultProfiles(o.Profiles...),
cli.WithName(o.ProjectName))...)
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/e2e/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,15 @@ func TestRemoveOrphaned(t *testing.T) {
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/sentences/compose.yaml", "-p", projectName, "ps", "--format", "{{.Name}}")
res.Assert(t, icmd.Expected{Out: fmt.Sprintf("%s-words-1", projectName)})
}

func TestResolveDotEnv(t *testing.T) {
c := NewCLI(t)

cmd := c.NewDockerComposeCmd(t, "config")
cmd.Dir = filepath.Join(".", "fixtures", "dotenv")
res := icmd.RunCmd(cmd)
res.Assert(t, icmd.Expected{
ExitCode: 0,
Out: "image: backend:latest",
})
}
1 change: 1 addition & 0 deletions pkg/e2e/fixtures/dotenv/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMPOSE_FILE="${COMPOSE_FILE:-development/compose.yaml}"
2 changes: 2 additions & 0 deletions pkg/e2e/fixtures/dotenv/development/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IMAGE_NAME="${IMAGE_NAME:-backend}"
IMAGE_TAG="${IMAGE_TAG:-latest}"
3 changes: 3 additions & 0 deletions pkg/e2e/fixtures/dotenv/development/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
backend:
image: $IMAGE_NAME:$IMAGE_TAG

0 comments on commit 3c25af4

Please sign in to comment.