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

feat: allow setting platform for scratch image #5670

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dsseng
Copy link

@dsseng dsseng commented Jan 17, 2025

BuildKit refers to platform set in the current LLB node for determining whether or not executing commands should use QEMU. This makes some build flows working fine without BuildKit to fail with it. This is of particular importance for cross-compilation cases.

Make scratch image a no exception and allow platform to be set, therefore determining the architecture of binaries planned to be ran (e.g. if they are COPYed from contexts)

Example use case: siderolabs/stagex@eec19a8 - here we build for arm64 and amd64 targets, but use linux/386 compiler binary, as these are cross-compilation stages. So if scratch is used, then buildkit would use target platform and assume QEMU must be called to run /bin/sh, which crashed the build, since BuildKit called qemu-aarch64, which errored on i386 ELF file supplied. But with this patch I'm able to declare platform build happens in, even though I only add images later on (and for example stage3 pulls in multiplatform stage2, so in this case FROM stage2 directly won't work either)

Example build (listing logs with linux/386->arm64) https://github.com/siderolabs/stagex/actions/runs/12834542603/job/35792080087

BuildKit refers to platform set in the current LLB node for determining whether or not executing commands should use QEMU. This makes some build flows working fine without BuildKit to fail with it. This is of particular importance for cross-compilation cases.

Make scratch image a no exception and allow platform to be set, therefore determining the architecture of binaries planned to be ran (e.g. if they are COPYed from contexts)

Signed-off-by: Dmitry Sharshakov <[email protected]>
Comment on lines +471 to +474
platform := d.platform
if platform == nil {
platform = &platformOpt.targetPlatform
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if that's needed

Suggested change
platform := d.platform
if platform == nil {
platform = &platformOpt.targetPlatform
}
platform := d.platform
if platform == nil {
platform = &platformOpt.targetPlatform
}
d.platform = platform

dsseng added a commit to siderolabs/stagex that referenced this pull request Jan 18, 2025
dsseng added a commit to siderolabs/stagex that referenced this pull request Jan 18, 2025
dsseng added a commit to siderolabs/stagex that referenced this pull request Jan 18, 2025
dsseng added a commit to siderolabs/stagex that referenced this pull request Jan 18, 2025
dsseng added a commit to siderolabs/stagex that referenced this pull request Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant