|
| 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 | +} |
0 commit comments