Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 15 additions & 2 deletions wanda/forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,27 @@ func NewForge(config *ForgeConfig) (*Forge, error) {
return nil, fmt.Errorf("abs path for work dir: %w", err)
}

// Determine target platform for image resolution.
// If Platform is specified in config, parse it (e.g., "linux/arm64").
// Otherwise, default to the host OS/arch.
targetOS := runtime.GOOS
targetArch := runtime.GOARCH
if config.Platform != "" {
parts := strings.SplitN(config.Platform, "/", 2)
if len(parts) == 2 {
targetOS = parts[0]
targetArch = parts[1]
}
}
Comment on lines 60 to 67
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The current platform string parsing is not robust. It silently ignores malformed platform strings (e.g., "linux") by falling back to the host's platform, and can mis-parse strings like "/arm64" or "linux/". This could lead to unexpected behavior. It would be better to validate the format and return an error for invalid input.

Suggested change
if config.Platform != "" {
parts := strings.SplitN(config.Platform, "/", 2)
if len(parts) == 2 {
targetOS = parts[0]
targetArch = parts[1]
}
}
if config.Platform != "" {
parts := strings.SplitN(config.Platform, "/", 2)
if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
return nil, fmt.Errorf("invalid platform format: %q, expected \"os/arch\"", config.Platform)
}
targetOS = parts[0]
targetArch = parts[1]
}


f := &Forge{
config: config,
workDir: absWorkDir,
remoteOpts: []remote.Option{
remote.WithAuthFromKeychain(authn.DefaultKeychain),
remote.WithPlatform(crane.Platform{
OS: runtime.GOOS,
Architecture: runtime.GOARCH,
OS: targetOS,
Architecture: targetArch,
}),
},
}
Expand Down
4 changes: 4 additions & 0 deletions wanda/forge_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ type ForgeConfig struct {
BuildID string
Epoch string

// Platform specifies the target platform for image resolution (e.g., "linux/arm64").
// If empty, defaults to the host OS/arch.
Platform string

RayCI bool
Rebuild bool

Expand Down
9 changes: 9 additions & 0 deletions wanda/wanda/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Flags:
func main() {
workDir := flag.String("work_dir", ".", "root directory for the build")
docker := flag.String("docker", "", "path to the docker client binary")
platform := flag.String("platform", "", "target platform for image resolution (e.g., linux/arm64)")
rayCI := flag.Bool(
"rayci", false,
"takes RAYCI_ env vars for input and run in remote mode",
Expand Down Expand Up @@ -71,13 +72,21 @@ func main() {
input = os.Getenv("RAYCI_WANDA_FILE")
}

// Platform can be set via flag or WANDA_PLATFORM env var.
// This is needed for cross-platform builds (e.g., building linux/arm64 on macOS).
targetPlatform := *platform
if targetPlatform == "" {
targetPlatform = os.Getenv("WANDA_PLATFORM")
}

config := &wanda.ForgeConfig{
WorkDir: *workDir,
DockerBin: *docker,
WorkRepo: *workRepo,
NamePrefix: *namePrefix,
BuildID: *buildID,
Epoch: *epoch,
Platform: targetPlatform,

RayCI: *rayCI,
Rebuild: *rebuild,
Expand Down