2014-11-18 00:29:42 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
2014-12-24 00:01:38 +00:00
|
|
|
"github.com/docker/distribution/digest"
|
2015-01-02 21:21:29 +00:00
|
|
|
"github.com/docker/distribution/manifest"
|
2014-12-24 00:01:38 +00:00
|
|
|
"github.com/docker/distribution/storagedriver"
|
2014-11-18 00:29:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Services provides various services with application-level operations for
|
|
|
|
// use across backend storage drivers.
|
|
|
|
type Services struct {
|
|
|
|
driver storagedriver.StorageDriver
|
|
|
|
pathMapper *pathMapper
|
|
|
|
layerUploadStore layerUploadStore
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewServices creates a new Services object to access docker objects stored
|
|
|
|
// in the underlying driver.
|
|
|
|
func NewServices(driver storagedriver.StorageDriver) *Services {
|
|
|
|
layerUploadStore, err := newTemporaryLocalFSLayerUploadStore()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
// TODO(stevvooe): This failure needs to be understood in the context
|
|
|
|
// of the lifecycle of the services object, which is uncertain at this
|
|
|
|
// point.
|
|
|
|
panic("unable to allocate layerUploadStore: " + err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Services{
|
|
|
|
driver: driver,
|
|
|
|
pathMapper: &pathMapper{
|
|
|
|
// TODO(sday): This should be configurable.
|
|
|
|
root: "/docker/registry/",
|
|
|
|
version: storagePathVersion,
|
|
|
|
},
|
|
|
|
layerUploadStore: layerUploadStore,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 (ss *Services) Layers() LayerService {
|
2014-11-21 01:49:35 +00:00
|
|
|
return &layerStore{driver: ss.driver, pathMapper: ss.pathMapper, uploadStore: ss.layerUploadStore}
|
2014-11-18 00:29:42 +00:00
|
|
|
}
|
2014-11-22 03:39:52 +00:00
|
|
|
|
|
|
|
// 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 (ss *Services) Manifests() ManifestService {
|
|
|
|
return &manifestStore{driver: ss.driver, pathMapper: ss.pathMapper, layerService: ss.Layers()}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ManifestService provides operations on image manifests.
|
|
|
|
type ManifestService interface {
|
2014-12-09 19:06:51 +00:00
|
|
|
// Tags lists the tags under the named repository.
|
|
|
|
Tags(name string) ([]string, error)
|
|
|
|
|
2014-11-22 03:39:52 +00:00
|
|
|
// Exists returns true if the layer exists.
|
|
|
|
Exists(name, tag string) (bool, error)
|
|
|
|
|
|
|
|
// Get retrieves the named manifest, if it exists.
|
2015-01-02 21:21:29 +00:00
|
|
|
Get(name, tag string) (*manifest.SignedManifest, error)
|
2014-11-22 03:39:52 +00:00
|
|
|
|
|
|
|
// Put creates or updates the named manifest.
|
2015-01-02 21:21:29 +00:00
|
|
|
Put(name, tag string, manifest *manifest.SignedManifest) error
|
2014-11-22 03:39:52 +00:00
|
|
|
|
|
|
|
// Delete removes the named manifest, if it exists.
|
|
|
|
Delete(name, tag string) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// LayerService provides operations on layer files in a backend storage.
|
|
|
|
type LayerService interface {
|
|
|
|
// Exists returns true if the layer exists.
|
|
|
|
Exists(name string, digest digest.Digest) (bool, error)
|
|
|
|
|
|
|
|
// Fetch the layer identifed by TarSum.
|
|
|
|
Fetch(name string, digest digest.Digest) (Layer, error)
|
|
|
|
|
|
|
|
// Upload begins a layer upload to repository identified by name,
|
|
|
|
// returning a handle.
|
|
|
|
Upload(name string) (LayerUpload, error)
|
|
|
|
|
|
|
|
// Resume continues an in progress layer upload, returning the current
|
|
|
|
// state of the upload.
|
|
|
|
Resume(uuid string) (LayerUpload, error)
|
|
|
|
}
|