Skip to content

Commit 6c1d491

Browse files
committed
containerimage: use platform matcher to detect platform to unpack
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
1 parent ec51ec8 commit 6c1d491

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

exporter/containerimage/export.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/base64"
66
"encoding/json"
77
"fmt"
8+
"sort"
89
"strconv"
910
"strings"
1011

@@ -358,25 +359,27 @@ func (e *imageExporterInstance) pushImage(ctx context.Context, src *exporter.Sou
358359
}
359360

360361
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+
matcher := platforms.Only(platforms.Normalize(platforms.DefaultSpec()))
362363

363364
ps, err := exptypes.ParsePlatforms(src.Metadata)
364365
if err != nil {
365366
return err
366367
}
367-
found := false
368+
matching := []exptypes.Platform{}
368369
for _, p2 := range ps.Platforms {
369-
if p2.ID == p {
370-
found = true
371-
break
370+
if matcher.Match(p2.Platform) {
371+
matching = append(matching, p2)
372372
}
373373
}
374-
if !found {
374+
if len(matching) == 0 {
375375
// current platform was not found, so skip unpacking
376376
return nil
377377
}
378+
sort.SliceStable(matching, func(i, j int) bool {
379+
return matcher.Less(matching[i].Platform, matching[j].Platform)
380+
})
378381

379-
ref, _ := src.FindRef(p)
382+
ref, _ := src.FindRef(matching[0].ID)
380383
if ref == nil {
381384
// ref has no layers, so nothing to unpack
382385
return nil

0 commit comments

Comments
 (0)