@@ -358,6 +358,30 @@ func (e *imageExporterInstance) pushImage(ctx context.Context, src *exporter.Sou
358
358
}
359
359
360
360
func (e * imageExporterInstance ) unpackImage (ctx context.Context , img images.Image , src * exporter.Source , s session.Group ) (err0 error ) {
361
+ p := platforms .Format (platforms .Normalize (platforms .DefaultSpec ()))
362
+
363
+ ps , err := exptypes .ParsePlatforms (src .Metadata )
364
+ if err != nil {
365
+ return err
366
+ }
367
+ found := false
368
+ for _ , p2 := range ps .Platforms {
369
+ if p2 .ID == p {
370
+ found = true
371
+ break
372
+ }
373
+ }
374
+ if ! found {
375
+ // current platform was not found, so skip unpacking
376
+ return nil
377
+ }
378
+
379
+ ref , _ := src .FindRef (p )
380
+ if ref == nil {
381
+ // ref has no layers, so nothing to unpack
382
+ return nil
383
+ }
384
+
361
385
unpackDone := progress .OneOff (ctx , "unpacking to " + img .Name )
362
386
defer func () {
363
387
unpackDone (err0 )
@@ -375,15 +399,6 @@ func (e *imageExporterInstance) unpackImage(ctx context.Context, img images.Imag
375
399
return err
376
400
}
377
401
378
- ref , ok := src .FindRef (defaultPlatform ())
379
- if ! ok {
380
- return errors .Errorf ("no reference for default platform %s" , defaultPlatform ())
381
- }
382
- if ref == nil {
383
- // ref has no layers, so nothing to unpack
384
- return nil
385
- }
386
-
387
402
remotes , err := ref .GetRemotes (ctx , true , e .opts .RefCfg , false , s )
388
403
if err != nil {
389
404
return err
@@ -457,12 +472,6 @@ func addAnnotations(m map[digest.Digest]map[string]string, desc ocispecs.Descrip
457
472
}
458
473
}
459
474
460
- func defaultPlatform () string {
461
- // Use normalized platform string to avoid the mismatch with platform options which
462
- // are normalized using platforms.Normalize()
463
- return platforms .Format (platforms .Normalize (platforms .DefaultSpec ()))
464
- }
465
-
466
475
func NewDescriptorReference (desc ocispecs.Descriptor , release func (context.Context ) error ) exporter.DescriptorReference {
467
476
return & descriptorReference {
468
477
desc : desc ,
0 commit comments