Преглед на файлове

Merge pull request #11405 from ndeloof/issue_11392

Fix load .env from project directory when project file is set by COMPOSE_FILE
Guillaume Lours преди 1 година
родител
ревизия
3c25af4fe9

+ 2 - 2
cmd/compose/compose.go

@@ -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))...)
 }

+ 12 - 0
pkg/e2e/compose_test.go

@@ -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 - 0
pkg/e2e/fixtures/dotenv/.env

@@ -0,0 +1 @@
+COMPOSE_FILE="${COMPOSE_FILE:-development/compose.yaml}"

+ 2 - 0
pkg/e2e/fixtures/dotenv/development/.env

@@ -0,0 +1,2 @@
+IMAGE_NAME="${IMAGE_NAME:-backend}"
+IMAGE_TAG="${IMAGE_TAG:-latest}"

+ 3 - 0
pkg/e2e/fixtures/dotenv/development/compose.yaml

@@ -0,0 +1,3 @@
+services:
+  backend:
+    image: $IMAGE_NAME:$IMAGE_TAG