Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions bake/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,13 @@ func loadDotEnv(curenv map[string]string, workingDir string) (map[string]string,
return nil, err
}

if _, err = os.Stat(ef); os.IsNotExist(err) {
return curenv, nil
} else if err != nil {
if st, err := os.Stat(ef); err != nil {
if os.IsNotExist(err) {
return curenv, nil
}
return nil, err
} else if st.IsDir() {
return curenv, nil
}

dt, err := os.ReadFile(ef)
Expand Down
16 changes: 16 additions & 0 deletions bake/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,22 @@ services:
require.Equal(t, map[string]string{"base": "target:base"}, c.Targets[1].Contexts)
}

func TestDotEnvDir(t *testing.T) {
tmpdir := t.TempDir()
require.NoError(t, os.Mkdir(filepath.Join(tmpdir, ".env"), 0755))

dt := []byte(`
services:
foo:
build:
context: .
`)

chdir(t, tmpdir)
_, err := ParseComposeFiles([]File{{Name: "compose.yml", Data: dt}})
require.NoError(t, err)
}

// chdir changes the current working directory to the named directory,
// and then restore the original working directory at the end of the test.
func chdir(t *testing.T, dir string) {
Expand Down