@@ -13,12 +13,13 @@ import (
1313
1414// DepotLoadOptions are options to load images from the depot hosted registry.
1515type DepotLoadOptions struct {
16- Project string // Depot project name; used to tag images.
17- BuildID string // Depot build ID; used to tag images.
18- IsBake bool // If run from bake, we add the bake target to the image tag.
19- ProgressMode string // ProgressMode quiet will not print progress.
20- UseRegistry bool // If UseRegistry, load build from registry instead of proxy
21- PullInfo * depotbuild.PullInfo // If UseRegistry, the credentials for pulling from registry
16+ Project string // Depot project name; used to tag images.
17+ BuildID string // Depot build ID; used to tag images.
18+ IsBake bool // If run from bake, we add the bake target to the image tag.
19+ ProgressMode string // ProgressMode quiet will not print progress.
20+ UseRegistry bool // If UseRegistry, load build from registry instead of proxy
21+ PullInfo * depotbuild.PullInfo // If UseRegistry, the credentials for pulling from registry
22+ BuildPlatform string // If set (e.g. "linux/amd64"), used as the pull platform when buildOpt.Platforms is empty.
2223}
2324
2425// Options to download from the Depot hosted registry and tag the image with the user provide tag.
@@ -74,19 +75,28 @@ func WithDepotImagePull(buildOpts map[string]build.Options, loadOpts DepotLoadOp
7475 Quiet : loadOpts .ProgressMode == progress .PrinterModeQuiet ,
7576 }
7677
78+ // Specify a platform to pull when a single platform is used.
79+ // This ensures Docker pulls the correct architecture manifest
80+ // even when the build platform differs from the host (e.g.
81+ // building amd64 on an arm64 Mac), avoiding a slow tarball
82+ // fallback during fast load.
83+ platforms := platformutil .Format (buildOpt .Platforms )
84+ if len (platforms ) == 1 {
85+ platform := platforms [0 ]
86+ pullOpt .Platform = & platform
87+ } else if len (platforms ) == 0 && loadOpts .BuildPlatform != "" {
88+ // When --build-platform is specified but platforms is not set in the
89+ // compose file, use the build platform so Docker pulls the correct
90+ // architecture instead of defaulting to the host architecture.
91+ pullOpt .Platform = & loadOpts .BuildPlatform
92+ }
93+
7794 if loadOpts .UseRegistry && loadOpts .PullInfo != nil {
7895 serverAddress := "registry.depot.dev"
7996 pullOpt .KeepImage = true
8097 pullOpt .Username = & loadOpts .PullInfo .Username
8198 pullOpt .Password = & loadOpts .PullInfo .Password
8299 pullOpt .ServerAddress = & serverAddress
83-
84- platforms := platformutil .Format (buildOpt .Platforms )
85- // only specify a platform to pull when a single platform is used
86- if len (platforms ) == 1 {
87- platform := platforms [0 ]
88- pullOpt .Platform = & platform
89- }
90100 }
91101
92102 toPull [target ] = pullOpt
0 commit comments