@@ -2670,6 +2670,65 @@ _EOF
26702670 expect_output " $want_output "
26712671}
26722672
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+ if [[ $( cat ${TEST_SCRATCH_DIR} /id1) != $( cat ${TEST_SCRATCH_DIR} /id2) ]]; then
2715+ echo " Expected image id to not change" >&2
2716+ false
2717+ fi
2718+
2719+ # Now build same file with --inherit-labels=false and verify if target stage did not inherit any labels from base stage.
2720+ run_buildah build $WITH_POLICY_JSON --layers --inherit-labels=false -t exp -f $BUDFILES /base-with-labels/Containerfile.multi-stage
2721+ want_output=' map["io.buildah.version":"' $buildah_version ' "]'
2722+ run_buildah inspect --format ' {{printf "%q" .Docker.Config.Labels}}' exp
2723+ expect_output " $want_output "
2724+
2725+ # Now build same file with --inherit-labels=true and verify if target stage inherits labels from the base stage.
2726+ run_buildah build $WITH_POLICY_JSON --layers --inherit-labels=true -t exp -f $BUDFILES /base-with-labels/Containerfile.multi-stage
2727+ want_output=' map["io.buildah.version":"' $buildah_version ' " "name":"world"]'
2728+ run_buildah inspect --format ' {{printf "%q" .Docker.Config.Labels}}' exp
2729+ expect_output " $want_output "
2730+ }
2731+
26732732@test " build using intermediate images should not inherit label" {
26742733 _prefetch alpine
26752734
0 commit comments