Skip to content

Commit

Permalink
resolve environment incrementaly, including values loaded from previo…
Browse files Browse the repository at this point in the history
…us files in the list

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Dec 21, 2022
1 parent b764b46 commit 2cb1a7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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
4 changes: 2 additions & 2 deletions types/types.go
Expand Up @@ -356,12 +356,12 @@ type ThrottleDevice struct {
// ShellCommand is a string or list of string args.
//
// When marshaled to YAML, nil command fields will be omitted if `omitempty`
// is specified as a struct tag. Explicitly empty commands (i.e. `[]` or `''`)
// is specified as a struct tag. Explicitly empty commands (i.e. `[]` or ``)
// will serialize to an empty array (`[]`).
//
// When marshaled to JSON, the `omitempty` struct must NOT be specified.
// If the command field is nil, it will be serialized as `null`.
// Explicitly empty commands (i.e. `[]` or `''`) will serialize to an empty
// Explicitly empty commands (i.e. `[]` or ``) will serialize to an empty
// array (`[]`).
//
// The distinction between nil and explicitly empty is important to distinguish
Expand Down

0 comments on commit 2cb1a7c

Please sign in to comment.