diff --git a/builder/command/command.go b/builder/command/command.go new file mode 100644 index 0000000000..3901bb34f7 --- /dev/null +++ b/builder/command/command.go @@ -0,0 +1,37 @@ +// This package contains the set of Dockerfile commands. +package command + +const ( + Env = "env" + Maintainer = "maintainer" + Add = "add" + Copy = "copy" + From = "from" + Onbuild = "onbuild" + Workdir = "workdir" + Run = "run" + Cmd = "cmd" + Entrypoint = "entrypoint" + Expose = "expose" + Volume = "volume" + User = "user" + Insert = "insert" +) + +// Commands is list of all Dockerfile commands +var Commands = []string{ + Env, + Maintainer, + Add, + Copy, + From, + Onbuild, + Workdir, + Run, + Cmd, + Entrypoint, + Expose, + Volume, + User, + Insert, +} diff --git a/builder/evaluator.go b/builder/evaluator.go index d9dd3547ab..1152f29448 100644 --- a/builder/evaluator.go +++ b/builder/evaluator.go @@ -28,6 +28,7 @@ import ( "strings" log "github.com/Sirupsen/logrus" + "github.com/docker/docker/builder/command" "github.com/docker/docker/builder/parser" "github.com/docker/docker/daemon" "github.com/docker/docker/engine" @@ -45,35 +46,33 @@ var ( // Environment variable interpolation will happen on these statements only. var replaceEnvAllowed = map[string]struct{}{ - "env": {}, - "add": {}, - "copy": {}, - "workdir": {}, - "expose": {}, - "volume": {}, - "user": {}, + command.Env: {}, + command.Add: {}, + command.Copy: {}, + command.Workdir: {}, + command.Expose: {}, + command.Volume: {}, + command.User: {}, } -// EvaluateTable is public so that we can get the list of Dockerfile -// commands from within the test cases -var EvaluateTable map[string]func(*Builder, []string, map[string]bool, string) error +var evaluateTable map[string]func(*Builder, []string, map[string]bool, string) error func init() { - EvaluateTable = map[string]func(*Builder, []string, map[string]bool, string) error{ - "env": env, - "maintainer": maintainer, - "add": add, - "copy": dispatchCopy, // copy() is a go builtin - "from": from, - "onbuild": onbuild, - "workdir": workdir, - "run": run, - "cmd": cmd, - "entrypoint": entrypoint, - "expose": expose, - "volume": volume, - "user": user, - "insert": insert, + evaluateTable = map[string]func(*Builder, []string, map[string]bool, string) error{ + command.Env: env, + command.Maintainer: maintainer, + command.Add: add, + command.Copy: dispatchCopy, // copy() is a go builtin + command.From: from, + command.Onbuild: onbuild, + command.Workdir: workdir, + command.Run: run, + command.Cmd: cmd, + command.Entrypoint: entrypoint, + command.Expose: expose, + command.Volume: volume, + command.User: user, + command.Insert: insert, } } @@ -226,7 +225,7 @@ func (b *Builder) readDockerfile(origFile string) error { // Child[Node, Node, Node] where Child is from parser.Node.Children and each // node comes from parser.Node.Next. This forms a "line" with a statement and // arguments and we process them in this normalized form by hitting -// EvaluateTable with the leaf nodes of the command and the Builder object. +// evaluateTable with the leaf nodes of the command and the Builder object. // // ONBUILD is a special case; in this case the parser will emit: // 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 { // XXX yes, we skip any cmds that are not valid; the parser should have // picked these out already. - if f, ok := EvaluateTable[cmd]; ok { + if f, ok := evaluateTable[cmd]; ok { return f(b, strList, attrs, original) } diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index e2804cf94a..c0aae34a5d 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -19,7 +19,7 @@ import ( "text/template" "time" - "github.com/docker/docker/builder" + "github.com/docker/docker/builder/command" "github.com/docker/docker/pkg/archive" ) @@ -4828,7 +4828,6 @@ func TestBuildMissingArgs(t *testing.T) { // Test to make sure that all Dockerfile commands (except the ones listed // in skipCmds) will generate an error if no args are provided. // Note: INSERT is deprecated so we exclude it because of that. - skipCmds := map[string]struct{}{ "CMD": {}, "RUN": {}, @@ -4838,15 +4837,13 @@ func TestBuildMissingArgs(t *testing.T) { defer deleteAllContainers() - for cmd := range builder.EvaluateTable { - var dockerfile string - + for _, cmd := range command.Commands { cmd = strings.ToUpper(cmd) - if _, ok := skipCmds[cmd]; ok { continue } + var dockerfile string if cmd == "FROM" { dockerfile = cmd } else {