Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ $ dockerfile-json --jsonpath=..As Dockerfile

`Dockerfile`
```Dockerfile
ARG ALPINE_TAG=3.10
ARG ALPINE_MINOR=10
ARG ALPINE_TAG=3.${ALPINE_MINOR}
ARG APP_BASE=scratch

FROM alpine:$ALPINE_TAG AS build
Expand Down
3 changes: 2 additions & 1 deletion examples/Dockerfile.3
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ARG ALPINE_TAG=3.10
ARG ALPINE_MINOR=10
ARG ALPINE_TAG=3.${ALPINE_MINOR}
ARG APP_BASE=scratch

FROM alpine:${ALPINE_TAG} AS build
Expand Down
19 changes: 11 additions & 8 deletions pkg/dockerfile/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,24 @@ func (d *Dockerfile) metaArgsEnvExpander(env instructions.SingleWordExpander) in
if defaultValue := arg.DefaultValue; defaultValue != nil {
metaArgsEnv[arg.Key] = *defaultValue
}

if value, err := env(arg.Key); err == nil {
arg.ProvidedValue = &value
metaArgsEnv[arg.Key] = value
arg.Value = &value
}
err := arg.Expand(env)
if err != nil {
continue
}
for _, kv := range arg.ArgCommand.Args {
if kv.Value != nil {
metaArgsEnv[arg.Key] = *kv.Value

exp := os.Expand(*arg.Value, func(argval string) string {
if val, ok := metaArgsEnv[argval]; ok {
return val;
}
}

return argval;
})
arg.Value = &exp;
metaArgsEnv[arg.Key] = exp;
}

return func(key string) (string, error) {
if value, ok := metaArgsEnv[key]; ok {
return value, nil
Expand Down