Browse Source

Looking up a tag by repository name will default to REPOSITORY:latest. The empty tag '' is no longer allowed.

Solomon Hykes 12 năm trước cách đây
mục cha
commit
640026ec59
3 tập tin đã thay đổi với 53 bổ sung27 xóa
  1. 1 1
      commands.go
  2. 1 22
      runtime.go
  3. 51 4
      tags.go

+ 1 - 1
commands.go

@@ -326,7 +326,7 @@ func (srv *Server) CmdHistory(stdin io.ReadCloser, stdout io.Writer, args ...str
 		cmd.Usage()
 		cmd.Usage()
 		return nil
 		return nil
 	}
 	}
-	image, err := srv.runtime.LookupImage(cmd.Arg(0))
+	image, err := srv.runtime.repositories.LookupImage(cmd.Arg(0))
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}

+ 1 - 22
runtime.go

@@ -9,7 +9,6 @@ import (
 	"os"
 	"os"
 	"path"
 	"path"
 	"sort"
 	"sort"
-	"strings"
 	"sync"
 	"sync"
 	"time"
 	"time"
 )
 )
@@ -63,29 +62,9 @@ func (runtime *Runtime) containerRoot(id string) string {
 	return path.Join(runtime.repository, id)
 	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) {
 func (runtime *Runtime) Create(command string, args []string, image string, config *Config) (*Container, error) {
 	// Lookup image
 	// Lookup image
-	img, err := runtime.LookupImage(image)
+	img, err := runtime.repositories.LookupImage(image)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}

+ 51 - 4
tags.go

@@ -9,6 +9,8 @@ import (
 	"strings"
 	"strings"
 )
 )
 
 
+const DEFAULT_TAG = "latest"
+
 type TagStore struct {
 type TagStore struct {
 	path         string
 	path         string
 	graph        *Graph
 	graph        *Graph
@@ -61,12 +63,35 @@ func (store *TagStore) Reload() error {
 	return nil
 	return nil
 }
 }
 
 
+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
+		}
+	}
+	return img, nil
+}
+
 func (store *TagStore) Set(repoName, tag, revision string) error {
 func (store *TagStore) Set(repoName, tag, revision string) error {
-	if strings.Contains(repoName, ":") {
-		return fmt.Errorf("Illegal repository name: %s", repoName)
+	if tag == "" {
+		tag = DEFAULT_TAG
 	}
 	}
-	if strings.Contains(repoName, ":") {
-		return fmt.Errorf("Illegal tag name: %s", tag)
+	if err := validateRepoName(repoName); err != nil {
+		return err
+	}
+	if err := validateTagName(tag); err != nil {
+		return err
 	}
 	}
 	if err := store.Reload(); err != nil {
 	if err := store.Reload(); err != nil {
 		return err
 		return err
@@ -104,3 +129,25 @@ func (store *TagStore) GetImage(repoName, tag string) (*Image, error) {
 	}
 	}
 	return nil, nil
 	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
+}