cb6f002350
Add a generic Manifest interface to represent manifests in the registry and remove references to schema specific manifests. Add a ManifestBuilder to construct Manifest objects. Concrete manifest builders will exist for each manifest type and implementations will contain manifest specific data used to build a manifest. Remove Signatures() from Repository interface. Signatures are relevant only to schema1 manifests. Move access to the signature store inside the schema1 manifestStore. Add some API tests to verify signature roundtripping. schema1 ------- Change the way data is stored in schema1.Manifest to enable Payload() to be used to return complete Manifest JSON from the HTTP handler without knowledge of the schema1 protocol. tags ---- Move tag functionality to a seperate TagService and update ManifestService to use the new interfaces. Implement a driver based tagService to be backward compatible with the current tag service. Add a proxyTagService to enable the registry to get a digest for remote manifests from a tag. manifest store -------------- Remove revision store and move all signing functionality into the signed manifeststore. manifest registration --------------------- Add a mechanism to register manifest media types and to allow different manifest types to be Unmarshalled correctly. client ------ Add ManifestServiceOptions to client functions to allow tags to be passed into Put and Get for building correct registry URLs. Change functional arguments to be an interface type to allow passing data without mutating shared state. Signed-off-by: Richard Scothern <richard.scothern@gmail.com> Signed-off-by: Richard Scothern <richard.scothern@docker.com>
159 lines
4.3 KiB
Go
159 lines
4.3 KiB
Go
package storage
|
|
|
|
import (
|
|
"path"
|
|
|
|
"github.com/docker/distribution"
|
|
"github.com/docker/distribution/context"
|
|
"github.com/docker/distribution/digest"
|
|
storagedriver "github.com/docker/distribution/registry/storage/driver"
|
|
)
|
|
|
|
var _ distribution.TagService = &tagStore{}
|
|
|
|
// tagStore provides methods to manage manifest tags in a backend storage driver.
|
|
// This implementation uses the same on-disk layout as the (now deleted) tag
|
|
// store. This provides backward compatibility with current registry deployments
|
|
// which only makes use of the Digest field of the returned distribution.Descriptor
|
|
// but does not enable full roundtripping of Descriptor objects
|
|
type tagStore struct {
|
|
repository *repository
|
|
blobStore *blobStore
|
|
}
|
|
|
|
// All returns all tags
|
|
func (ts *tagStore) All(ctx context.Context) ([]string, error) {
|
|
var tags []string
|
|
|
|
pathSpec, err := pathFor(manifestTagPathSpec{
|
|
name: ts.repository.Name(),
|
|
})
|
|
if err != nil {
|
|
return tags, err
|
|
}
|
|
|
|
entries, err := ts.blobStore.driver.List(ctx, pathSpec)
|
|
if err != nil {
|
|
switch err := err.(type) {
|
|
case storagedriver.PathNotFoundError:
|
|
return tags, distribution.ErrRepositoryUnknown{Name: ts.repository.Name()}
|
|
default:
|
|
return tags, err
|
|
}
|
|
}
|
|
|
|
for _, entry := range entries {
|
|
_, filename := path.Split(entry)
|
|
tags = append(tags, filename)
|
|
}
|
|
|
|
return tags, nil
|
|
}
|
|
|
|
// exists returns true if the specified manifest tag exists in the repository.
|
|
func (ts *tagStore) exists(ctx context.Context, tag string) (bool, error) {
|
|
tagPath, err := pathFor(manifestTagCurrentPathSpec{
|
|
name: ts.repository.Name(),
|
|
tag: tag,
|
|
})
|
|
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
exists, err := exists(ctx, ts.blobStore.driver, tagPath)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return exists, nil
|
|
}
|
|
|
|
// Tag tags the digest with the given tag, updating the the store to point at
|
|
// the current tag. The digest must point to a manifest.
|
|
func (ts *tagStore) Tag(ctx context.Context, tag string, desc distribution.Descriptor) error {
|
|
currentPath, err := pathFor(manifestTagCurrentPathSpec{
|
|
name: ts.repository.Name(),
|
|
tag: tag,
|
|
})
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
lbs := ts.linkedBlobStore(ctx, tag)
|
|
|
|
// Link into the index
|
|
if err := lbs.linkBlob(ctx, desc); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Overwrite the current link
|
|
return ts.blobStore.link(ctx, currentPath, desc.Digest)
|
|
}
|
|
|
|
// resolve the current revision for name and tag.
|
|
func (ts *tagStore) Get(ctx context.Context, tag string) (distribution.Descriptor, error) {
|
|
currentPath, err := pathFor(manifestTagCurrentPathSpec{
|
|
name: ts.repository.Name(),
|
|
tag: tag,
|
|
})
|
|
|
|
if err != nil {
|
|
return distribution.Descriptor{}, err
|
|
}
|
|
|
|
revision, err := ts.blobStore.readlink(ctx, currentPath)
|
|
if err != nil {
|
|
switch err.(type) {
|
|
case storagedriver.PathNotFoundError:
|
|
return distribution.Descriptor{}, distribution.ErrTagUnknown{Tag: tag}
|
|
}
|
|
|
|
return distribution.Descriptor{}, err
|
|
}
|
|
|
|
return distribution.Descriptor{Digest: revision}, nil
|
|
}
|
|
|
|
// delete removes the tag from repository, including the history of all
|
|
// revisions that have the specified tag.
|
|
func (ts *tagStore) Untag(ctx context.Context, tag string) error {
|
|
tagPath, err := pathFor(manifestTagPathSpec{
|
|
name: ts.repository.Name(),
|
|
tag: tag,
|
|
})
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return ts.blobStore.driver.Delete(ctx, tagPath)
|
|
}
|
|
|
|
// linkedBlobStore returns the linkedBlobStore for the named tag, allowing one
|
|
// to index manifest blobs by tag name. While the tag store doesn't map
|
|
// precisely to the linked blob store, using this ensures the links are
|
|
// managed via the same code path.
|
|
func (ts *tagStore) linkedBlobStore(ctx context.Context, tag string) *linkedBlobStore {
|
|
return &linkedBlobStore{
|
|
blobStore: ts.blobStore,
|
|
repository: ts.repository,
|
|
ctx: ctx,
|
|
linkPathFns: []linkPathFunc{func(name string, dgst digest.Digest) (string, error) {
|
|
return pathFor(manifestTagIndexEntryLinkPathSpec{
|
|
name: name,
|
|
tag: tag,
|
|
revision: dgst,
|
|
})
|
|
|
|
}},
|
|
}
|
|
}
|
|
|
|
// Lookup recovers a list of tags which refer to this digest. When a manifest is deleted by
|
|
// digest, tag entries which point to it need to be recovered to avoid dangling tags.
|
|
func (ts *tagStore) Lookup(ctx context.Context, digest distribution.Descriptor) ([]string, error) {
|
|
// An efficient implementation of this will require changes to the S3 driver.
|
|
return make([]string, 0), nil
|
|
}
|