Move manifest package to schema1
As we begin our march towards multi-arch, we must prepare for the reality of multiple manifest schemas. This is the beginning of a set of changes to facilitate this. We are both moving this package into its target position where it may live peacefully next to other manfiest versions. Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
f639a1af8c
commit
bb098c72a2
9 changed files with 60 additions and 56 deletions
|
@ -14,7 +14,7 @@ import (
|
||||||
"github.com/docker/distribution"
|
"github.com/docker/distribution"
|
||||||
"github.com/docker/distribution/context"
|
"github.com/docker/distribution/context"
|
||||||
"github.com/docker/distribution/digest"
|
"github.com/docker/distribution/digest"
|
||||||
"github.com/docker/distribution/manifest"
|
"github.com/docker/distribution/manifest/schema1"
|
||||||
"github.com/docker/distribution/registry/api/v2"
|
"github.com/docker/distribution/registry/api/v2"
|
||||||
"github.com/docker/distribution/registry/client/transport"
|
"github.com/docker/distribution/registry/client/transport"
|
||||||
"github.com/docker/distribution/registry/storage/cache"
|
"github.com/docker/distribution/registry/storage/cache"
|
||||||
|
@ -242,7 +242,7 @@ func (ms *manifests) ExistsByTag(tag string) (bool, error) {
|
||||||
return false, handleErrorResponse(resp)
|
return false, handleErrorResponse(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ms *manifests) Get(dgst digest.Digest) (*manifest.SignedManifest, error) {
|
func (ms *manifests) Get(dgst digest.Digest) (*schema1.SignedManifest, error) {
|
||||||
// Call by Tag endpoint since the API uses the same
|
// Call by Tag endpoint since the API uses the same
|
||||||
// URL endpoint for tags and digests.
|
// URL endpoint for tags and digests.
|
||||||
return ms.GetByTag(dgst.String())
|
return ms.GetByTag(dgst.String())
|
||||||
|
@ -262,7 +262,7 @@ func AddEtagToTag(tag, etag string) distribution.ManifestServiceOption {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ms *manifests) GetByTag(tag string, options ...distribution.ManifestServiceOption) (*manifest.SignedManifest, error) {
|
func (ms *manifests) GetByTag(tag string, options ...distribution.ManifestServiceOption) (*schema1.SignedManifest, error) {
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
err := option(ms)
|
err := option(ms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -290,7 +290,7 @@ func (ms *manifests) GetByTag(tag string, options ...distribution.ManifestServic
|
||||||
if resp.StatusCode == http.StatusNotModified {
|
if resp.StatusCode == http.StatusNotModified {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
} else if SuccessStatus(resp.StatusCode) {
|
} else if SuccessStatus(resp.StatusCode) {
|
||||||
var sm manifest.SignedManifest
|
var sm schema1.SignedManifest
|
||||||
decoder := json.NewDecoder(resp.Body)
|
decoder := json.NewDecoder(resp.Body)
|
||||||
|
|
||||||
if err := decoder.Decode(&sm); err != nil {
|
if err := decoder.Decode(&sm); err != nil {
|
||||||
|
@ -301,7 +301,7 @@ func (ms *manifests) GetByTag(tag string, options ...distribution.ManifestServic
|
||||||
return nil, handleErrorResponse(resp)
|
return nil, handleErrorResponse(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ms *manifests) Put(m *manifest.SignedManifest) error {
|
func (ms *manifests) Put(m *schema1.SignedManifest) error {
|
||||||
manifestURL, err := ms.ub.BuildManifestURL(ms.name, m.Tag)
|
manifestURL, err := ms.ub.BuildManifestURL(ms.name, m.Tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"github.com/docker/distribution/context"
|
"github.com/docker/distribution/context"
|
||||||
"github.com/docker/distribution/digest"
|
"github.com/docker/distribution/digest"
|
||||||
"github.com/docker/distribution/manifest"
|
"github.com/docker/distribution/manifest"
|
||||||
|
"github.com/docker/distribution/manifest/schema1"
|
||||||
"github.com/docker/distribution/registry/api/errcode"
|
"github.com/docker/distribution/registry/api/errcode"
|
||||||
"github.com/docker/distribution/testutil"
|
"github.com/docker/distribution/testutil"
|
||||||
)
|
)
|
||||||
|
@ -419,19 +420,19 @@ func TestBlobUploadMonolithic(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRandomSchemaV1Manifest(name, tag string, blobCount int) (*manifest.SignedManifest, digest.Digest) {
|
func newRandomSchemaV1Manifest(name, tag string, blobCount int) (*schema1.SignedManifest, digest.Digest) {
|
||||||
blobs := make([]manifest.FSLayer, blobCount)
|
blobs := make([]schema1.FSLayer, blobCount)
|
||||||
history := make([]manifest.History, blobCount)
|
history := make([]schema1.History, blobCount)
|
||||||
|
|
||||||
for i := 0; i < blobCount; i++ {
|
for i := 0; i < blobCount; i++ {
|
||||||
dgst, blob := newRandomBlob((i % 5) * 16)
|
dgst, blob := newRandomBlob((i % 5) * 16)
|
||||||
|
|
||||||
blobs[i] = manifest.FSLayer{BlobSum: dgst}
|
blobs[i] = schema1.FSLayer{BlobSum: dgst}
|
||||||
history[i] = manifest.History{V1Compatibility: fmt.Sprintf("{\"Hex\": \"%x\"}", blob)}
|
history[i] = schema1.History{V1Compatibility: fmt.Sprintf("{\"Hex\": \"%x\"}", blob)}
|
||||||
}
|
}
|
||||||
|
|
||||||
m := &manifest.SignedManifest{
|
m := &schema1.SignedManifest{
|
||||||
Manifest: manifest.Manifest{
|
Manifest: schema1.Manifest{
|
||||||
Name: name,
|
Name: name,
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
Architecture: "x86",
|
Architecture: "x86",
|
||||||
|
@ -521,7 +522,7 @@ func addTestManifest(repo, reference string, content []byte, m *testutil.Request
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkEqualManifest(m1, m2 *manifest.SignedManifest) error {
|
func checkEqualManifest(m1, m2 *schema1.SignedManifest) error {
|
||||||
if m1.Name != m2.Name {
|
if m1.Name != m2.Name {
|
||||||
return fmt.Errorf("name does not match %q != %q", m1.Name, m2.Name)
|
return fmt.Errorf("name does not match %q != %q", m1.Name, m2.Name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/docker/distribution/context"
|
"github.com/docker/distribution/context"
|
||||||
"github.com/docker/distribution/digest"
|
"github.com/docker/distribution/digest"
|
||||||
"github.com/docker/distribution/manifest"
|
"github.com/docker/distribution/manifest"
|
||||||
|
"github.com/docker/distribution/manifest/schema1"
|
||||||
"github.com/docker/distribution/registry/api/errcode"
|
"github.com/docker/distribution/registry/api/errcode"
|
||||||
"github.com/docker/distribution/registry/api/v2"
|
"github.com/docker/distribution/registry/api/v2"
|
||||||
_ "github.com/docker/distribution/registry/storage/driver/inmemory"
|
_ "github.com/docker/distribution/registry/storage/driver/inmemory"
|
||||||
|
@ -648,7 +649,7 @@ func httpDelete(url string) (*http.Response, error) {
|
||||||
|
|
||||||
type manifestArgs struct {
|
type manifestArgs struct {
|
||||||
imageName string
|
imageName string
|
||||||
signedManifest *manifest.SignedManifest
|
signedManifest *schema1.SignedManifest
|
||||||
dgst digest.Digest
|
dgst digest.Digest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -741,13 +742,13 @@ func testManifestAPI(t *testing.T, env *testEnv, args manifestArgs) (*testEnv, m
|
||||||
|
|
||||||
// --------------------------------
|
// --------------------------------
|
||||||
// Attempt to push unsigned manifest with missing layers
|
// Attempt to push unsigned manifest with missing layers
|
||||||
unsignedManifest := &manifest.Manifest{
|
unsignedManifest := &schema1.Manifest{
|
||||||
Versioned: manifest.Versioned{
|
Versioned: manifest.Versioned{
|
||||||
SchemaVersion: 1,
|
SchemaVersion: 1,
|
||||||
},
|
},
|
||||||
Name: imageName,
|
Name: imageName,
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
FSLayers: []manifest.FSLayer{
|
FSLayers: []schema1.FSLayer{
|
||||||
{
|
{
|
||||||
BlobSum: "asdf",
|
BlobSum: "asdf",
|
||||||
},
|
},
|
||||||
|
@ -797,7 +798,7 @@ func testManifestAPI(t *testing.T, env *testEnv, args manifestArgs) (*testEnv, m
|
||||||
|
|
||||||
// -------------------
|
// -------------------
|
||||||
// Push the signed manifest with all layers pushed.
|
// Push the signed manifest with all layers pushed.
|
||||||
signedManifest, err := manifest.Sign(unsignedManifest, env.pk)
|
signedManifest, err := schema1.Sign(unsignedManifest, env.pk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error signing manifest: %v", err)
|
t.Fatalf("unexpected error signing manifest: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -844,7 +845,7 @@ func testManifestAPI(t *testing.T, env *testEnv, args manifestArgs) (*testEnv, m
|
||||||
"ETag": []string{fmt.Sprintf(`"%s"`, dgst)},
|
"ETag": []string{fmt.Sprintf(`"%s"`, dgst)},
|
||||||
})
|
})
|
||||||
|
|
||||||
var fetchedManifest manifest.SignedManifest
|
var fetchedManifest schema1.SignedManifest
|
||||||
dec := json.NewDecoder(resp.Body)
|
dec := json.NewDecoder(resp.Body)
|
||||||
if err := dec.Decode(&fetchedManifest); err != nil {
|
if err := dec.Decode(&fetchedManifest); err != nil {
|
||||||
t.Fatalf("error decoding fetched manifest: %v", err)
|
t.Fatalf("error decoding fetched manifest: %v", err)
|
||||||
|
@ -866,7 +867,7 @@ func testManifestAPI(t *testing.T, env *testEnv, args manifestArgs) (*testEnv, m
|
||||||
"ETag": []string{fmt.Sprintf(`"%s"`, dgst)},
|
"ETag": []string{fmt.Sprintf(`"%s"`, dgst)},
|
||||||
})
|
})
|
||||||
|
|
||||||
var fetchedManifestByDigest manifest.SignedManifest
|
var fetchedManifestByDigest schema1.SignedManifest
|
||||||
dec = json.NewDecoder(resp.Body)
|
dec = json.NewDecoder(resp.Body)
|
||||||
if err := dec.Decode(&fetchedManifestByDigest); err != nil {
|
if err := dec.Decode(&fetchedManifestByDigest); err != nil {
|
||||||
t.Fatalf("error decoding fetched manifest: %v", err)
|
t.Fatalf("error decoding fetched manifest: %v", err)
|
||||||
|
@ -1062,7 +1063,7 @@ func newTestEnvWithConfig(t *testing.T, config *configuration.Configuration) *te
|
||||||
|
|
||||||
func putManifest(t *testing.T, msg, url string, v interface{}) *http.Response {
|
func putManifest(t *testing.T, msg, url string, v interface{}) *http.Response {
|
||||||
var body []byte
|
var body []byte
|
||||||
if sm, ok := v.(*manifest.SignedManifest); ok {
|
if sm, ok := v.(*schema1.SignedManifest); ok {
|
||||||
body = sm.Raw
|
body = sm.Raw
|
||||||
} else {
|
} else {
|
||||||
var err error
|
var err error
|
||||||
|
@ -1355,13 +1356,13 @@ func checkErr(t *testing.T, err error, msg string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createRepository(env *testEnv, t *testing.T, imageName string, tag string) {
|
func createRepository(env *testEnv, t *testing.T, imageName string, tag string) {
|
||||||
unsignedManifest := &manifest.Manifest{
|
unsignedManifest := &schema1.Manifest{
|
||||||
Versioned: manifest.Versioned{
|
Versioned: manifest.Versioned{
|
||||||
SchemaVersion: 1,
|
SchemaVersion: 1,
|
||||||
},
|
},
|
||||||
Name: imageName,
|
Name: imageName,
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
FSLayers: []manifest.FSLayer{
|
FSLayers: []schema1.FSLayer{
|
||||||
{
|
{
|
||||||
BlobSum: "asdf",
|
BlobSum: "asdf",
|
||||||
},
|
},
|
||||||
|
@ -1389,7 +1390,7 @@ func createRepository(env *testEnv, t *testing.T, imageName string, tag string)
|
||||||
pushLayer(t, env.builder, imageName, dgst, uploadURLBase, rs)
|
pushLayer(t, env.builder, imageName, dgst, uploadURLBase, rs)
|
||||||
}
|
}
|
||||||
|
|
||||||
signedManifest, err := manifest.Sign(unsignedManifest, env.pk)
|
signedManifest, err := schema1.Sign(unsignedManifest, env.pk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error signing manifest: %v", err)
|
t.Fatalf("unexpected error signing manifest: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -1425,13 +1426,13 @@ func TestRegistryAsCacheMutationAPIs(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manifest upload
|
// Manifest upload
|
||||||
unsignedManifest := &manifest.Manifest{
|
unsignedManifest := &schema1.Manifest{
|
||||||
Versioned: manifest.Versioned{
|
Versioned: manifest.Versioned{
|
||||||
SchemaVersion: 1,
|
SchemaVersion: 1,
|
||||||
},
|
},
|
||||||
Name: imageName,
|
Name: imageName,
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
FSLayers: []manifest.FSLayer{},
|
FSLayers: []schema1.FSLayer{},
|
||||||
}
|
}
|
||||||
resp := putManifest(t, "putting unsigned manifest", manifestURL, unsignedManifest)
|
resp := putManifest(t, "putting unsigned manifest", manifestURL, unsignedManifest)
|
||||||
checkResponse(t, "putting signed manifest to cache", resp, errcode.ErrorCodeUnsupported.Descriptor().HTTPStatusCode)
|
checkResponse(t, "putting signed manifest to cache", resp, errcode.ErrorCodeUnsupported.Descriptor().HTTPStatusCode)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/docker/distribution"
|
"github.com/docker/distribution"
|
||||||
ctxu "github.com/docker/distribution/context"
|
ctxu "github.com/docker/distribution/context"
|
||||||
"github.com/docker/distribution/digest"
|
"github.com/docker/distribution/digest"
|
||||||
"github.com/docker/distribution/manifest"
|
"github.com/docker/distribution/manifest/schema1"
|
||||||
"github.com/docker/distribution/registry/api/errcode"
|
"github.com/docker/distribution/registry/api/errcode"
|
||||||
"github.com/docker/distribution/registry/api/v2"
|
"github.com/docker/distribution/registry/api/v2"
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
|
@ -57,7 +57,7 @@ func (imh *imageManifestHandler) GetImageManifest(w http.ResponseWriter, r *http
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var sm *manifest.SignedManifest
|
var sm *schema1.SignedManifest
|
||||||
if imh.Tag != "" {
|
if imh.Tag != "" {
|
||||||
sm, err = manifests.GetByTag(imh.Tag)
|
sm, err = manifests.GetByTag(imh.Tag)
|
||||||
} else {
|
} else {
|
||||||
|
@ -119,7 +119,7 @@ func (imh *imageManifestHandler) PutImageManifest(w http.ResponseWriter, r *http
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var manifest manifest.SignedManifest
|
var manifest schema1.SignedManifest
|
||||||
if err := json.Unmarshal(jsonBuf.Bytes(), &manifest); err != nil {
|
if err := json.Unmarshal(jsonBuf.Bytes(), &manifest); err != nil {
|
||||||
imh.Errors = append(imh.Errors, v2.ErrorCodeManifestInvalid.WithDetail(err))
|
imh.Errors = append(imh.Errors, v2.ErrorCodeManifestInvalid.WithDetail(err))
|
||||||
return
|
return
|
||||||
|
@ -229,7 +229,7 @@ func (imh *imageManifestHandler) DeleteImageManifest(w http.ResponseWriter, r *h
|
||||||
|
|
||||||
// digestManifest takes a digest of the given manifest. This belongs somewhere
|
// digestManifest takes a digest of the given manifest. This belongs somewhere
|
||||||
// better but we'll wait for a refactoring cycle to find that real somewhere.
|
// better but we'll wait for a refactoring cycle to find that real somewhere.
|
||||||
func digestManifest(ctx context.Context, sm *manifest.SignedManifest) (digest.Digest, error) {
|
func digestManifest(ctx context.Context, sm *schema1.SignedManifest) (digest.Digest, error) {
|
||||||
p, err := sm.Payload()
|
p, err := sm.Payload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !strings.Contains(err.Error(), "missing signature key") {
|
if !strings.Contains(err.Error(), "missing signature key") {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/docker/distribution"
|
"github.com/docker/distribution"
|
||||||
"github.com/docker/distribution/context"
|
"github.com/docker/distribution/context"
|
||||||
"github.com/docker/distribution/digest"
|
"github.com/docker/distribution/digest"
|
||||||
"github.com/docker/distribution/manifest"
|
"github.com/docker/distribution/manifest/schema1"
|
||||||
"github.com/docker/distribution/registry/client"
|
"github.com/docker/distribution/registry/client"
|
||||||
"github.com/docker/distribution/registry/proxy/scheduler"
|
"github.com/docker/distribution/registry/proxy/scheduler"
|
||||||
)
|
)
|
||||||
|
@ -36,7 +36,7 @@ func (pms proxyManifestStore) Exists(dgst digest.Digest) (bool, error) {
|
||||||
return pms.remoteManifests.Exists(dgst)
|
return pms.remoteManifests.Exists(dgst)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pms proxyManifestStore) Get(dgst digest.Digest) (*manifest.SignedManifest, error) {
|
func (pms proxyManifestStore) Get(dgst digest.Digest) (*schema1.SignedManifest, error) {
|
||||||
sm, err := pms.localManifests.Get(dgst)
|
sm, err := pms.localManifests.Get(dgst)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
proxyMetrics.ManifestPush(uint64(len(sm.Raw)))
|
proxyMetrics.ManifestPush(uint64(len(sm.Raw)))
|
||||||
|
@ -81,7 +81,7 @@ func (pms proxyManifestStore) ExistsByTag(tag string) (bool, error) {
|
||||||
return pms.remoteManifests.ExistsByTag(tag)
|
return pms.remoteManifests.ExistsByTag(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pms proxyManifestStore) GetByTag(tag string, options ...distribution.ManifestServiceOption) (*manifest.SignedManifest, error) {
|
func (pms proxyManifestStore) GetByTag(tag string, options ...distribution.ManifestServiceOption) (*schema1.SignedManifest, error) {
|
||||||
var localDigest digest.Digest
|
var localDigest digest.Digest
|
||||||
|
|
||||||
localManifest, err := pms.localManifests.GetByTag(tag, options...)
|
localManifest, err := pms.localManifests.GetByTag(tag, options...)
|
||||||
|
@ -100,7 +100,7 @@ func (pms proxyManifestStore) GetByTag(tag string, options ...distribution.Manif
|
||||||
}
|
}
|
||||||
|
|
||||||
fromremote:
|
fromremote:
|
||||||
var sm *manifest.SignedManifest
|
var sm *schema1.SignedManifest
|
||||||
sm, err = pms.remoteManifests.GetByTag(tag, client.AddEtagToTag(tag, localDigest.String()))
|
sm, err = pms.remoteManifests.GetByTag(tag, client.AddEtagToTag(tag, localDigest.String()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -130,7 +130,7 @@ fromremote:
|
||||||
return sm, err
|
return sm, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func manifestDigest(sm *manifest.SignedManifest) (digest.Digest, error) {
|
func manifestDigest(sm *schema1.SignedManifest) (digest.Digest, error) {
|
||||||
payload, err := sm.Payload()
|
payload, err := sm.Payload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -145,7 +145,7 @@ func manifestDigest(sm *manifest.SignedManifest) (digest.Digest, error) {
|
||||||
return dgst, nil
|
return dgst, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pms proxyManifestStore) Put(manifest *manifest.SignedManifest) error {
|
func (pms proxyManifestStore) Put(manifest *schema1.SignedManifest) error {
|
||||||
return distribution.ErrUnsupported
|
return distribution.ErrUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/docker/distribution/context"
|
"github.com/docker/distribution/context"
|
||||||
"github.com/docker/distribution/digest"
|
"github.com/docker/distribution/digest"
|
||||||
"github.com/docker/distribution/manifest"
|
"github.com/docker/distribution/manifest"
|
||||||
|
"github.com/docker/distribution/manifest/schema1"
|
||||||
"github.com/docker/distribution/registry/proxy/scheduler"
|
"github.com/docker/distribution/registry/proxy/scheduler"
|
||||||
"github.com/docker/distribution/registry/storage"
|
"github.com/docker/distribution/registry/storage"
|
||||||
"github.com/docker/distribution/registry/storage/cache/memory"
|
"github.com/docker/distribution/registry/storage/cache/memory"
|
||||||
|
@ -51,17 +52,17 @@ func (sm statsManifest) ExistsByTag(tag string) (bool, error) {
|
||||||
return sm.manifests.ExistsByTag(tag)
|
return sm.manifests.ExistsByTag(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm statsManifest) Get(dgst digest.Digest) (*manifest.SignedManifest, error) {
|
func (sm statsManifest) Get(dgst digest.Digest) (*schema1.SignedManifest, error) {
|
||||||
sm.stats["get"]++
|
sm.stats["get"]++
|
||||||
return sm.manifests.Get(dgst)
|
return sm.manifests.Get(dgst)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm statsManifest) GetByTag(tag string, options ...distribution.ManifestServiceOption) (*manifest.SignedManifest, error) {
|
func (sm statsManifest) GetByTag(tag string, options ...distribution.ManifestServiceOption) (*schema1.SignedManifest, error) {
|
||||||
sm.stats["getbytag"]++
|
sm.stats["getbytag"]++
|
||||||
return sm.manifests.GetByTag(tag, options...)
|
return sm.manifests.GetByTag(tag, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm statsManifest) Put(manifest *manifest.SignedManifest) error {
|
func (sm statsManifest) Put(manifest *schema1.SignedManifest) error {
|
||||||
sm.stats["put"]++
|
sm.stats["put"]++
|
||||||
return sm.manifests.Put(manifest)
|
return sm.manifests.Put(manifest)
|
||||||
}
|
}
|
||||||
|
@ -126,7 +127,7 @@ func newManifestStoreTestEnv(t *testing.T, name, tag string) *manifestStoreTestE
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateRepo(t *testing.T, ctx context.Context, repository distribution.Repository, name, tag string) (digest.Digest, error) {
|
func populateRepo(t *testing.T, ctx context.Context, repository distribution.Repository, name, tag string) (digest.Digest, error) {
|
||||||
m := manifest.Manifest{
|
m := schema1.Manifest{
|
||||||
Versioned: manifest.Versioned{
|
Versioned: manifest.Versioned{
|
||||||
SchemaVersion: 1,
|
SchemaVersion: 1,
|
||||||
},
|
},
|
||||||
|
@ -159,7 +160,7 @@ func populateRepo(t *testing.T, ctx context.Context, repository distribution.Rep
|
||||||
t.Fatalf("unexpected error generating private key: %v", err)
|
t.Fatalf("unexpected error generating private key: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sm, err := manifest.Sign(&m, pk)
|
sm, err := schema1.Sign(&m, pk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error signing manifest: %v", err)
|
t.Fatalf("error signing manifest: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/docker/distribution"
|
"github.com/docker/distribution"
|
||||||
"github.com/docker/distribution/context"
|
"github.com/docker/distribution/context"
|
||||||
"github.com/docker/distribution/digest"
|
"github.com/docker/distribution/digest"
|
||||||
"github.com/docker/distribution/manifest"
|
"github.com/docker/distribution/manifest/schema1"
|
||||||
"github.com/docker/libtrust"
|
"github.com/docker/libtrust"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ func (ms *manifestStore) Exists(dgst digest.Digest) (bool, error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ms *manifestStore) Get(dgst digest.Digest) (*manifest.SignedManifest, error) {
|
func (ms *manifestStore) Get(dgst digest.Digest) (*schema1.SignedManifest, error) {
|
||||||
context.GetLogger(ms.ctx).Debug("(*manifestStore).Get")
|
context.GetLogger(ms.ctx).Debug("(*manifestStore).Get")
|
||||||
return ms.revisionStore.get(ms.ctx, dgst)
|
return ms.revisionStore.get(ms.ctx, dgst)
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ func SkipLayerVerification(ms distribution.ManifestService) error {
|
||||||
return fmt.Errorf("skip layer verification only valid for manifeststore")
|
return fmt.Errorf("skip layer verification only valid for manifeststore")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ms *manifestStore) Put(manifest *manifest.SignedManifest) error {
|
func (ms *manifestStore) Put(manifest *schema1.SignedManifest) error {
|
||||||
context.GetLogger(ms.ctx).Debug("(*manifestStore).Put")
|
context.GetLogger(ms.ctx).Debug("(*manifestStore).Put")
|
||||||
|
|
||||||
if err := ms.verifyManifest(ms.ctx, manifest); err != nil {
|
if err := ms.verifyManifest(ms.ctx, manifest); err != nil {
|
||||||
|
@ -83,7 +83,7 @@ func (ms *manifestStore) ExistsByTag(tag string) (bool, error) {
|
||||||
return ms.tagStore.exists(tag)
|
return ms.tagStore.exists(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ms *manifestStore) GetByTag(tag string, options ...distribution.ManifestServiceOption) (*manifest.SignedManifest, error) {
|
func (ms *manifestStore) GetByTag(tag string, options ...distribution.ManifestServiceOption) (*schema1.SignedManifest, error) {
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
err := option(ms)
|
err := option(ms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -104,13 +104,13 @@ func (ms *manifestStore) GetByTag(tag string, options ...distribution.ManifestSe
|
||||||
// perspective of the registry. It ensures that the signature is valid for the
|
// perspective of the registry. It ensures that the signature is valid for the
|
||||||
// enclosed payload. As a policy, the registry only tries to store valid
|
// enclosed payload. As a policy, the registry only tries to store valid
|
||||||
// content, leaving trust policies of that content up to consumers.
|
// content, leaving trust policies of that content up to consumers.
|
||||||
func (ms *manifestStore) verifyManifest(ctx context.Context, mnfst *manifest.SignedManifest) error {
|
func (ms *manifestStore) verifyManifest(ctx context.Context, mnfst *schema1.SignedManifest) error {
|
||||||
var errs distribution.ErrManifestVerification
|
var errs distribution.ErrManifestVerification
|
||||||
if mnfst.Name != ms.repository.Name() {
|
if mnfst.Name != ms.repository.Name() {
|
||||||
errs = append(errs, fmt.Errorf("repository name does not match manifest name"))
|
errs = append(errs, fmt.Errorf("repository name does not match manifest name"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := manifest.Verify(mnfst); err != nil {
|
if _, err := schema1.Verify(mnfst); err != nil {
|
||||||
switch err {
|
switch err {
|
||||||
case libtrust.ErrMissingSignatureKey, libtrust.ErrInvalidJSONContent, libtrust.ErrMissingSignatureKey:
|
case libtrust.ErrMissingSignatureKey, libtrust.ErrInvalidJSONContent, libtrust.ErrMissingSignatureKey:
|
||||||
errs = append(errs, distribution.ErrManifestUnverified{})
|
errs = append(errs, distribution.ErrManifestUnverified{})
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/docker/distribution/context"
|
"github.com/docker/distribution/context"
|
||||||
"github.com/docker/distribution/digest"
|
"github.com/docker/distribution/digest"
|
||||||
"github.com/docker/distribution/manifest"
|
"github.com/docker/distribution/manifest"
|
||||||
|
"github.com/docker/distribution/manifest/schema1"
|
||||||
"github.com/docker/distribution/registry/storage/cache/memory"
|
"github.com/docker/distribution/registry/storage/cache/memory"
|
||||||
"github.com/docker/distribution/registry/storage/driver"
|
"github.com/docker/distribution/registry/storage/driver"
|
||||||
"github.com/docker/distribution/registry/storage/driver/inmemory"
|
"github.com/docker/distribution/registry/storage/driver/inmemory"
|
||||||
|
@ -75,7 +76,7 @@ func TestManifestStorage(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m := manifest.Manifest{
|
m := schema1.Manifest{
|
||||||
Versioned: manifest.Versioned{
|
Versioned: manifest.Versioned{
|
||||||
SchemaVersion: 1,
|
SchemaVersion: 1,
|
||||||
},
|
},
|
||||||
|
@ -94,7 +95,7 @@ func TestManifestStorage(t *testing.T) {
|
||||||
dgst := digest.Digest(ds)
|
dgst := digest.Digest(ds)
|
||||||
|
|
||||||
testLayers[digest.Digest(dgst)] = rs
|
testLayers[digest.Digest(dgst)] = rs
|
||||||
m.FSLayers = append(m.FSLayers, manifest.FSLayer{
|
m.FSLayers = append(m.FSLayers, schema1.FSLayer{
|
||||||
BlobSum: dgst,
|
BlobSum: dgst,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -104,7 +105,7 @@ func TestManifestStorage(t *testing.T) {
|
||||||
t.Fatalf("unexpected error generating private key: %v", err)
|
t.Fatalf("unexpected error generating private key: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sm, merr := manifest.Sign(&m, pk)
|
sm, merr := schema1.Sign(&m, pk)
|
||||||
if merr != nil {
|
if merr != nil {
|
||||||
t.Fatalf("error signing manifest: %v", err)
|
t.Fatalf("error signing manifest: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -232,7 +233,7 @@ func TestManifestStorage(t *testing.T) {
|
||||||
t.Fatalf("unexpected error generating private key: %v", err)
|
t.Fatalf("unexpected error generating private key: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sm2, err := manifest.Sign(&m, pk2)
|
sm2, err := schema1.Sign(&m, pk2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error signing manifest: %v", err)
|
t.Fatalf("unexpected error signing manifest: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -260,7 +261,7 @@ func TestManifestStorage(t *testing.T) {
|
||||||
t.Fatalf("unexpected error fetching manifest: %v", err)
|
t.Fatalf("unexpected error fetching manifest: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := manifest.Verify(fetched); err != nil {
|
if _, err := schema1.Verify(fetched); err != nil {
|
||||||
t.Fatalf("unexpected error verifying manifest: %v", err)
|
t.Fatalf("unexpected error verifying manifest: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/docker/distribution"
|
"github.com/docker/distribution"
|
||||||
"github.com/docker/distribution/context"
|
"github.com/docker/distribution/context"
|
||||||
"github.com/docker/distribution/digest"
|
"github.com/docker/distribution/digest"
|
||||||
"github.com/docker/distribution/manifest"
|
"github.com/docker/distribution/manifest/schema1"
|
||||||
"github.com/docker/libtrust"
|
"github.com/docker/libtrust"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ type revisionStore struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get retrieves the manifest, keyed by revision digest.
|
// get retrieves the manifest, keyed by revision digest.
|
||||||
func (rs *revisionStore) get(ctx context.Context, revision digest.Digest) (*manifest.SignedManifest, error) {
|
func (rs *revisionStore) get(ctx context.Context, revision digest.Digest) (*schema1.SignedManifest, error) {
|
||||||
// Ensure that this revision is available in this repository.
|
// Ensure that this revision is available in this repository.
|
||||||
_, err := rs.blobStore.Stat(ctx, revision)
|
_, err := rs.blobStore.Stat(ctx, revision)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -64,7 +64,7 @@ func (rs *revisionStore) get(ctx context.Context, revision digest.Digest) (*mani
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var sm manifest.SignedManifest
|
var sm schema1.SignedManifest
|
||||||
if err := json.Unmarshal(raw, &sm); err != nil {
|
if err := json.Unmarshal(raw, &sm); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ func (rs *revisionStore) get(ctx context.Context, revision digest.Digest) (*mani
|
||||||
|
|
||||||
// put stores the manifest in the repository, if not already present. Any
|
// put stores the manifest in the repository, if not already present. Any
|
||||||
// updated signatures will be stored, as well.
|
// updated signatures will be stored, as well.
|
||||||
func (rs *revisionStore) put(ctx context.Context, sm *manifest.SignedManifest) (distribution.Descriptor, error) {
|
func (rs *revisionStore) put(ctx context.Context, sm *schema1.SignedManifest) (distribution.Descriptor, error) {
|
||||||
// Resolve the payload in the manifest.
|
// Resolve the payload in the manifest.
|
||||||
payload, err := sm.Payload()
|
payload, err := sm.Payload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -82,7 +82,7 @@ func (rs *revisionStore) put(ctx context.Context, sm *manifest.SignedManifest) (
|
||||||
}
|
}
|
||||||
|
|
||||||
// Digest and store the manifest payload in the blob store.
|
// Digest and store the manifest payload in the blob store.
|
||||||
revision, err := rs.blobStore.Put(ctx, manifest.ManifestMediaType, payload)
|
revision, err := rs.blobStore.Put(ctx, schema1.ManifestMediaType, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
context.GetLogger(ctx).Errorf("error putting payload into blobstore: %v", err)
|
context.GetLogger(ctx).Errorf("error putting payload into blobstore: %v", err)
|
||||||
return distribution.Descriptor{}, err
|
return distribution.Descriptor{}, err
|
||||||
|
|
Loading…
Reference in a new issue