Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 8e4221d

Browse files
authored
Merge pull request #448 from surajnarwade/fix_env_issue
Fixes .env file lookup
2 parents 9aa966c + d1fec56 commit 8e4221d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

project/project.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"os"
7+
"path"
78
"path/filepath"
89
"strings"
910

@@ -65,15 +66,25 @@ func NewProject(context *Context, runtime RuntimeProject, parseOptions *config.P
6566
}
6667

6768
if context.EnvironmentLookup == nil {
68-
cwd, err := os.Getwd()
69+
var envPath, absPath, cwd string
70+
var err error
71+
if len(context.ComposeFiles) > 0 {
72+
absPath, err = filepath.Abs(context.ComposeFiles[0])
73+
dir, _ := path.Split(absPath)
74+
envPath = filepath.Join(dir, ".env")
75+
} else {
76+
cwd, err = os.Getwd()
77+
envPath = filepath.Join(cwd, ".env")
78+
}
79+
6980
if err != nil {
7081
log.Errorf("Could not get the rooted path name to the current directory: %v", err)
7182
return nil
7283
}
7384
context.EnvironmentLookup = &lookup.ComposableEnvLookup{
7485
Lookups: []config.EnvironmentLookup{
7586
&lookup.EnvfileLookup{
76-
Path: filepath.Join(cwd, ".env"),
87+
Path: envPath,
7788
},
7889
&lookup.OsEnvLookup{},
7990
},

0 commit comments

Comments
 (0)