Skip to content

Commit 3d926d3

Browse files
committed
stage_executor,getCreatedBy: expand buildArgs for sources correctly
Patch in PR #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: containers/podman#25425 Signed-off-by: flouthoc <[email protected]>
1 parent 7509c34 commit 3d926d3

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

imagebuildah/stage_executor.go

+4
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,10 @@ func (s *StageExecutor) getCreatedBy(node *parser.Node, addedContentSummary stri
19031903
continue
19041904
}
19051905
mountOptionSource = mountInfo.Source
1906+
mountOptionSource, err = imagebuilder.ProcessWord(mountOptionSource, s.stage.Builder.Arguments())
1907+
if err != nil {
1908+
return "", fmt.Errorf("getCreatedBy: while replacing arg variables with values for format %q: %w", mountOptionSource, err)
1909+
}
19061910
mountOptionFrom = mountInfo.From
19071911
// If source is not specified then default is '.'
19081912
if mountOptionSource == "" {

tests/bud.bats

+10
Original file line numberDiff line numberDiff line change
@@ -6745,6 +6745,16 @@ _EOF
67456745
expect_output --substring "hello"
67466746
}
67476747

6748+
@test "bud-with-mount-relative-path-like-buildkit-arg-in-source" {
6749+
skip_if_no_runtime
6750+
skip_if_in_container
6751+
_prefetch alpine
6752+
local contextdir=${TEST_SCRATCH_DIR}/buildkit-mount
6753+
cp -R $BUDFILES/buildkit-mount $contextdir
6754+
run_buildah build --build-arg INPUTPATH_1=subdir -t testbud $WITH_POLICY_JSON -f $contextdir/Containerfile5 $contextdir/
6755+
expect_output --substring "hello"
6756+
}
6757+
67486758
@test "bud-with-mount-with-rw-like-buildkit" {
67496759
skip_if_no_runtime
67506760
skip_if_in_container
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM alpine
2+
ARG INPUTPATH_1=subdir
3+
RUN mkdir /test
4+
# use option z if selinux is enabled
5+
RUN --mount=type=bind,source=${INPUTPATH_1:?}/,target=/test,z cat /test/input_file

0 commit comments

Comments
 (0)