@@ -943,6 +943,34 @@ _EOF
943
943
944
944
}
945
945
946
+ @test " build-test use image from cache with --mount and burst when image is changed" {
947
+ _prefetch alpine
948
+ local contextdir=${TEST_SCRATCH_DIR} /bud/platform
949
+ mkdir -p $contextdir
950
+
951
+ cat > $contextdir /Containerfile << _EOF
952
+ FROM alpine
953
+ RUN touch firstfile
954
+ _EOF
955
+
956
+ run_buildah build $WITH_POLICY_JSON --layers -t source -f $contextdir /Containerfile
957
+
958
+ cat > $contextdir /Containerfile2 << _EOF
959
+ FROM alpine
960
+
961
+ RUN --mount=type=bind,source=.,target=/build,from=source ls /build
962
+
963
+ _EOF
964
+
965
+ run_buildah build $WITH_POLICY_JSON --layers -t source2 -f $contextdir /Containerfile2
966
+ expect_output --substring " firstfile"
967
+
968
+ # Building again must use cache
969
+ run_buildah build $WITH_POLICY_JSON --layers -t source2 -f $contextdir /Containerfile2
970
+ expect_output --substring " Using cache"
971
+ assert " $output " ! ~ " firstfile"
972
+ }
973
+
946
974
# Verify: https://github.com/containers/buildah/issues/4572
947
975
@test " build-test verify no dangling containers are left" {
948
976
_prefetch alpine busybox
@@ -1515,6 +1543,30 @@ _EOF
1515
1543
expect_output --substring " world"
1516
1544
}
1517
1545
1546
+ @test " build-with-additional-build-context must use cache if built with layers" {
1547
+ _prefetch alpine
1548
+ local contextdir=${TEST_SCRATCH_DIR} /bud/platform
1549
+ mkdir -p $contextdir
1550
+ echo world > $contextdir /hello
1551
+
1552
+ cat > $contextdir /Containerfile2 << _EOF
1553
+ FROM alpine as some-stage
1554
+ RUN echo some_text
1555
+
1556
+ # hello should get copied since we are giving priority to additional context
1557
+ FROM alpine
1558
+ RUN --mount=type=bind,from=some-stage,target=/test,z cat /test/hello
1559
+ _EOF
1560
+
1561
+ # Additional context for RUN --mount is file on host
1562
+ run_buildah build $WITH_POLICY_JSON --layers --build-context some-stage=$contextdir -t test -f $contextdir /Containerfile2
1563
+ expect_output --substring " world"
1564
+
1565
+ run_buildah build $WITH_POLICY_JSON --layers --build-context some-stage=$contextdir -t test -f $contextdir /Containerfile2
1566
+ expect_output --substring " Using cache"
1567
+ assert " $output " ! ~ " world"
1568
+ }
1569
+
1518
1570
# Test usage of RUN --mount=from=<name> with additional context is URL and mount source is relative using src
1519
1571
@test " build-with-additional-build-context and RUN --mount=from=, additional-context is URL and mounted from subdir" {
1520
1572
_prefetch alpine
0 commit comments