@@ -61,7 +61,8 @@ func GetPublicImage(ctx context.Context, dockerhubRepository dockerhub.RemoteRep
6161 }
6262
6363 // Build options
64- opts := []remote.Option {remote .WithPlatform (DefaultPlatform )}
64+ platform := DefaultPlatform
65+ opts := []remote.Option {remote .WithPlatform (platform )}
6566
6667 // Use the auth provider if provided
6768 if authProvider != nil {
@@ -81,20 +82,32 @@ func GetPublicImage(ctx context.Context, dockerhubRepository dockerhub.RemoteRep
8182
8283 telemetry .ReportEvent (ctx , "pulled public image" )
8384
85+ err = verifyImagePlatform (img , platform )
86+ if err != nil {
87+ return nil , err
88+ }
89+
8490 return img , nil
8591}
8692
8793func GetImage (ctx context.Context , artifactRegistry artifactsregistry.ArtifactsRegistry , templateId string , buildId string ) (containerregistry.Image , error ) {
8894 childCtx , childSpan := tracer .Start (ctx , "pull-docker-image" )
8995 defer childSpan .End ()
9096
91- img , err := artifactRegistry .GetImage (childCtx , templateId , buildId , DefaultPlatform )
97+ platform := DefaultPlatform
98+
99+ img , err := artifactRegistry .GetImage (childCtx , templateId , buildId , platform )
92100 if err != nil {
93101 return nil , fmt .Errorf ("error pulling image: %w" , err )
94102 }
95103
96104 telemetry .ReportEvent (childCtx , "pulled image" )
97105
106+ err = verifyImagePlatform (img , platform )
107+ if err != nil {
108+ return nil , err
109+ }
110+
98111 return img , nil
99112}
100113
@@ -366,3 +379,14 @@ func createExport(ctx context.Context, logger *zap.Logger, srcImage containerreg
366379
367380 return layerPaths , nil
368381}
382+
383+ func verifyImagePlatform (img containerregistry.Image , platform containerregistry.Platform ) error {
384+ config , err := img .ConfigFile ()
385+ if err != nil {
386+ return fmt .Errorf ("error getting image config file: %w" , err )
387+ }
388+ if config .Architecture != platform .Architecture {
389+ return fmt .Errorf ("image is not %s" , platform .Architecture )
390+ }
391+ return nil
392+ }
0 commit comments