Skip to content

Commit c4f0515

Browse files
committed
Register OCI image media types
OCI types are backwards compatible with Docker manifest types, however the media types must be registered. Signed-off-by: Derek McGowan <[email protected]>
1 parent 68e25cf commit c4f0515

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

distribution/oci.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package distribution
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/docker/distribution"
7+
"github.com/docker/distribution/manifest/manifestlist"
8+
"github.com/docker/distribution/manifest/schema2"
9+
digest "github.com/opencontainers/go-digest"
10+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
11+
)
12+
13+
func init() {
14+
// TODO: Remove this registration if distribution is included with OCI support
15+
16+
ocischemaFunc := func(b []byte) (distribution.Manifest, distribution.Descriptor, error) {
17+
m := new(schema2.DeserializedManifest)
18+
err := m.UnmarshalJSON(b)
19+
if err != nil {
20+
return nil, distribution.Descriptor{}, err
21+
}
22+
23+
dgst := digest.FromBytes(b)
24+
return m, distribution.Descriptor{Digest: dgst, Size: int64(len(b)), MediaType: ocispec.MediaTypeImageManifest}, err
25+
}
26+
err := distribution.RegisterManifestSchema(ocispec.MediaTypeImageManifest, ocischemaFunc)
27+
if err != nil {
28+
panic(fmt.Sprintf("Unable to register manifest: %s", err))
29+
}
30+
31+
manifestListFunc := func(b []byte) (distribution.Manifest, distribution.Descriptor, error) {
32+
m := new(manifestlist.DeserializedManifestList)
33+
err := m.UnmarshalJSON(b)
34+
if err != nil {
35+
return nil, distribution.Descriptor{}, err
36+
}
37+
38+
dgst := digest.FromBytes(b)
39+
return m, distribution.Descriptor{Digest: dgst, Size: int64(len(b)), MediaType: ocispec.MediaTypeImageIndex}, err
40+
}
41+
err = distribution.RegisterManifestSchema(ocispec.MediaTypeImageIndex, manifestListFunc)
42+
if err != nil {
43+
panic(fmt.Sprintf("Unable to register manifest: %s", err))
44+
}
45+
}

distribution/registry.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ import (
1717
"github.com/docker/docker/dockerversion"
1818
"github.com/docker/docker/registry"
1919
"github.com/docker/go-connections/sockets"
20+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2021
)
2122

2223
// ImageTypes represents the schema2 config types for images
2324
var ImageTypes = []string{
2425
schema2.MediaTypeImageConfig,
26+
ocispec.MediaTypeImageConfig,
2527
// Handle unexpected values from https://github.com/docker/distribution/issues/1621
2628
// (see also https://github.com/docker/docker/issues/22378,
2729
// https://github.com/docker/docker/issues/30083)

0 commit comments

Comments
 (0)