-
Notifications
You must be signed in to change notification settings - Fork 269
[env] Fixed env_from bug when it is called from a subdirectory #2355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
9336afa
b4045af
6dbef33
24caaf8
cbf49a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package configfile | |
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
|
||
"github.com/hashicorp/go-envparse" | ||
|
@@ -25,10 +26,15 @@ func (c *ConfigFile) ParseEnvsFromDotEnv() (map[string]string, error) { | |
if !c.IsdotEnvEnabled() { | ||
return nil, fmt.Errorf("env file does not have a .env extension") | ||
} | ||
|
||
file, err := os.Open(c.EnvFrom) | ||
envFileAbsPath := filepath.Dir(c.AbsRootPath) | ||
if filepath.IsAbs(c.EnvFrom) { | ||
envFileAbsPath = path.Join(envFileAbsPath, path.Base(c.EnvFrom)) | ||
|
||
} else { | ||
envFileAbsPath = path.Join(envFileAbsPath, c.EnvFrom) | ||
} | ||
file, err := os.Open(envFileAbsPath) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to open file: %s", c.EnvFrom) | ||
return nil, fmt.Errorf("failed to open file: %s", envFileAbsPath) | ||
} | ||
defer file.Close() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this scenario be
envFileAbsPath = c.EnvFrom
?if the user has set
Then, I'd think we want to just obey the absolute path directive.
Perhaps we should error if the env_from path is absolute, because that would mess up any reproducibility of the devbox.json config. But I'll be open to just letting it fly. We can expect our users to use their judgement for when they want to make their config a bit less reproducible. For example, for the sake of some quick changes they may want to experiment with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the absolute path erroring out case. Reproducibility should be considered here. I'll push a commit to change this case to an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We allow absolute paths for flakes and plugins. I don't think env should be different. Absolute paths can be important for reproducibility as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about it even more, I don't think relative paths are any more reproducible than absolute paths! relative paths are more reproducible only if
.env
file is in the repo, but in that case you are better off just adding to theenv
field in devbox.jsonThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikeland73 the idea is to prevent unintended mistakes that comes with putting absolute paths. For example, if user A puts
/Users/A/projects/Aproject/.env
and user B has the repo clone in/Users/B/...
it will break the reproducibility.Do you think this is an acceptable risk and we should allow absolute path here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 reasons:
../path/to/my/.env
would also live outside the repo. Or just.env
when.env
is in gititnore.Why would folks use this feature with
.env
file that is checked in to their repo? (I guess some convenience maybe, but seems low value). The use case for this feature is for people to have different .env files, so by definition reproducibility is not as important.