@@ -2670,6 +2670,69 @@ _EOF
2670
2670
expect_output " $want_output "
2671
2671
}
2672
2672
2673
+ @test " bud and test inherit-labels" {
2674
+ run_buildah --version
2675
+ local -a output_fields=($output )
2676
+ buildah_version=${output_fields[2]}
2677
+ run_buildah build $WITH_POLICY_JSON -t exp -f $BUDFILES /base-with-labels/Containerfile
2678
+
2679
+ run_buildah inspect --format ' {{ index .Docker.Config.Labels "license"}}' exp
2680
+ expect_output " MIT" " license must be MIT from fedora base image"
2681
+ run_buildah inspect --format ' {{ index .Docker.Config.Labels "name"}}' exp
2682
+ expect_output " fedora-minimal" " name must be fedora from base image"
2683
+
2684
+ run_buildah build $WITH_POLICY_JSON --inherit-labels=false --label name=world -t exp -f $BUDFILES /base-with-labels/Containerfile
2685
+ # no labels should be inherited from base image only the, buildah version label
2686
+ # and `hello=world` which we just added using cli flag
2687
+ want_output=' map["io.buildah.version":"' $buildah_version ' " "name":"world"]'
2688
+ run_buildah inspect --format ' {{printf "%q" .Docker.Config.Labels}}' exp
2689
+ expect_output " $want_output "
2690
+
2691
+ # Try building another file with multiple layers
2692
+ run_buildah build $WITH_POLICY_JSON --iidfile ${TEST_SCRATCH_DIR} /id1 --layers -t exp -f $BUDFILES /base-with-labels/Containerfile.layer
2693
+ run_buildah inspect --format ' {{ index .Docker.Config.Labels "license"}}' exp
2694
+ expect_output " MIT" " license must be MIT from fedora base image"
2695
+ run_buildah inspect --format ' {{ index .Docker.Config.Labels "name"}}' exp
2696
+ expect_output " world" " name must be world from Containerfile"
2697
+
2698
+ # Now build same file with --inherit-labels=false and verify if we are not using the cache again.
2699
+ run_buildah build $WITH_POLICY_JSON --layers --inherit-labels=false -t exp -f $BUDFILES /base-with-labels/Containerfile.layer
2700
+ # Should not contain `Using cache` at all since
2701
+ assert " $output " ! ~ " Using cache"
2702
+ want_output=' map["io.buildah.version":"' $buildah_version ' " "name":"world"]'
2703
+ run_buildah inspect --format ' {{printf "%q" .Docker.Config.Labels}}' exp
2704
+ expect_output " $want_output "
2705
+
2706
+ # Now build same file with --inherit-labels=true and verify if using the cache
2707
+ run_buildah build $WITH_POLICY_JSON --iidfile ${TEST_SCRATCH_DIR} /id2 --layers --inherit-labels=true -t exp -f $BUDFILES /base-with-labels/Containerfile.layer
2708
+ expect_output --substring " Using cache"
2709
+ run_buildah inspect --format ' {{ index .Docker.Config.Labels "license"}}' exp
2710
+ expect_output " MIT" " license must be MIT from fedora base image"
2711
+ run_buildah inspect --format ' {{ index .Docker.Config.Labels "name"}}' exp
2712
+ expect_output " world" " name must be world from Containerfile"
2713
+ # Final image id should be exactly same as the one image which was built in the past.
2714
+ assert " $( cat ${TEST_SCRATCH_DIR} /id1) " = " $( cat ${TEST_SCRATCH_DIR} /id2) " " expected image ids to not change"
2715
+
2716
+ # Now build same file with --inherit-labels=false and verify if target stage did not inherit any labels from base stage.
2717
+ run_buildah build $WITH_POLICY_JSON --layers --inherit-labels=false -t exp -f $BUDFILES /base-with-labels/Containerfile.multi-stage
2718
+ want_output=' map["io.buildah.version":"' $buildah_version ' "]'
2719
+ run_buildah inspect --format ' {{printf "%q" .Docker.Config.Labels}}' exp
2720
+ expect_output " $want_output "
2721
+
2722
+ # Now build same file with --inherit-labels=true and verify if target stage inherits labels from the base stage.
2723
+ run_buildah build $WITH_POLICY_JSON --iidfile ${TEST_SCRATCH_DIR} /id3 --layers --inherit-labels=true -t exp -f $BUDFILES /base-with-labels/Containerfile.multi-stage
2724
+ want_output=' map["io.buildah.version":"' $buildah_version ' " "name":"world"]'
2725
+ run_buildah inspect --format ' {{printf "%q" .Docker.Config.Labels}}' exp
2726
+ expect_output " $want_output "
2727
+
2728
+ # Rebuild again with layers should not build image again at all.
2729
+ run_buildah build $WITH_POLICY_JSON --iidfile ${TEST_SCRATCH_DIR} /id4 --layers --inherit-labels=true -t exp -f $BUDFILES /base-with-labels/Containerfile.multi-stage
2730
+ want_output=' map["io.buildah.version":"' $buildah_version ' " "name":"world"]'
2731
+ run_buildah inspect --format ' {{printf "%q" .Docker.Config.Labels}}' exp
2732
+ expect_output " $want_output "
2733
+ assert " $( cat ${TEST_SCRATCH_DIR} /id3) " = " $( cat ${TEST_SCRATCH_DIR} /id3) " " expected image ids to not change"
2734
+ }
2735
+
2673
2736
@test " build using intermediate images should not inherit label" {
2674
2737
_prefetch alpine
2675
2738
0 commit comments