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>
This commit is contained in:
parent
f4749acad4
commit
ccde3a1f73
3 changed files with 66 additions and 33 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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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…
Reference in a new issue