Refactor storage API to be registry oriented
In support of making the storage API ready for supporting notifications and mirroring, we've begun the process of paring down the storage model. The process started by creating a central Registry interface. From there, the common name argument on the LayerService and ManifestService was factored into a Repository interface. The rest of the changes directly follow from this. An interface wishlist was added, suggesting a direction to take the registry package that should support the distribution project's future goals. As these objects move out of the storage package and we implement a Registry backed by the http client, these design choices will start getting validation. Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
03406ab708
commit
ea5b999fc0
10 changed files with 287 additions and 301 deletions
75
storage/registry.go
Normal file
75
storage/registry.go
Normal file
|
@ -0,0 +1,75 @@
|
|||
package storage
|
||||
|
||||
import "github.com/docker/distribution/storagedriver"
|
||||
|
||||
// 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.
|
||||
func NewRegistryWithDriver(driver storagedriver.StorageDriver) Registry {
|
||||
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.
|
||||
func (reg *registry) Repository(name string) Repository {
|
||||
return &repository{
|
||||
registry: reg,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
// repository provides name-scoped access to various services.
|
||||
type repository struct {
|
||||
*registry
|
||||
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.
|
||||
func (repo *repository) Manifests() ManifestService {
|
||||
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.
|
||||
func (repo *repository) Layers() LayerService {
|
||||
return &layerStore{
|
||||
repository: repo,
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue