Skip to content

Commit ce3443b

Browse files
committed
executor: resolve BultInArgs while expanding baseImage
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: #4820 Signed-off-by: Aditya R <[email protected]>
1 parent 6ec93ce commit ce3443b

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

imagebuildah/build.go

+2
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,8 @@ func baseImages(dockerfilenames []string, dockerfilecontents [][]byte, from stri
672672
if base != "scratch" && !nicknames[base] {
673673
headingArgs := argsMapToSlice(stage.Builder.HeadingArgs)
674674
userArgs := argsMapToSlice(stage.Builder.Args)
675+
populatedBuiltInBuildArgs := argsMapToSlice(imagebuilder.GetBuiltinBuildArgs())
676+
userArgs = append(userArgs, populatedBuiltInBuildArgs...)
675677
// append heading args so if --build-arg key=value is not
676678
// specified but default value is set in Containerfile
677679
// via `ARG key=value` so default value can be used.

imagebuildah/executor.go

+2
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,11 @@ func (b *Executor) Build(ctx context.Context, stages imagebuilder.Stages) (image
751751
}
752752
headingArgs := argsMapToSlice(stage.Builder.HeadingArgs)
753753
userArgs := argsMapToSlice(stage.Builder.Args)
754+
populatedBuiltInBuildArgs := argsMapToSlice(imagebuilder.GetBuiltinBuildArgs())
754755
// append heading args so if --build-arg key=value is not
755756
// specified but default value is set in Containerfile
756757
// via `ARG key=value` so default value can be used.
758+
userArgs = append(userArgs, populatedBuiltInBuildArgs...)
757759
userArgs = append(headingArgs, userArgs...)
758760
baseWithArg, err := imagebuilder.ProcessWord(base, userArgs)
759761
if err != nil {

tests/bud.bats

+4
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ symlink(subdir)"
266266

267267
run_buildah build --platform linux/$myarch/$myvariant $WITH_POLICY_JSON -t test -f $BUDFILES/base-with-arg/Containerfile
268268
expect_output --substring "This is built for $myarch"
269+
270+
# Should work without platform string as well
271+
run_buildah build $WITH_POLICY_JSON -t test -f $BUDFILES/base-with-arg/Containerfile
272+
expect_output --substring "This is built for $myarch"
269273
}
270274

271275
@test "build with basename resolving user arg" {

0 commit comments

Comments
 (0)