mirror of
https://github.com/moby/buildkit.git
synced 2026-11-06 05:16:45 +00:00
exporter: normalize annotation platforms
Normalize platform selectors in annotation keys to match exported image platforms. Explicit linux/arm64/v8 selectors otherwise miss linux/arm64 images, silently dropping manifest and descriptor annotations. Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
3 files changed
+37
-4
No files matched your search
@@ -431,8 +431,8 @@ func testExportAnnotations(t *testing.T, sb integration.Sandbox) {
|
||||
"annotation-manifest-descriptor.gmdo": "generic manifest descriptor opt",
|
||||
"annotation-manifest[linux/amd64].mo": "amd64 manifest opt",
|
||||
"annotation-manifest-descriptor[linux/amd64].mdo": "amd64 manifest descriptor opt",
|
||||
"annotation-manifest[linux/arm64].mo": "arm64 manifest opt",
|
||||
"annotation-manifest-descriptor[linux/arm64].mdo": "arm64 manifest descriptor opt",
|
||||
"annotation-manifest[linux/arm64/v8].mo": "arm64 manifest opt",
|
||||
"annotation-manifest-descriptor[linux/arm64/v8].mdo": "arm64 manifest descriptor opt",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -498,8 +498,8 @@ func testExportAnnotations(t *testing.T, sb integration.Sandbox) {
|
||||
"annotation-manifest-descriptor.gmdo": "generic manifest descriptor opt",
|
||||
"annotation-manifest[linux/amd64].mo": "amd64 manifest opt",
|
||||
"annotation-manifest-descriptor[linux/amd64].mdo": "amd64 manifest descriptor opt",
|
||||
"annotation-manifest[linux/arm64].mo": "arm64 manifest opt",
|
||||
"annotation-manifest-descriptor[linux/arm64].mdo": "arm64 manifest descriptor opt",
|
||||
"annotation-manifest[linux/arm64/v8].mo": "arm64 manifest opt",
|
||||
"annotation-manifest-descriptor[linux/arm64/v8].mdo": "arm64 manifest descriptor opt",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -103,6 +103,7 @@ func ParseAnnotationKey(result string) (AnnotationKey, bool, error) {
|
||||
if err != nil {
|
||||
return AnnotationKey{}, true, err
|
||||
}
|
||||
p = platforms.Normalize(p)
|
||||
ociPlatform = &p
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package exptypes
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParseAnnotationKeyPlatform(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
platform string
|
||||
want ocispecs.Platform
|
||||
}{
|
||||
{"linux/arm64", ocispecs.Platform{OS: "linux", Architecture: "arm64"}},
|
||||
{"linux/arm64/v8", ocispecs.Platform{OS: "linux", Architecture: "arm64"}},
|
||||
{"linux/arm64/8", ocispecs.Platform{OS: "linux", Architecture: "arm64"}},
|
||||
{"linux/arm64/v9", ocispecs.Platform{OS: "linux", Architecture: "arm64", Variant: "v9"}},
|
||||
{"linux/arm", ocispecs.Platform{OS: "linux", Architecture: "arm", Variant: "v7"}},
|
||||
{"linux/arm/v6", ocispecs.Platform{OS: "linux", Architecture: "arm", Variant: "v6"}},
|
||||
{"linux/arm/v7", ocispecs.Platform{OS: "linux", Architecture: "arm", Variant: "v7"}},
|
||||
} {
|
||||
for _, typ := range []string{AnnotationManifest, AnnotationManifestDescriptor} {
|
||||
t.Run(typ+"/"+tc.platform, func(t *testing.T) {
|
||||
key, ok, err := ParseAnnotationKey("annotation-" + typ + "[" + tc.platform + "].example")
|
||||
require.NoError(t, err)
|
||||
require.True(t, ok)
|
||||
require.Equal(t, AnnotationKey{Type: typ, Platform: &tc.want, Key: "example"}, key)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user