diff --git a/imagebuildah/build.go b/imagebuildah/build.go index 3c8150ef6d3..cefb1857ef6 100644 --- a/imagebuildah/build.go +++ b/imagebuildah/build.go @@ -216,8 +216,12 @@ func BuildDockerfiles(ctx context.Context, store storage.Store, options define.B Architecture: platform.Arch, Variant: platform.Variant, }) - if platformSpec.OS != "" && platformSpec.Architecture != "" { + // platforms.Normalize converts an empty os value to GOOS + // so we have to check the original value here to not overwrite the default for no reason + if platform.OS != "" { platformContext.OSChoice = platformSpec.OS + } + if platform.Arch != "" { platformContext.ArchitectureChoice = platformSpec.Architecture platformContext.VariantChoice = platformSpec.Variant } diff --git a/tests/bud.bats b/tests/bud.bats index ffefe58b82c..1964d5c111a 100644 --- a/tests/bud.bats +++ b/tests/bud.bats @@ -2429,6 +2429,30 @@ EOM expect_output arm } +@test "bud with custom platform and empty os or arch" { + run_buildah build --signature-policy ${TESTSDIR}/policy.json \ + -f ${TESTSDIR}/bud/from-scratch/Containerfile \ + -t platform-test \ + --platform=windows/ + + run_buildah inspect --format "{{ .Docker.OS }}" platform-test + expect_output windows + + run_buildah inspect --format "{{ .OCIv1.OS }}" platform-test + expect_output windows + + run_buildah build --signature-policy ${TESTSDIR}/policy.json \ + -f ${TESTSDIR}/bud/from-scratch/Containerfile \ + -t platform-test2 \ + --platform=/arm + + run_buildah inspect --format "{{ .Docker.Architecture }}" platform-test2 + expect_output arm + + run_buildah inspect --format "{{ .OCIv1.Architecture }}" platform-test2 + expect_output arm +} + @test "bud Add with linked tarball" { _prefetch alpine run_buildah build --signature-policy ${TESTSDIR}/policy.json -f ${TESTSDIR}/bud/symlink/Containerfile.add-tar-with-link -t testctr ${TESTSDIR}/bud/symlink