Browse code

Create builder/command, cut libcontainer dependency on integration-cli

d1e9d07c introduces a dependency to libcontainer and other daemon
related packages through builder package. The only thing test needs
is set of the Dockerfile commands. Extracting them to a separate
package.

This was causing CI tests to not to compile on non-Linux platforms.

Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>

Ahmet Alp Balkan authored on 2015/02/12 14:18:48
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,37 @@
0
+// This package contains the set of Dockerfile commands.
1
+package command
2
+
3
+const (
4
+	Env        = "env"
5
+	Maintainer = "maintainer"
6
+	Add        = "add"
7
+	Copy       = "copy"
8
+	From       = "from"
9
+	Onbuild    = "onbuild"
10
+	Workdir    = "workdir"
11
+	Run        = "run"
12
+	Cmd        = "cmd"
13
+	Entrypoint = "entrypoint"
14
+	Expose     = "expose"
15
+	Volume     = "volume"
16
+	User       = "user"
17
+	Insert     = "insert"
18
+)
19
+
20
+// Commands is list of all Dockerfile commands
21
+var Commands = []string{
22
+	Env,
23
+	Maintainer,
24
+	Add,
25
+	Copy,
26
+	From,
27
+	Onbuild,
28
+	Workdir,
29
+	Run,
30
+	Cmd,
31
+	Entrypoint,
32
+	Expose,
33
+	Volume,
34
+	User,
35
+	Insert,
36
+}
... ...
@@ -28,6 +28,7 @@ import (
28 28
 	"strings"
29 29
 
30 30
 	log "github.com/Sirupsen/logrus"
31
+	"github.com/docker/docker/builder/command"
31 32
 	"github.com/docker/docker/builder/parser"
32 33
 	"github.com/docker/docker/daemon"
33 34
 	"github.com/docker/docker/engine"
... ...
@@ -45,35 +46,33 @@ var (
45 45
 
46 46
 // Environment variable interpolation will happen on these statements only.
47 47
 var replaceEnvAllowed = map[string]struct{}{
48
-	"env":     {},
49
-	"add":     {},
50
-	"copy":    {},
51
-	"workdir": {},
52
-	"expose":  {},
53
-	"volume":  {},
54
-	"user":    {},
48
+	command.Env:     {},
49
+	command.Add:     {},
50
+	command.Copy:    {},
51
+	command.Workdir: {},
52
+	command.Expose:  {},
53
+	command.Volume:  {},
54
+	command.User:    {},
55 55
 }
56 56
 
57
-// EvaluateTable is public so that we can get the list of Dockerfile
58
-// commands from within the test cases
59
-var EvaluateTable map[string]func(*Builder, []string, map[string]bool, string) error
57
+var evaluateTable map[string]func(*Builder, []string, map[string]bool, string) error
60 58
 
61 59
 func init() {
62
-	EvaluateTable = map[string]func(*Builder, []string, map[string]bool, string) error{
63
-		"env":        env,
64
-		"maintainer": maintainer,
65
-		"add":        add,
66
-		"copy":       dispatchCopy, // copy() is a go builtin
67
-		"from":       from,
68
-		"onbuild":    onbuild,
69
-		"workdir":    workdir,
70
-		"run":        run,
71
-		"cmd":        cmd,
72
-		"entrypoint": entrypoint,
73
-		"expose":     expose,
74
-		"volume":     volume,
75
-		"user":       user,
76
-		"insert":     insert,
60
+	evaluateTable = map[string]func(*Builder, []string, map[string]bool, string) error{
61
+		command.Env:        env,
62
+		command.Maintainer: maintainer,
63
+		command.Add:        add,
64
+		command.Copy:       dispatchCopy, // copy() is a go builtin
65
+		command.From:       from,
66
+		command.Onbuild:    onbuild,
67
+		command.Workdir:    workdir,
68
+		command.Run:        run,
69
+		command.Cmd:        cmd,
70
+		command.Entrypoint: entrypoint,
71
+		command.Expose:     expose,
72
+		command.Volume:     volume,
73
+		command.User:       user,
74
+		command.Insert:     insert,
77 75
 	}
78 76
 }
79 77
 
... ...
@@ -226,7 +225,7 @@ func (b *Builder) readDockerfile(origFile string) error {
226 226
 // Child[Node, Node, Node] where Child is from parser.Node.Children and each
227 227
 // node comes from parser.Node.Next. This forms a "line" with a statement and
228 228
 // arguments and we process them in this normalized form by hitting
229
-// EvaluateTable with the leaf nodes of the command and the Builder object.
229
+// evaluateTable with the leaf nodes of the command and the Builder object.
230 230
 //
231 231
 // ONBUILD is a special case; in this case the parser will emit:
232 232
 // Child[Node, Child[Node, Node...]] where the first node is the literal
... ...
@@ -282,7 +281,7 @@ func (b *Builder) dispatch(stepN int, ast *parser.Node) error {
282 282
 
283 283
 	// XXX yes, we skip any cmds that are not valid; the parser should have
284 284
 	// picked these out already.
285
-	if f, ok := EvaluateTable[cmd]; ok {
285
+	if f, ok := evaluateTable[cmd]; ok {
286 286
 		return f(b, strList, attrs, original)
287 287
 	}
288 288
 
... ...
@@ -19,7 +19,7 @@ import (
19 19
 	"text/template"
20 20
 	"time"
21 21
 
22
-	"github.com/docker/docker/builder"
22
+	"github.com/docker/docker/builder/command"
23 23
 	"github.com/docker/docker/pkg/archive"
24 24
 )
25 25
 
... ...
@@ -4828,7 +4828,6 @@ func TestBuildMissingArgs(t *testing.T) {
4828 4828
 	// Test to make sure that all Dockerfile commands (except the ones listed
4829 4829
 	// in skipCmds) will generate an error if no args are provided.
4830 4830
 	// Note: INSERT is deprecated so we exclude it because of that.
4831
-
4832 4831
 	skipCmds := map[string]struct{}{
4833 4832
 		"CMD":        {},
4834 4833
 		"RUN":        {},
... ...
@@ -4838,15 +4837,13 @@ func TestBuildMissingArgs(t *testing.T) {
4838 4838
 
4839 4839
 	defer deleteAllContainers()
4840 4840
 
4841
-	for cmd := range builder.EvaluateTable {
4842
-		var dockerfile string
4843
-
4841
+	for _, cmd := range command.Commands {
4844 4842
 		cmd = strings.ToUpper(cmd)
4845
-
4846 4843
 		if _, ok := skipCmds[cmd]; ok {
4847 4844
 			continue
4848 4845
 		}
4849 4846
 
4847
+		var dockerfile string
4850 4848
 		if cmd == "FROM" {
4851 4849
 			dockerfile = cmd
4852 4850
 		} else {