Skip to content

Commit

Permalink
Fix platform handling for empty os/arch values
Browse files Browse the repository at this point in the history
If you run `buildah bud --platform windows/` the os is ignored at the
moment and it uses the host os. We should still use the os from the
platform in this case. This fixes an issue with podman-remote build
where it is possible that only the os is set in the platform string.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Jan 11, 2022
1 parent b3798a1 commit d5043a8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion imagebuildah/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ func BuildDockerfiles(ctx context.Context, store storage.Store, options define.B
Architecture: platform.Arch,
Variant: platform.Variant,
})
if platformSpec.OS != "" && platformSpec.Architecture != "" {
if platformSpec.OS != "" {
platformContext.OSChoice = platformSpec.OS
}
if platformSpec.Architecture != "" {
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 @@ -2423,6 +2423,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 d5043a8

Please sign in to comment.