Skip to content

Commit

Permalink
Merge pull request #25 from silphid/resolve-env-variables
Browse files Browse the repository at this point in the history
resolve env variables
  • Loading branch information
silphid authored Jun 24, 2021
2 parents 0d0e56b + 12a6c72 commit 7d68948
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
22 changes: 22 additions & 0 deletions src/internal/contextFile.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func parseContextFile(dir string, data []byte) (Contexts, error) {
contexts = parent.Merge(contexts)
}

contexts = resolveEnvironmentVariables(contexts)

return contexts, nil
}

Expand Down Expand Up @@ -216,3 +218,23 @@ func resolvePath(dir, path string) (string, error) {

return filepath.Join(dir, path), nil
}

func resolveEnvironmentVariables(contexts Contexts) Contexts {
clone := contexts
clone.Context = clone.Context.Clone()
clone.Layers = clone.Layers.Clone()

for key, value := range clone.Env {
clone.Context.Env[key] = os.ExpandEnv(value)
}

for _, layer := range clone.Layers {
for _, ctx := range layer.Contexts {
for key, value := range ctx.Env {
ctx.Env[key] = os.ExpandEnv(value)
}
}
}

return clone
}
6 changes: 1 addition & 5 deletions src/internal/docker/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,7 @@ func runContainer(ctx context.Context, yeyCtx yey.Context, containerName string,

// Context env vars
for name, value := range yeyCtx.Env {
arg := name
if value != "" {
arg = fmt.Sprintf("%s=%s", name, value)
}
args = append(args, "--env", arg)
args = append(args, "--env", fmt.Sprintf("%s=%s", name, value))
}

// Mount binds
Expand Down

0 comments on commit 7d68948

Please sign in to comment.