Merge pull request #11405 from ndeloof/issue_11392

Fix load .env from project directory when project file is set by COMPOSE_FILE
This commit is contained in:
Guillaume Lours 2024-01-31 10:52:28 +01:00 committed by GitHub
commit 3c25af4fe9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 20 additions and 2 deletions

View File

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

View File

@ -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",
})
}

View File

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

View File

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

View File

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