compose: ignore dotenv that is a directory

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2025-06-30 17:11:54 +02:00
parent 6deb9ff384
commit 40e3e5a27e
2 changed files with 22 additions and 3 deletions
+6 -3
View File
@@ -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)
+16
View File
@@ -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) {