@@ -3,11 +3,13 @@ package local
33import (
44 "context"
55 "fmt"
6+ "runtime"
67
78 cerrdefs "github.com/containerd/errdefs"
89 v1 "github.com/google/go-containerregistry/pkg/v1"
910 "github.com/moby/moby/api/types/image"
1011 "github.com/moby/moby/client"
12+ ocispec "github.com/opencontainers/image-spec/specs-go/v1"
1113
1214 "github.com/buildpacks/imgutil"
1315)
@@ -26,7 +28,7 @@ func NewImage(repoName string, dockerClient DockerClient, ops ...imgutil.ImageOp
2628 return nil , err
2729 }
2830
29- previousImage , err := processImageOption (options .PreviousImageRepoName , dockerClient , true )
31+ previousImage , err := processImageOption (options .PreviousImageRepoName , options . Platform , dockerClient , true )
3032 if err != nil {
3133 return nil , err
3234 }
@@ -38,7 +40,7 @@ func NewImage(repoName string, dockerClient DockerClient, ops ...imgutil.ImageOp
3840 baseIdentifier string
3941 store * Store
4042 )
41- baseImage , err := processImageOption (options .BaseImageRepoName , dockerClient , false )
43+ baseImage , err := processImageOption (options .BaseImageRepoName , options . Platform , dockerClient , false )
4244 if err != nil {
4345 return nil , err
4446 }
@@ -69,6 +71,12 @@ func defaultPlatform(dockerClient DockerClient) (imgutil.Platform, error) {
6971 if err != nil {
7072 return imgutil.Platform {}, err
7173 }
74+ if daemonInfo .Os == "linux" {
75+ return imgutil.Platform {
76+ OS : "linux" ,
77+ Architecture : runtime .GOARCH ,
78+ }, nil
79+ }
7280 return imgutil.Platform {
7381 OS : daemonInfo .Os ,
7482 Architecture : daemonInfo .Arch ,
@@ -96,11 +104,11 @@ type imageResult struct {
96104 layerStore * Store
97105}
98106
99- func processImageOption (repoName string , dockerClient DockerClient , downloadLayersOnAccess bool ) (imageResult , error ) {
107+ func processImageOption (repoName string , platform imgutil. Platform , dockerClient DockerClient , downloadLayersOnAccess bool ) (imageResult , error ) {
100108 if repoName == "" {
101109 return imageResult {}, nil
102110 }
103- inspect , history , err := getInspectAndHistory (repoName , dockerClient )
111+ inspect , history , err := getInspectAndHistory (repoName , platform , dockerClient )
104112 if err != nil {
105113 return imageResult {}, err
106114 }
@@ -119,8 +127,19 @@ func processImageOption(repoName string, dockerClient DockerClient, downloadLaye
119127 }, nil
120128}
121129
122- func getInspectAndHistory (repoName string , dockerClient DockerClient ) (* image.InspectResponse , []image.HistoryResponseItem , error ) {
123- inspect , err := dockerClient .ImageInspect (context .Background (), repoName )
130+ func getInspectAndHistory (repoName string , platform imgutil.Platform , dockerClient DockerClient ) (* image.InspectResponse , []image.HistoryResponseItem , error ) {
131+ platformOpt := client .ImageInspectWithPlatform (& ocispec.Platform {
132+ Architecture : platform .Architecture ,
133+ OS : platform .OS ,
134+ OSVersion : platform .OSVersion ,
135+ Variant : platform .Variant ,
136+ })
137+ // Try to inspect the image with the default platform/arch
138+ inspect , err := dockerClient .ImageInspect (context .Background (), repoName , platformOpt )
139+ if err != nil {
140+ // ...and if that fails, inspect without the platfrom
141+ inspect , err = dockerClient .ImageInspect (context .Background (), repoName )
142+ }
124143 if err != nil {
125144 if cerrdefs .IsNotFound (err ) {
126145 return nil , nil , nil
0 commit comments