Skip to content

Commit

Permalink
executor: resolve BultInArgs while expanding baseImage
Browse files Browse the repository at this point in the history
While creating a dependency map, executor must consider expanding base
images with `builtInArgs` like `TARGETARCH, TARGETOS` etc so buildah can
still keep and use the stages as dependency later on.

Closes: containers#4820

Signed-off-by: Aditya R <[email protected]>
  • Loading branch information
flouthoc committed Jun 21, 2023
1 parent 6ec93ce commit ce3443b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions imagebuildah/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,8 @@ func baseImages(dockerfilenames []string, dockerfilecontents [][]byte, from stri
if base != "scratch" && !nicknames[base] {
headingArgs := argsMapToSlice(stage.Builder.HeadingArgs)
userArgs := argsMapToSlice(stage.Builder.Args)
populatedBuiltInBuildArgs := argsMapToSlice(imagebuilder.GetBuiltinBuildArgs())
userArgs = append(userArgs, populatedBuiltInBuildArgs...)
// append heading args so if --build-arg key=value is not
// specified but default value is set in Containerfile
// via `ARG key=value` so default value can be used.
Expand Down
2 changes: 2 additions & 0 deletions imagebuildah/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,11 @@ func (b *Executor) Build(ctx context.Context, stages imagebuilder.Stages) (image
}
headingArgs := argsMapToSlice(stage.Builder.HeadingArgs)
userArgs := argsMapToSlice(stage.Builder.Args)
populatedBuiltInBuildArgs := argsMapToSlice(imagebuilder.GetBuiltinBuildArgs())
// append heading args so if --build-arg key=value is not
// specified but default value is set in Containerfile
// via `ARG key=value` so default value can be used.
userArgs = append(userArgs, populatedBuiltInBuildArgs...)
userArgs = append(headingArgs, userArgs...)
baseWithArg, err := imagebuilder.ProcessWord(base, userArgs)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ symlink(subdir)"

run_buildah build --platform linux/$myarch/$myvariant $WITH_POLICY_JSON -t test -f $BUDFILES/base-with-arg/Containerfile
expect_output --substring "This is built for $myarch"

# Should work without platform string as well
run_buildah build $WITH_POLICY_JSON -t test -f $BUDFILES/base-with-arg/Containerfile
expect_output --substring "This is built for $myarch"
}

@test "build with basename resolving user arg" {
Expand Down

0 comments on commit ce3443b

Please sign in to comment.