This repository has been archived by the owner on Oct 13, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from thaJeztah/18.06-backport-register-oci-medi…
…atypes [18.06] Register OCI image media types Upstream-commit: 85b4dbd3db3761dc3e21f3361cf840eefc1e9fb3 Component: engine
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package distribution | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/docker/distribution" | ||
"github.com/docker/distribution/manifest/manifestlist" | ||
"github.com/docker/distribution/manifest/schema2" | ||
digest "github.com/opencontainers/go-digest" | ||
ocispec "github.com/opencontainers/image-spec/specs-go/v1" | ||
) | ||
|
||
func init() { | ||
// TODO: Remove this registration if distribution is included with OCI support | ||
|
||
ocischemaFunc := func(b []byte) (distribution.Manifest, distribution.Descriptor, error) { | ||
m := new(schema2.DeserializedManifest) | ||
err := m.UnmarshalJSON(b) | ||
if err != nil { | ||
return nil, distribution.Descriptor{}, err | ||
} | ||
|
||
dgst := digest.FromBytes(b) | ||
return m, distribution.Descriptor{Digest: dgst, Size: int64(len(b)), MediaType: ocispec.MediaTypeImageManifest}, err | ||
} | ||
err := distribution.RegisterManifestSchema(ocispec.MediaTypeImageManifest, ocischemaFunc) | ||
if err != nil { | ||
panic(fmt.Sprintf("Unable to register manifest: %s", err)) | ||
} | ||
|
||
manifestListFunc := func(b []byte) (distribution.Manifest, distribution.Descriptor, error) { | ||
m := new(manifestlist.DeserializedManifestList) | ||
err := m.UnmarshalJSON(b) | ||
if err != nil { | ||
return nil, distribution.Descriptor{}, err | ||
} | ||
|
||
dgst := digest.FromBytes(b) | ||
return m, distribution.Descriptor{Digest: dgst, Size: int64(len(b)), MediaType: ocispec.MediaTypeImageIndex}, err | ||
} | ||
err = distribution.RegisterManifestSchema(ocispec.MediaTypeImageIndex, manifestListFunc) | ||
if err != nil { | ||
panic(fmt.Sprintf("Unable to register manifest: %s", err)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters