Skip to content
Closed
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
34 changes: 34 additions & 0 deletions cli/src/pkg/booth/ensure_docker_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/nawaman/codingbooth/src/pkg/appctx"
"github.com/nawaman/codingbooth/src/pkg/boothfile"
Expand Down Expand Up @@ -249,6 +250,18 @@ func buildLocalImage(ctx appctx.AppContext) {
"--pull=false",
)))
}
// A --platform in common-args/run-args exists to force a specific
// architecture for the whole booth (e.g. an x86_64-only SDK under
// emulation on arm64), but it was only ever threaded into `docker run`.
// Building without it produces an image for the host's native arch, and
// `docker run --platform ...` then refuses to start it: the local image
// has no manifest for the platform it was asked to run under. Apply the
// same platform to the build so the image it produces actually matches.
if platform, ok := extractPlatformFlag(ctx.CommonArgs(), ctx.RunArgs()); ok {
args = args.ExtendByLists(ilist.NewList(ilist.NewList(
"--platform", platform,
)))
}
args = args.ExtendByLists(ilist.NewList(ilist.NewList(
"--build-arg", fmt.Sprintf("BOOTH_VARIANT_TAG=%s", ctx.Variant()),
)))
Expand Down Expand Up @@ -278,6 +291,27 @@ func buildLocalImage(ctx appctx.AppContext) {
}
}

// extractPlatformFlag scans the given argument groups (in order) for a
// "--platform <value>" or "--platform=<value>" pair and returns the first
// value found. Groups are flat docker CLI argument lists, e.g. common-args
// or run-args from config.toml.
func extractPlatformFlag(groupLists ...ilist.List[ilist.List[string]]) (string, bool) {
for _, groups := range groupLists {
for _, group := range groups.Slice() {
items := group.Slice()
for i, item := range items {
if item == "--platform" && i+1 < len(items) {
return items[i+1], true
}
if value, ok := strings.CutPrefix(item, "--platform="); ok {
return value, true
}
}
}
}
return "", false
}

// pullImageIfNeeded pulls the Docker image if needed.
func pullImageIfNeeded(ctx appctx.AppContext) {
imageName := ctx.Image()
Expand Down
Loading