Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix platform handling for empty os/arch values #3698

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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