@@ -2670,6 +2670,49 @@ _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 hello=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["hello":"world" "io.buildah.version":"' $buildah_version ' "]'
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 --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 --layers --inherit-labels=true -t exp -f $BUDFILES /base-with-labels/Containerfile.layer
2708+ # Should contain `Using cache` at all since
2709+ expect_output --substring " Using cache"
2710+ run_buildah inspect --format ' {{ index .Docker.Config.Labels "license"}}' exp
2711+ expect_output " MIT" " license must be MIT from fedora base image"
2712+ run_buildah inspect --format ' {{ index .Docker.Config.Labels "name"}}' exp
2713+ expect_output " world" " name must be world from Containerfile"
2714+ }
2715+
26732716@test " build using intermediate images should not inherit label" {
26742717 _prefetch alpine
26752718
0 commit comments