OCI types are backwards compatible with Docker manifest
types, however the media types must be registered.
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,45 @@ |
| 0 |
+package distribution |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "fmt" |
|
| 4 |
+ |
|
| 5 |
+ "github.com/docker/distribution" |
|
| 6 |
+ "github.com/docker/distribution/manifest/manifestlist" |
|
| 7 |
+ "github.com/docker/distribution/manifest/schema2" |
|
| 8 |
+ digest "github.com/opencontainers/go-digest" |
|
| 9 |
+ ocispec "github.com/opencontainers/image-spec/specs-go/v1" |
|
| 10 |
+) |
|
| 11 |
+ |
|
| 12 |
+func init() {
|
|
| 13 |
+ // TODO: Remove this registration if distribution is included with OCI support |
|
| 14 |
+ |
|
| 15 |
+ ocischemaFunc := func(b []byte) (distribution.Manifest, distribution.Descriptor, error) {
|
|
| 16 |
+ m := new(schema2.DeserializedManifest) |
|
| 17 |
+ err := m.UnmarshalJSON(b) |
|
| 18 |
+ if err != nil {
|
|
| 19 |
+ return nil, distribution.Descriptor{}, err
|
|
| 20 |
+ } |
|
| 21 |
+ |
|
| 22 |
+ dgst := digest.FromBytes(b) |
|
| 23 |
+ return m, distribution.Descriptor{Digest: dgst, Size: int64(len(b)), MediaType: ocispec.MediaTypeImageManifest}, err
|
|
| 24 |
+ } |
|
| 25 |
+ err := distribution.RegisterManifestSchema(ocispec.MediaTypeImageManifest, ocischemaFunc) |
|
| 26 |
+ if err != nil {
|
|
| 27 |
+ panic(fmt.Sprintf("Unable to register manifest: %s", err))
|
|
| 28 |
+ } |
|
| 29 |
+ |
|
| 30 |
+ manifestListFunc := func(b []byte) (distribution.Manifest, distribution.Descriptor, error) {
|
|
| 31 |
+ m := new(manifestlist.DeserializedManifestList) |
|
| 32 |
+ err := m.UnmarshalJSON(b) |
|
| 33 |
+ if err != nil {
|
|
| 34 |
+ return nil, distribution.Descriptor{}, err
|
|
| 35 |
+ } |
|
| 36 |
+ |
|
| 37 |
+ dgst := digest.FromBytes(b) |
|
| 38 |
+ return m, distribution.Descriptor{Digest: dgst, Size: int64(len(b)), MediaType: ocispec.MediaTypeImageIndex}, err
|
|
| 39 |
+ } |
|
| 40 |
+ err = distribution.RegisterManifestSchema(ocispec.MediaTypeImageIndex, manifestListFunc) |
|
| 41 |
+ if err != nil {
|
|
| 42 |
+ panic(fmt.Sprintf("Unable to register manifest: %s", err))
|
|
| 43 |
+ } |
|
| 44 |
+} |
| ... | ... |
@@ -17,11 +17,13 @@ import ( |
| 17 | 17 |
"github.com/docker/docker/dockerversion" |
| 18 | 18 |
"github.com/docker/docker/registry" |
| 19 | 19 |
"github.com/docker/go-connections/sockets" |
| 20 |
+ ocispec "github.com/opencontainers/image-spec/specs-go/v1" |
|
| 20 | 21 |
) |
| 21 | 22 |
|
| 22 | 23 |
// ImageTypes represents the schema2 config types for images |
| 23 | 24 |
var ImageTypes = []string{
|
| 24 | 25 |
schema2.MediaTypeImageConfig, |
| 26 |
+ ocispec.MediaTypeImageConfig, |
|
| 25 | 27 |
// Handle unexpected values from https://github.com/docker/distribution/issues/1621 |
| 26 | 28 |
// (see also https://github.com/docker/docker/issues/22378, |
| 27 | 29 |
// https://github.com/docker/docker/issues/30083) |