From bc05858e503b1aa7c0726bef4f2ca05efc266154 Mon Sep 17 00:00:00 2001 From: flouthoc Date: Fri, 4 Apr 2025 08:33:56 -0700 Subject: [PATCH] stage_executor,getCreatedBy: expand buildArgs for sources correctly Patch in PR https://github.com/containers/buildah/pull/5691 added a function to calculate and write checksum to history of `source` in `--mount` instructions but it did not add part to expand build args if they are present in `source` path. Following PR Just corrects the above issue and also adds a new test to make sure we don't break this in future again. Closes: https://github.com/containers/podman/issues/25425 Signed-off-by: flouthoc --- imagebuildah/stage_executor.go | 4 ++++ tests/bud.bats | 10 ++++++++++ tests/bud/buildkit-mount/Containerfile5 | 5 +++++ 3 files changed, 19 insertions(+) create mode 100644 tests/bud/buildkit-mount/Containerfile5 diff --git a/imagebuildah/stage_executor.go b/imagebuildah/stage_executor.go index fbf8d395418..b1848311b93 100644 --- a/imagebuildah/stage_executor.go +++ b/imagebuildah/stage_executor.go @@ -1896,6 +1896,10 @@ func (s *StageExecutor) getCreatedBy(node *parser.Node, addedContentSummary stri continue } mountOptionSource = mountInfo.Source + mountOptionSource, err = imagebuilder.ProcessWord(mountOptionSource, s.stage.Builder.Arguments()) + if err != nil { + return "", fmt.Errorf("getCreatedBy: while replacing arg variables with values for format %q: %w", mountOptionSource, err) + } mountOptionFrom = mountInfo.From // If source is not specified then default is '.' if mountOptionSource == "" { diff --git a/tests/bud.bats b/tests/bud.bats index 5e54a10a016..a562972d92a 100644 --- a/tests/bud.bats +++ b/tests/bud.bats @@ -6757,6 +6757,16 @@ _EOF expect_output --substring "hello" } +@test "bud-with-mount-relative-path-like-buildkit-arg-in-source" { + skip_if_no_runtime + skip_if_in_container + _prefetch alpine + local contextdir=${TEST_SCRATCH_DIR}/buildkit-mount + cp -R $BUDFILES/buildkit-mount $contextdir + run_buildah build --build-arg INPUTPATH_1=subdir -t testbud $WITH_POLICY_JSON -f $contextdir/Containerfile5 $contextdir/ + expect_output --substring "hello" +} + @test "bud-with-mount-with-rw-like-buildkit" { skip_if_no_runtime skip_if_in_container diff --git a/tests/bud/buildkit-mount/Containerfile5 b/tests/bud/buildkit-mount/Containerfile5 new file mode 100644 index 00000000000..9e31936072f --- /dev/null +++ b/tests/bud/buildkit-mount/Containerfile5 @@ -0,0 +1,5 @@ +FROM alpine +ARG INPUTPATH_1=subdir +RUN mkdir /test +# use option z if selinux is enabled +RUN --mount=type=bind,source=${INPUTPATH_1:?}/,target=/test,z cat /test/input_file