OCI media types; annotation support; oci index

Signed-off-by: Mike Brown <brownwm@us.ibm.com>
This commit is contained in:
Mike Brown
2017-07-11 14:19:47 -05:00
parent 6fcea22b0a
commit c94f28805e
11 changed files with 102 additions and 90 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/docker/distribution/manifest/schema1"
"github.com/docker/distribution/manifest/schema2"
"github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go/v1"
)
// A ManifestHandler gets and puts manifests of a particular type.
@@ -101,9 +102,9 @@ func (ms *manifestStore) Get(ctx context.Context, dgst digest.Digest, options ..
switch versioned.MediaType {
case schema2.MediaTypeManifest:
return ms.schema2Handler.Unmarshal(ctx, dgst, content)
case ocischema.MediaTypeManifest:
case v1.MediaTypeImageManifest:
return ms.ocischemaHandler.Unmarshal(ctx, dgst, content)
case manifestlist.MediaTypeManifestList, manifestlist.MediaTypeOCIManifestList:
case manifestlist.MediaTypeManifestList, v1.MediaTypeImageIndex:
return ms.manifestListHandler.Unmarshal(ctx, dgst, content)
default:
return nil, distribution.ErrManifestVerification{fmt.Errorf("unrecognized manifest content type %s", versioned.MediaType)}

View File

@@ -9,6 +9,7 @@ import (
"github.com/docker/distribution/context"
"github.com/docker/distribution/manifest/ocischema"
"github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go/v1"
)
//ocischemaManifestHandler is a ManifestHandler that covers ocischema manifests.
@@ -79,7 +80,8 @@ func (ms *ocischemaManifestHandler) verifyManifest(ctx context.Context, mnfst oc
var err error
switch descriptor.MediaType {
case ocischema.MediaTypeForeignLayer:
// TODO: mikebrow/steveoe verify we should treat oci nondistributable like foreign layers?
case v1.MediaTypeImageLayerNonDistributable, v1.MediaTypeImageLayerNonDistributableGzip:
// Clients download this layer from an external URL, so do not check for
// its presense.
if len(descriptor.URLs) == 0 {
@@ -95,7 +97,7 @@ func (ms *ocischemaManifestHandler) verifyManifest(ctx context.Context, mnfst oc
break
}
}
case ocischema.MediaTypeManifest:
case v1.MediaTypeImageManifest:
var exists bool
exists, err = manifestService.Exists(ctx, descriptor.Digest)
if err != nil || !exists {

View File

@@ -9,9 +9,10 @@ import (
"github.com/docker/distribution/manifest"
"github.com/docker/distribution/manifest/ocischema"
"github.com/docker/distribution/registry/storage/driver/inmemory"
"github.com/opencontainers/image-spec/specs-go/v1"
)
func TestVerifyOCIManifestForeignLayer(t *testing.T) {
func TestVerifyOCIManifestNonDistributableLayer(t *testing.T) {
ctx := context.Background()
inmemoryDriver := inmemory.New()
registry := createRegistry(t, inmemoryDriver,
@@ -20,26 +21,26 @@ func TestVerifyOCIManifestForeignLayer(t *testing.T) {
repo := makeRepository(t, registry, "test")
manifestService := makeManifestService(t, repo)
config, err := repo.Blobs(ctx).Put(ctx, ocischema.MediaTypeConfig, nil)
config, err := repo.Blobs(ctx).Put(ctx, v1.MediaTypeImageConfig, nil)
if err != nil {
t.Fatal(err)
}
layer, err := repo.Blobs(ctx).Put(ctx, ocischema.MediaTypeLayer, nil)
layer, err := repo.Blobs(ctx).Put(ctx, v1.MediaTypeImageLayerGzip, nil)
if err != nil {
t.Fatal(err)
}
foreignLayer := distribution.Descriptor{
nonDistributableLayer := distribution.Descriptor{
Digest: "sha256:463435349086340864309863409683460843608348608934092322395278926a",
Size: 6323,
MediaType: ocischema.MediaTypeForeignLayer,
MediaType: v1.MediaTypeImageLayerNonDistributableGzip,
}
template := ocischema.Manifest{
Versioned: manifest.Versioned{
SchemaVersion: 2,
MediaType: ocischema.MediaTypeManifest,
MediaType: v1.MediaTypeImageManifest,
},
Config: config,
}
@@ -52,58 +53,58 @@ func TestVerifyOCIManifestForeignLayer(t *testing.T) {
cases := []testcase{
{
foreignLayer,
nonDistributableLayer,
nil,
errMissingURL,
},
{
// regular layers may have foreign urls
// regular layers may have foreign urls (non-Distributable Layers)
layer,
[]string{"http://foo/bar"},
nil,
},
{
foreignLayer,
nonDistributableLayer,
[]string{"file:///local/file"},
errInvalidURL,
},
{
foreignLayer,
nonDistributableLayer,
[]string{"http://foo/bar#baz"},
errInvalidURL,
},
{
foreignLayer,
nonDistributableLayer,
[]string{""},
errInvalidURL,
},
{
foreignLayer,
nonDistributableLayer,
[]string{"https://foo/bar", ""},
errInvalidURL,
},
{
foreignLayer,
nonDistributableLayer,
[]string{"", "https://foo/bar"},
errInvalidURL,
},
{
foreignLayer,
nonDistributableLayer,
[]string{"http://nope/bar"},
errInvalidURL,
},
{
foreignLayer,
nonDistributableLayer,
[]string{"http://foo/nope"},
errInvalidURL,
},
{
foreignLayer,
nonDistributableLayer,
[]string{"http://foo/bar"},
nil,
},
{
foreignLayer,
nonDistributableLayer,
[]string{"https://foo/bar"},
nil,
},