|
@@ -24,13 +24,13 @@ import (
|
|
|
"github.com/docker/libtrust"
|
|
|
)
|
|
|
|
|
|
-// DefaultTag defines the default tag used when performing images related actions and no tag string is specified
|
|
|
-const DefaultTag = "latest"
|
|
|
-
|
|
|
-// TagStore contains information to push and pull to the repo.
|
|
|
+// TagStore manages repositories. It encompasses the Graph used for versioned
|
|
|
+// storage, as well as various services involved in pushing and pulling
|
|
|
+// repositories.
|
|
|
type TagStore struct {
|
|
|
- path string
|
|
|
- graph *Graph
|
|
|
+ path string
|
|
|
+ graph *Graph
|
|
|
+ // Repositories is a map of repositories, indexed by name.
|
|
|
Repositories map[string]Repository
|
|
|
trustKey libtrust.PrivateKey
|
|
|
sync.Mutex
|
|
@@ -43,7 +43,7 @@ type TagStore struct {
|
|
|
trustService *trust.TrustStore
|
|
|
}
|
|
|
|
|
|
-// Repository maps image id to image tag.
|
|
|
+// Repository maps tags to image IDs.
|
|
|
type Repository map[string]string
|
|
|
|
|
|
// Update updates repository mapping with content of repository 'u'.
|
|
@@ -53,7 +53,8 @@ func (r Repository) Update(u Repository) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// Contains returns true if the contents of u Repository, are wholly contained in r Repository.
|
|
|
+// Contains returns true if the contents of Repository u are wholly contained
|
|
|
+// in Repository r.
|
|
|
func (r Repository) Contains(u Repository) bool {
|
|
|
for k, v := range u {
|
|
|
// if u's key is not present in r OR u's key is present, but not the same value
|
|
@@ -64,16 +65,23 @@ func (r Repository) Contains(u Repository) bool {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
-// TagStoreConfig holds tag store configuration.
|
|
|
+// TagStoreConfig provides parameters for a new TagStore.
|
|
|
type TagStoreConfig struct {
|
|
|
- Graph *Graph
|
|
|
- Key libtrust.PrivateKey
|
|
|
+ // Graph is the versioned image store
|
|
|
+ Graph *Graph
|
|
|
+ // Key is the private key to use for signing manifests.
|
|
|
+ Key libtrust.PrivateKey
|
|
|
+ // Registry is the registry service to use for TLS configuration and
|
|
|
+ // endpoint lookup.
|
|
|
Registry *registry.Service
|
|
|
- Events *events.Events
|
|
|
- Trust *trust.TrustStore
|
|
|
+ // Events is the events service to use for logging.
|
|
|
+ Events *events.Events
|
|
|
+ // Trust is the trust service to use for push and pull operations.
|
|
|
+ Trust *trust.TrustStore
|
|
|
}
|
|
|
|
|
|
-// NewTagStore creates a tag store to specified path.
|
|
|
+// NewTagStore creates a new TagStore at specified path, using the parameters
|
|
|
+// and services provided in cfg.
|
|
|
func NewTagStore(path string, cfg *TagStoreConfig) (*TagStore, error) {
|
|
|
abspath, err := filepath.Abs(path)
|
|
|
if err != nil {
|
|
@@ -126,13 +134,15 @@ func (store *TagStore) reload() error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-// LookupImage returns the image from the store.
|
|
|
+// LookupImage returns pointer to an Image struct corresponding to the given
|
|
|
+// name. The name can include an optional tag; otherwise the default tag will
|
|
|
+// be used.
|
|
|
func (store *TagStore) LookupImage(name string) (*image.Image, error) {
|
|
|
// FIXME: standardize on returning nil when the image doesn't exist, and err for everything else
|
|
|
// (so we can pass all errors here)
|
|
|
repoName, ref := parsers.ParseRepositoryTag(name)
|
|
|
if ref == "" {
|
|
|
- ref = DefaultTag
|
|
|
+ ref = tags.DefaultTag
|
|
|
}
|
|
|
var (
|
|
|
err error
|
|
@@ -158,8 +168,8 @@ func (store *TagStore) LookupImage(name string) (*image.Image, error) {
|
|
|
return img, nil
|
|
|
}
|
|
|
|
|
|
-// ByID returns a reverse-lookup table of all the names which refer to each image.
|
|
|
-// Eg. {"43b5f19b10584": {"base:latest", "base:v1"}}
|
|
|
+// ByID returns a reverse-lookup table of all the names which refer to each
|
|
|
+// image - e.g. {"43b5f19b10584": {"base:latest", "base:v1"}}
|
|
|
func (store *TagStore) ByID() map[string][]string {
|
|
|
store.Lock()
|
|
|
defer store.Unlock()
|
|
@@ -178,7 +188,7 @@ func (store *TagStore) ByID() map[string][]string {
|
|
|
return byID
|
|
|
}
|
|
|
|
|
|
-// ImageName returns name of the image.
|
|
|
+// ImageName returns name of an image, given the image's ID.
|
|
|
func (store *TagStore) ImageName(id string) string {
|
|
|
if names, exists := store.ByID()[id]; exists && len(names) > 0 {
|
|
|
return names[0]
|
|
@@ -186,7 +196,7 @@ func (store *TagStore) ImageName(id string) string {
|
|
|
return stringid.TruncateID(id)
|
|
|
}
|
|
|
|
|
|
-// DeleteAll removes images identified by a specific id from the store.
|
|
|
+// DeleteAll removes images identified by a specific ID from the store.
|
|
|
func (store *TagStore) DeleteAll(id string) error {
|
|
|
names, exists := store.ByID()[id]
|
|
|
if !exists || len(names) == 0 {
|
|
@@ -207,7 +217,9 @@ func (store *TagStore) DeleteAll(id string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-// Delete removes a repo identified by a given name from the store
|
|
|
+// Delete deletes a repository or a specific tag. If ref is empty, the entire
|
|
|
+// repository named repoName will be deleted; otherwise only the tag named by
|
|
|
+// ref will be deleted.
|
|
|
func (store *TagStore) Delete(repoName, ref string) (bool, error) {
|
|
|
store.Lock()
|
|
|
defer store.Unlock()
|
|
@@ -240,14 +252,16 @@ func (store *TagStore) Delete(repoName, ref string) (bool, error) {
|
|
|
return deleted, store.save()
|
|
|
}
|
|
|
|
|
|
-// Tag adds a new tag to an existing image.
|
|
|
+// Tag creates a tag in the repository reponame, pointing to the image named
|
|
|
+// imageName. If force is true, an existing tag with the same name may be
|
|
|
+// overwritten.
|
|
|
func (store *TagStore) Tag(repoName, tag, imageName string, force bool) error {
|
|
|
- return store.SetLoad(repoName, tag, imageName, force, nil)
|
|
|
+ return store.setLoad(repoName, tag, imageName, force, nil)
|
|
|
}
|
|
|
|
|
|
-// SetLoad stores the image to the store.
|
|
|
+// setLoad stores the image to the store.
|
|
|
// If the imageName is already in the repo then a '-f' flag should be used to replace existing image.
|
|
|
-func (store *TagStore) SetLoad(repoName, tag, imageName string, force bool, out io.Writer) error {
|
|
|
+func (store *TagStore) setLoad(repoName, tag, imageName string, force bool, out io.Writer) error {
|
|
|
img, err := store.LookupImage(imageName)
|
|
|
store.Lock()
|
|
|
defer store.Unlock()
|
|
@@ -255,7 +269,7 @@ func (store *TagStore) SetLoad(repoName, tag, imageName string, force bool, out
|
|
|
return err
|
|
|
}
|
|
|
if tag == "" {
|
|
|
- tag = tags.DEFAULTTAG
|
|
|
+ tag = tags.DefaultTag
|
|
|
}
|
|
|
if err := validateRepoName(repoName); err != nil {
|
|
|
return err
|
|
@@ -331,7 +345,7 @@ func (store *TagStore) SetDigest(repoName, digest, imageName string) error {
|
|
|
return store.save()
|
|
|
}
|
|
|
|
|
|
-// Get returns a repo from the store.
|
|
|
+// Get returns the Repository tag/image map for a given repository.
|
|
|
func (store *TagStore) Get(repoName string) (Repository, error) {
|
|
|
store.Lock()
|
|
|
defer store.Unlock()
|
|
@@ -345,7 +359,8 @@ func (store *TagStore) Get(repoName string) (Repository, error) {
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
-// GetImage returns an image from a given repo from the store.
|
|
|
+// GetImage returns a pointer to an Image structure describing the image
|
|
|
+// referred to by refOrID inside repository repoName.
|
|
|
func (store *TagStore) GetImage(repoName, refOrID string) (*image.Image, error) {
|
|
|
repo, err := store.Get(repoName)
|
|
|
|
|
@@ -375,7 +390,8 @@ func (store *TagStore) GetImage(repoName, refOrID string) (*image.Image, error)
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
-// GetRepoRefs returns list of repos.
|
|
|
+// GetRepoRefs returns a map with image IDs as keys, and slices listing
|
|
|
+// repo/tag references as the values. It covers all repositories.
|
|
|
func (store *TagStore) GetRepoRefs() map[string][]string {
|
|
|
store.Lock()
|
|
|
reporefs := make(map[string][]string)
|