Skip to content
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

resolve environment incrementaly, including values loaded from previous files in the list #331

Merged
merged 1 commit into from Dec 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion loader/loader.go
Expand Up @@ -629,6 +629,12 @@ func convertVolumePath(volume types.ServiceVolumeConfig) types.ServiceVolumeConf

func resolveEnvironment(serviceConfig *types.ServiceConfig, workingDir string, lookupEnv template.Mapping) error {
environment := types.MappingWithEquals{}
var resolve dotenv.LookupFn = func(s string) (string, bool) {
if v, ok := environment[s]; ok && v != nil {
return *v, true
}
return lookupEnv(s)
}

if len(serviceConfig.EnvFile) > 0 {
if serviceConfig.Environment == nil {
Expand All @@ -649,7 +655,7 @@ func resolveEnvironment(serviceConfig *types.ServiceConfig, workingDir string, l
// Do not defer to avoid it inside a loop
file.Close() //nolint:errcheck

fileVars, err := dotenv.ParseWithLookup(bytes.NewBuffer(b), dotenv.LookupFn(lookupEnv))
fileVars, err := dotenv.ParseWithLookup(bytes.NewBuffer(b), resolve)
if err != nil {
return err
}
Expand Down