зеркало из https://github.com/microsoft/docker.git
Looking up a tag by repository name will default to REPOSITORY:latest. The empty tag '' is no longer allowed.
This commit is contained in:
Родитель
d8fa52b7b5
Коммит
640026ec59
|
@ -326,7 +326,7 @@ func (srv *Server) CmdHistory(stdin io.ReadCloser, stdout io.Writer, args ...str
|
|||
cmd.Usage()
|
||||
return nil
|
||||
}
|
||||
image, err := srv.runtime.LookupImage(cmd.Arg(0))
|
||||
image, err := srv.runtime.repositories.LookupImage(cmd.Arg(0))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
23
runtime.go
23
runtime.go
|
@ -9,7 +9,6 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
@ -63,29 +62,9 @@ func (runtime *Runtime) containerRoot(id string) string {
|
|||
return path.Join(runtime.repository, id)
|
||||
}
|
||||
|
||||
func (runtime *Runtime) LookupImage(name string) (*Image, error) {
|
||||
img, err := runtime.graph.Get(name)
|
||||
if err != nil {
|
||||
// FIXME: standardize on returning nil when the image doesn't exist, and err for everything else
|
||||
// (so we can pass all errors here)
|
||||
repoAndTag := strings.SplitN(name, ":", 2)
|
||||
if len(repoAndTag) == 1 {
|
||||
repoAndTag = append(repoAndTag, "")
|
||||
}
|
||||
if i, err := runtime.repositories.GetImage(repoAndTag[0], repoAndTag[1]); err != nil {
|
||||
return nil, err
|
||||
} else if i == nil {
|
||||
return nil, fmt.Errorf("No such image: %s", name)
|
||||
} else {
|
||||
img = i
|
||||
}
|
||||
}
|
||||
return img, nil
|
||||
}
|
||||
|
||||
func (runtime *Runtime) Create(command string, args []string, image string, config *Config) (*Container, error) {
|
||||
// Lookup image
|
||||
img, err := runtime.LookupImage(image)
|
||||
img, err := runtime.repositories.LookupImage(image)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
57
tags.go
57
tags.go
|
@ -9,6 +9,8 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
const DEFAULT_TAG = "latest"
|
||||
|
||||
type TagStore struct {
|
||||
path string
|
||||
graph *Graph
|
||||
|
@ -61,12 +63,35 @@ func (store *TagStore) Reload() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (store *TagStore) Set(repoName, tag, revision string) error {
|
||||
if strings.Contains(repoName, ":") {
|
||||
return fmt.Errorf("Illegal repository name: %s", repoName)
|
||||
func (store *TagStore) LookupImage(name string) (*Image, error) {
|
||||
img, err := store.graph.Get(name)
|
||||
if err != nil {
|
||||
// FIXME: standardize on returning nil when the image doesn't exist, and err for everything else
|
||||
// (so we can pass all errors here)
|
||||
repoAndTag := strings.SplitN(name, ":", 2)
|
||||
if len(repoAndTag) == 1 {
|
||||
repoAndTag = append(repoAndTag, DEFAULT_TAG)
|
||||
}
|
||||
if i, err := store.GetImage(repoAndTag[0], repoAndTag[1]); err != nil {
|
||||
return nil, err
|
||||
} else if i == nil {
|
||||
return nil, fmt.Errorf("No such image: %s", name)
|
||||
} else {
|
||||
img = i
|
||||
}
|
||||
}
|
||||
if strings.Contains(repoName, ":") {
|
||||
return fmt.Errorf("Illegal tag name: %s", tag)
|
||||
return img, nil
|
||||
}
|
||||
|
||||
func (store *TagStore) Set(repoName, tag, revision string) error {
|
||||
if tag == "" {
|
||||
tag = DEFAULT_TAG
|
||||
}
|
||||
if err := validateRepoName(repoName); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateTagName(tag); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := store.Reload(); err != nil {
|
||||
return err
|
||||
|
@ -104,3 +129,25 @@ func (store *TagStore) GetImage(repoName, tag string) (*Image, error) {
|
|||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Validate the name of a repository
|
||||
func validateRepoName(name string) error {
|
||||
if name == "" {
|
||||
return fmt.Errorf("Repository name can't be empty")
|
||||
}
|
||||
if strings.Contains(name, ":") {
|
||||
return fmt.Errorf("Illegal repository name: %s", name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Validate the name of a tag
|
||||
func validateTagName(name string) error {
|
||||
if name == "" {
|
||||
return fmt.Errorf("Tag name can't be empty")
|
||||
}
|
||||
if strings.Contains(name, "/") || strings.Contains(name, ":") {
|
||||
return fmt.Errorf("Illegal tag name: %s", name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче