2015-02-11 01:41:09 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
2015-02-12 00:49:49 +00:00
|
|
|
"github.com/docker/distribution"
|
2015-02-11 02:14:23 +00:00
|
|
|
storagedriver "github.com/docker/distribution/registry/storage/driver"
|
2015-02-11 01:41:09 +00:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// registry is the top-level implementation of Registry for use in the storage
|
|
|
|
// package. All instances should descend from this object.
|
|
|
|
type registry struct {
|
|
|
|
driver storagedriver.StorageDriver
|
|
|
|
pm *pathMapper
|
|
|
|
blobStore *blobStore
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewRegistryWithDriver creates a new registry instance from the provided
|
|
|
|
// driver. The resulting registry may be shared by multiple goroutines but is
|
|
|
|
// cheap to allocate.
|
2015-02-12 00:49:49 +00:00
|
|
|
func NewRegistryWithDriver(driver storagedriver.StorageDriver) distribution.Registry {
|
2015-02-11 01:41:09 +00:00
|
|
|
bs := &blobStore{}
|
|
|
|
|
|
|
|
reg := ®istry{
|
|
|
|
driver: driver,
|
|
|
|
blobStore: bs,
|
|
|
|
|
|
|
|
// TODO(sday): This should be configurable.
|
|
|
|
pm: defaultPathMapper,
|
|
|
|
}
|
|
|
|
|
|
|
|
reg.blobStore.registry = reg
|
|
|
|
|
|
|
|
return reg
|
|
|
|
}
|
|
|
|
|
|
|
|
// Repository returns an instance of the repository tied to the registry.
|
|
|
|
// Instances should not be shared between goroutines but are cheap to
|
|
|
|
// allocate. In general, they should be request scoped.
|
2015-02-12 00:49:49 +00:00
|
|
|
func (reg *registry) Repository(ctx context.Context, name string) distribution.Repository {
|
2015-02-11 01:41:09 +00:00
|
|
|
return &repository{
|
|
|
|
ctx: ctx,
|
|
|
|
registry: reg,
|
|
|
|
name: name,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// repository provides name-scoped access to various services.
|
|
|
|
type repository struct {
|
|
|
|
*registry
|
|
|
|
ctx context.Context
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name returns the name of the repository.
|
|
|
|
func (repo *repository) Name() string {
|
|
|
|
return repo.name
|
|
|
|
}
|
|
|
|
|
|
|
|
// Manifests returns an instance of ManifestService. Instantiation is cheap and
|
|
|
|
// may be context sensitive in the future. The instance should be used similar
|
|
|
|
// to a request local.
|
2015-02-12 00:49:49 +00:00
|
|
|
func (repo *repository) Manifests() distribution.ManifestService {
|
2015-02-11 01:41:09 +00:00
|
|
|
return &manifestStore{
|
|
|
|
repository: repo,
|
|
|
|
revisionStore: &revisionStore{
|
|
|
|
repository: repo,
|
|
|
|
},
|
|
|
|
tagStore: &tagStore{
|
|
|
|
repository: repo,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Layers returns an instance of the LayerService. Instantiation is cheap and
|
|
|
|
// may be context sensitive in the future. The instance should be used similar
|
|
|
|
// to a request local.
|
2015-02-12 00:49:49 +00:00
|
|
|
func (repo *repository) Layers() distribution.LayerService {
|
2015-02-11 01:41:09 +00:00
|
|
|
return &layerStore{
|
|
|
|
repository: repo,
|
|
|
|
}
|
|
|
|
}
|