Skip to content

Commit

Permalink
feat: allow setting platform for scratch image
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
dsseng committed Jan 17, 2025
1 parent c2c70ac commit 4d1d94e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions frontend/dockerfile/dockerfile2llb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,12 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS
if d.base == nil && !d.dispatched && !d.resolved {
d.resolved = reachable // avoid re-resolving if called again after onbuild
if d.stage.BaseName == emptyImageName {
d.state = llb.Scratch()
d.image = emptyImage(platformOpt.targetPlatform)
d.platform = &platformOpt.targetPlatform
platform := d.platform
if platform == nil {
platform = &platformOpt.targetPlatform
}
d.state = llb.Scratch().Platform(*platform)
d.image = emptyImage(*platform)
if d.unregistered {
d.dispatched = true
}
Expand Down Expand Up @@ -511,7 +514,7 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS
if img != nil {
d.image = *img
} else {
d.image = emptyImage(platformOpt.targetPlatform)
d.image = emptyImage(*platform)
}
d.state = st.Platform(*platform)
d.platform = platform
Expand Down

0 comments on commit 4d1d94e

Please sign in to comment.