Skip to content

Commit

Permalink
Allow Args to be used in Variable Evaluation
Browse files Browse the repository at this point in the history
If the Dockerfile has a `ARG CHOWN_VAL=6173:6173`, then
a `COPY --chown=${CHOWN_VAL} srcFile destFile` will fail.
However if the Dockerfile has a `ENV CHOWN_VAL=6173:6173`
then it succeeds.

The dispatchCopy() function was only going through the
list of Environment variables to resolve a Variable instead
of the list of Args and Environment variables.  If there's
a trailing equal `=` sign in the arg, assume that we'd a
variable that did not resolve and try to resolve from the
list of args.

At some point I'd like to look into converting the b.Env to
a Map from a slice like b.Args, but didn't want to run this
down now.

Fixes: containers/buildah#2192
       and probably containers/buildah#2345

Signed-off-by: TomSweeneyRedHat <[email protected]>
  • Loading branch information
TomSweeneyRedHat committed May 14, 2020
1 parent e388800 commit f172ce4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions dispatchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ func dispatchCopy(b *Builder, args []string, attributes map[string]bool, flagArg
if err != nil {
return err
}
// If there's an arg ending with an '=', it's likely we did
// not resolve a variable value from the Environment Variables.
// Let's see if the variable was defined in an 'ARG' statement
// in the Dockerfile.
if strings.HasSuffix(arg, "=") {
var userArg []string
for key, value := range b.Args {
userArg = append(userArg, key+"="+value)
}
arg, err = ProcessWord(a, userArg)
if err != nil {
return err
}
}
switch {
case strings.HasPrefix(arg, "--chown="):
chown = strings.TrimPrefix(arg, "--chown=")
Expand Down

0 comments on commit f172ce4

Please sign in to comment.