From 5fa4de490df6486109278c47491f3e2b2d040e5f Mon Sep 17 00:00:00 2001 From: Aditya R Date: Fri, 2 Jun 2023 13:27:49 +0530 Subject: [PATCH] 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: https://github.com/containers/buildah/issues/4820 Signed-off-by: Aditya R --- imagebuildah/executor.go | 2 ++ tests/bud.bats | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/imagebuildah/executor.go b/imagebuildah/executor.go index 5f23a5826a2..7edba08d994 100644 --- a/imagebuildah/executor.go +++ b/imagebuildah/executor.go @@ -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.BuiltInBuildArgs) // 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 { diff --git a/tests/bud.bats b/tests/bud.bats index 064381bc88b..055adfdeab7 100644 --- a/tests/bud.bats +++ b/tests/bud.bats @@ -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" {