Skip to content

Commit

Permalink
Merge pull request #2567 from AkihiroSuda/fix-env-file
Browse files Browse the repository at this point in the history
nerdctl compose: fix `--env-file` (broken since v1.6.0)
  • Loading branch information
AkihiroSuda authored Oct 13, 2023
2 parents 2752149 + 5d4f032 commit e3dc23b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
21 changes: 21 additions & 0 deletions cmd/nerdctl/compose_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,24 @@ services:
base.ComposeCmd("--project-directory", comp.Dir(), "config", "--services").AssertOutContainsAll("hello1\n", "hello2\n")
base.ComposeCmd("--project-directory", comp.Dir(), "config").AssertOutContains("alpine:3.14")
}

func TestComposeConfigWithEnvFile(t *testing.T) {
base := testutil.NewBase(t)

const dockerComposeYAML = `
services:
hello:
image: ${image}
`

comp := testutil.NewComposeDir(t, dockerComposeYAML)
defer comp.CleanUp()

envFile := filepath.Join(comp.Dir(), "env")
const envFileContent = `
image: hello-world
`
assert.NilError(t, os.WriteFile(envFile, []byte(envFileContent), 0644))

base.ComposeCmd("-f", comp.YAMLFullPath(), "--env-file", envFile, "config").AssertOutContains("image: hello-world")
}
10 changes: 6 additions & 4 deletions pkg/composer/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ func New(o Options, client *containerd.Client) (*Composer, error) {
optionsFn = append(optionsFn,
composecli.WithOsEnv,
composecli.WithWorkingDirectory(o.ProjectDirectory),
composecli.WithConfigFileEnv,
composecli.WithDefaultConfigPath,
composecli.WithDotEnv,
composecli.WithName(o.Project),
)
if o.EnvFile != "" {
optionsFn = append(optionsFn,
composecli.WithEnvFiles(o.EnvFile),
)
}
optionsFn = append(optionsFn,
composecli.WithConfigFileEnv,
composecli.WithDefaultConfigPath,
composecli.WithDotEnv,
composecli.WithName(o.Project),
)

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

0 comments on commit e3dc23b

Please sign in to comment.