Merge pull request #10727 from ahmetalpbalkan/win-cli/integration-cli-compile-fix
Create builder/command, cut libcontainer dependency on integration-cli
This commit is contained in:
commit
802802b781
4 changed files with 82 additions and 47 deletions
37
builder/command/command.go
Normal file
37
builder/command/command.go
Normal file
|
@ -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,
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/docker/docker/builder/command"
|
||||
)
|
||||
|
||||
// Node is a structure used to represent a parse tree.
|
||||
|
@ -44,20 +46,20 @@ func init() {
|
|||
// functions. Errors are propagated up by Parse() and the resulting AST can
|
||||
// be incorporated directly into the existing AST as a next.
|
||||
dispatch = map[string]func(string) (*Node, map[string]bool, error){
|
||||
"user": parseString,
|
||||
"onbuild": parseSubCommand,
|
||||
"workdir": parseString,
|
||||
"env": parseEnv,
|
||||
"maintainer": parseString,
|
||||
"from": parseString,
|
||||
"add": parseMaybeJSONToList,
|
||||
"copy": parseMaybeJSONToList,
|
||||
"run": parseMaybeJSON,
|
||||
"cmd": parseMaybeJSON,
|
||||
"entrypoint": parseMaybeJSON,
|
||||
"expose": parseStringsWhitespaceDelimited,
|
||||
"volume": parseMaybeJSONToList,
|
||||
"insert": parseIgnore,
|
||||
command.User: parseString,
|
||||
command.Onbuild: parseSubCommand,
|
||||
command.Workdir: parseString,
|
||||
command.Env: parseEnv,
|
||||
command.Maintainer: parseString,
|
||||
command.From: parseString,
|
||||
command.Add: parseMaybeJSONToList,
|
||||
command.Copy: parseMaybeJSONToList,
|
||||
command.Run: parseMaybeJSON,
|
||||
command.Cmd: parseMaybeJSON,
|
||||
command.Entrypoint: parseMaybeJSON,
|
||||
command.Expose: parseStringsWhitespaceDelimited,
|
||||
command.Volume: parseMaybeJSONToList,
|
||||
command.Insert: parseIgnore,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue