Skip to content

Commit

Permalink
Merge pull request #3698 from Luap99/os-arch
Browse files Browse the repository at this point in the history
Fix platform handling for empty os/arch values
  • Loading branch information
openshift-merge-robot authored Jan 12, 2022
2 parents 031e72c + 42f1333 commit d744ebc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion imagebuildah/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
24 changes: 24 additions & 0 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d744ebc

Please sign in to comment.