Browse code

Move "image_tag" and "tag" to graph/tag.go

Note: these 2 jobs should be merged into one. This was noted in a FIXME.

Signed-off-by: Solomon Hykes <solomon@docker.com>

Solomon Hykes authored on 2014/08/05 15:49:10
Showing 4 changed files
... ...
@@ -5,13 +5,13 @@ import (
5 5
 
6 6
 	"github.com/docker/docker/engine"
7 7
 	"github.com/docker/docker/image"
8
-	"github.com/docker/docker/pkg/parsers"
9 8
 	"github.com/docker/docker/utils"
10 9
 )
11 10
 
12 11
 func (s *TagStore) Install(eng *engine.Engine) error {
13 12
 	eng.Register("image_set", s.CmdSet)
14 13
 	eng.Register("image_tag", s.CmdTag)
14
+	eng.Register("tag", s.CmdTagLegacy) // FIXME merge with "image_tag"
15 15
 	eng.Register("image_get", s.CmdGet)
16 16
 	eng.Register("image_inspect", s.CmdLookup)
17 17
 	eng.Register("image_tarlayer", s.CmdTarLayer)
... ...
@@ -71,29 +71,6 @@ func (s *TagStore) CmdSet(job *engine.Job) engine.Status {
71 71
 	return engine.StatusOK
72 72
 }
73 73
 
74
-// CmdTag assigns a new name and tag to an existing image. If the tag already exists,
75
-// it is changed and the image previously referenced by the tag loses that reference.
76
-// This may cause the old image to be garbage-collected if its reference count reaches zero.
77
-//
78
-// Syntax: image_tag NEWNAME OLDNAME
79
-// Example: image_tag shykes/myapp:latest shykes/myapp:1.42.0
80
-func (s *TagStore) CmdTag(job *engine.Job) engine.Status {
81
-	if len(job.Args) != 2 {
82
-		return job.Errorf("usage: %s NEWNAME OLDNAME", job.Name)
83
-	}
84
-	var (
85
-		newName = job.Args[0]
86
-		oldName = job.Args[1]
87
-	)
88
-	newRepo, newTag := parsers.ParseRepositoryTag(newName)
89
-	// FIXME: Set should either parse both old and new name, or neither.
90
-	// 	the current prototype is inconsistent.
91
-	if err := s.Set(newRepo, newTag, oldName, true); err != nil {
92
-		return job.Error(err)
93
-	}
94
-	return engine.StatusOK
95
-}
96
-
97 74
 // CmdGet returns information about an image.
98 75
 // If the image doesn't exist, an empty object is returned, to allow
99 76
 // checking for an image's existence.
100 77
new file mode 100644
... ...
@@ -0,0 +1,44 @@
0
+package graph
1
+
2
+import (
3
+	"github.com/docker/docker/engine"
4
+	"github.com/docker/docker/pkg/parsers"
5
+)
6
+
7
+// CmdTag assigns a new name and tag to an existing image. If the tag already exists,
8
+// it is changed and the image previously referenced by the tag loses that reference.
9
+// This may cause the old image to be garbage-collected if its reference count reaches zero.
10
+//
11
+// Syntax: image_tag NEWNAME OLDNAME
12
+// Example: image_tag shykes/myapp:latest shykes/myapp:1.42.0
13
+func (s *TagStore) CmdTag(job *engine.Job) engine.Status {
14
+	if len(job.Args) != 2 {
15
+		return job.Errorf("usage: %s NEWNAME OLDNAME", job.Name)
16
+	}
17
+	var (
18
+		newName = job.Args[0]
19
+		oldName = job.Args[1]
20
+	)
21
+	newRepo, newTag := parsers.ParseRepositoryTag(newName)
22
+	// FIXME: Set should either parse both old and new name, or neither.
23
+	// 	the current prototype is inconsistent.
24
+	if err := s.Set(newRepo, newTag, oldName, true); err != nil {
25
+		return job.Error(err)
26
+	}
27
+	return engine.StatusOK
28
+}
29
+
30
+// FIXME: merge into CmdTag above, and merge "image_tag" and "tag" into a single job.
31
+func (s *TagStore) CmdTagLegacy(job *engine.Job) engine.Status {
32
+	if len(job.Args) != 2 && len(job.Args) != 3 {
33
+		return job.Errorf("Usage: %s IMAGE REPOSITORY [TAG]\n", job.Name)
34
+	}
35
+	var tag string
36
+	if len(job.Args) == 3 {
37
+		tag = job.Args[2]
38
+	}
39
+	if err := s.Set(job.Args[1], tag, job.Args[0], job.GetenvBool("force")); err != nil {
40
+		return job.Error(err)
41
+	}
42
+	return engine.StatusOK
43
+}
... ...
@@ -105,20 +105,6 @@ func (srv *Server) Build(job *engine.Job) engine.Status {
105 105
 	return engine.StatusOK
106 106
 }
107 107
 
108
-func (srv *Server) ImageTag(job *engine.Job) engine.Status {
109
-	if len(job.Args) != 2 && len(job.Args) != 3 {
110
-		return job.Errorf("Usage: %s IMAGE REPOSITORY [TAG]\n", job.Name)
111
-	}
112
-	var tag string
113
-	if len(job.Args) == 3 {
114
-		tag = job.Args[2]
115
-	}
116
-	if err := srv.daemon.Repositories().Set(job.Args[1], tag, job.Args[0], job.GetenvBool("force")); err != nil {
117
-		return job.Error(err)
118
-	}
119
-	return engine.StatusOK
120
-}
121
-
122 108
 func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgID, endpoint string, token []string, sf *utils.StreamFormatter) error {
123 109
 	history, err := r.GetRemoteHistory(imgID, endpoint, token)
124 110
 	if err != nil {
... ...
@@ -86,7 +86,6 @@ func InitServer(job *engine.Job) engine.Status {
86 86
 	job.Eng.Hack_SetGlobalVar("httpapi.daemon", srv.daemon)
87 87
 
88 88
 	for name, handler := range map[string]engine.Handler{
89
-		"tag":    srv.ImageTag, // FIXME merge with "image_tag"
90 89
 		"info":   srv.DockerInfo,
91 90
 		"log":    srv.Log,
92 91
 		"build":  srv.Build,