diff --git a/exporter/containerimage/annotations.go b/exporter/containerimage/annotations.go index 1bf10f6c15db..b642077c6445 100644 --- a/exporter/containerimage/annotations.go +++ b/exporter/containerimage/annotations.go @@ -71,7 +71,7 @@ func (ag AnnotationsGroup) Platform(p *ocispecs.Platform) *Annotations { ps := []string{""} if p != nil { - ps = append(ps, platforms.FormatAll(*p)) + ps = append(ps, platforms.FormatAll(platforms.Normalize(*p))) } for _, a := range ag { diff --git a/exporter/containerimage/annotations_test.go b/exporter/containerimage/annotations_test.go new file mode 100644 index 000000000000..2649fb4d89cd --- /dev/null +++ b/exporter/containerimage/annotations_test.go @@ -0,0 +1,33 @@ +package containerimage + +import ( + "testing" + + "github.com/moby/buildkit/exporter/containerimage/exptypes" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/stretchr/testify/require" +) + +func TestAnnotationsPlatformNormalized(t *testing.T) { + ag, rest, err := ParseAnnotations(map[string][]byte{ + "annotation-manifest-descriptor[linux/arm64/v8].example": []byte("v"), + }) + require.NoError(t, err) + require.Empty(t, rest) + + for _, p := range []ocispecs.Platform{ + {OS: "linux", Architecture: "arm64"}, + {OS: "linux", Architecture: "arm64", Variant: "v8"}, + } { + a := ag.Platform(&p) + require.Equal(t, map[string]string{"example": "v"}, a.ManifestDescriptor, p) + } + + a := ag.Platform(&ocispecs.Platform{OS: "linux", Architecture: "amd64"}) + require.Empty(t, a.ManifestDescriptor) + + k, ok, err := exptypes.ParseAnnotationKey("annotation-manifest[linux/arm64/v8].k") + require.NoError(t, err) + require.True(t, ok) + require.Equal(t, "linux/arm64", k.PlatformString()) +} diff --git a/exporter/containerimage/exptypes/annotations.go b/exporter/containerimage/exptypes/annotations.go index a9b74d6b9681..6b77014ccdef 100644 --- a/exporter/containerimage/exptypes/annotations.go +++ b/exporter/containerimage/exptypes/annotations.go @@ -103,6 +103,7 @@ func ParseAnnotationKey(result string) (AnnotationKey, bool, error) { if err != nil { return AnnotationKey{}, true, err } + p = platforms.Normalize(p) ociPlatform = &p }