Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion exporter/containerimage/exptypes/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package exptypes
import (
"encoding/json"
"fmt"
"strings"

"github.com/containerd/platforms"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -33,7 +34,19 @@ func ParsePlatforms(meta map[string][]byte) (Platforms, error) {
}

var p ocispecs.Platform
if imgConfig, ok := meta[ExporterImageConfigKey]; ok {
var imgConfig []byte
if c, ok := meta[ExporterImageConfigKey]; ok {
imgConfig = c
} else {
for k, v := range meta {
if len(v) > 0 && strings.HasPrefix(k, ExporterImageConfigKey+"/") {
imgConfig = v
break
}
}
}

if len(imgConfig) > 0 {
var img ocispecs.Image
err := json.Unmarshal(imgConfig, &img)
if err != nil {
Expand Down
30 changes: 30 additions & 0 deletions exporter/containerimage/exptypes/parse_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package exptypes

import (
"encoding/json"
"testing"

ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/stretchr/testify/require"
)

func TestParsePlatforms(t *testing.T) {
img := ocispecs.Image{
Platform: ocispecs.Platform{
OS: "linux",
Architecture: "arm64",
},
}
dt, err := json.Marshal(img)
require.NoError(t, err)

meta := map[string][]byte{
ExporterImageConfigKey + "/linux/arm64": dt,
}

ps, err := ParsePlatforms(meta)
require.NoError(t, err)
require.Equal(t, 1, len(ps.Platforms))
require.Equal(t, "linux", ps.Platforms[0].Platform.OS)
require.Equal(t, "arm64", ps.Platforms[0].Platform.Architecture)
}