Skip to content

Commit e3dc23b

Browse files
authored
Merge pull request #2567 from AkihiroSuda/fix-env-file
nerdctl compose: fix `--env-file` (broken since v1.6.0)
2 parents 2752149 + 5d4f032 commit e3dc23b

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

cmd/nerdctl/compose_config_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,24 @@ services:
130130
base.ComposeCmd("--project-directory", comp.Dir(), "config", "--services").AssertOutContainsAll("hello1\n", "hello2\n")
131131
base.ComposeCmd("--project-directory", comp.Dir(), "config").AssertOutContains("alpine:3.14")
132132
}
133+
134+
func TestComposeConfigWithEnvFile(t *testing.T) {
135+
base := testutil.NewBase(t)
136+
137+
const dockerComposeYAML = `
138+
services:
139+
hello:
140+
image: ${image}
141+
`
142+
143+
comp := testutil.NewComposeDir(t, dockerComposeYAML)
144+
defer comp.CleanUp()
145+
146+
envFile := filepath.Join(comp.Dir(), "env")
147+
const envFileContent = `
148+
image: hello-world
149+
`
150+
assert.NilError(t, os.WriteFile(envFile, []byte(envFileContent), 0644))
151+
152+
base.ComposeCmd("-f", comp.YAMLFullPath(), "--env-file", envFile, "config").AssertOutContains("image: hello-world")
153+
}

pkg/composer/composer.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,18 @@ func New(o Options, client *containerd.Client) (*Composer, error) {
7070
optionsFn = append(optionsFn,
7171
composecli.WithOsEnv,
7272
composecli.WithWorkingDirectory(o.ProjectDirectory),
73-
composecli.WithConfigFileEnv,
74-
composecli.WithDefaultConfigPath,
75-
composecli.WithDotEnv,
76-
composecli.WithName(o.Project),
7773
)
7874
if o.EnvFile != "" {
7975
optionsFn = append(optionsFn,
8076
composecli.WithEnvFiles(o.EnvFile),
8177
)
8278
}
79+
optionsFn = append(optionsFn,
80+
composecli.WithConfigFileEnv,
81+
composecli.WithDefaultConfigPath,
82+
composecli.WithDotEnv,
83+
composecli.WithName(o.Project),
84+
)
8385

8486
projectOptions, err := composecli.NewProjectOptions(o.ConfigPaths, optionsFn...)
8587
if err != nil {

0 commit comments

Comments
 (0)