ignore invalid Dockerfile instructions and do not consider "docker-version" a Dockerfile instruction

Signed-off-by: Tibor Vass <teabee89@gmail.com>
This commit is contained in:
Tibor Vass 2014-10-06 23:24:43 -04:00
parent 9fe1dd3103
commit 0a2c481c7f
4 changed files with 36 additions and 38 deletions

View File

@ -45,21 +45,20 @@ var evaluateTable map[string]func(*Builder, []string, map[string]bool) error
func init() { func init() {
evaluateTable = map[string]func(*Builder, []string, map[string]bool) error{ evaluateTable = map[string]func(*Builder, []string, map[string]bool) error{
"env": env, "env": env,
"maintainer": maintainer, "maintainer": maintainer,
"add": add, "add": add,
"copy": dispatchCopy, // copy() is a go builtin "copy": dispatchCopy, // copy() is a go builtin
"from": from, "from": from,
"onbuild": onbuild, "onbuild": onbuild,
"workdir": workdir, "workdir": workdir,
"docker-version": nullDispatch, // we don't care about docker-version "run": run,
"run": run, "cmd": cmd,
"cmd": cmd, "entrypoint": entrypoint,
"entrypoint": entrypoint, "expose": expose,
"expose": expose, "volume": volume,
"volume": volume, "user": user,
"user": user, "insert": insert,
"insert": insert,
} }
} }

View File

@ -43,21 +43,20 @@ func init() {
// functions. Errors are propogated up by Parse() and the resulting AST can // functions. Errors are propogated up by Parse() and the resulting AST can
// be incorporated directly into the existing AST as a next. // be incorporated directly into the existing AST as a next.
dispatch = map[string]func(string) (*Node, map[string]bool, error){ dispatch = map[string]func(string) (*Node, map[string]bool, error){
"user": parseString, "user": parseString,
"onbuild": parseSubCommand, "onbuild": parseSubCommand,
"workdir": parseString, "workdir": parseString,
"env": parseEnv, "env": parseEnv,
"maintainer": parseString, "maintainer": parseString,
"docker-version": parseString, "from": parseString,
"from": parseString, "add": parseStringsWhitespaceDelimited,
"add": parseStringsWhitespaceDelimited, "copy": parseStringsWhitespaceDelimited,
"copy": parseStringsWhitespaceDelimited, "run": parseMaybeJSON,
"run": parseMaybeJSON, "cmd": parseMaybeJSON,
"cmd": parseMaybeJSON, "entrypoint": parseMaybeJSON,
"entrypoint": parseMaybeJSON, "expose": parseStringsWhitespaceDelimited,
"expose": parseStringsWhitespaceDelimited, "volume": parseMaybeJSONToList,
"volume": parseMaybeJSONToList, "insert": parseIgnore,
"insert": parseIgnore,
} }
} }

View File

@ -1,4 +1,4 @@
(docker-version "0.6.1") (docker-version)
(from "ubuntu:14.04") (from "ubuntu:14.04")
(maintainer "Tianon Gravi <admwiggin@gmail.com> (@tianon)") (maintainer "Tianon Gravi <admwiggin@gmail.com> (@tianon)")
(run "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -yq apt-utils aufs-tools automake btrfs-tools build-essential curl dpkg-sig git iptables libapparmor-dev libcap-dev libsqlite3-dev lxc=1.0* mercurial pandoc parallel reprepro ruby1.9.1 ruby1.9.1-dev s3cmd=1.1.0* --no-install-recommends") (run "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -yq apt-utils aufs-tools automake btrfs-tools build-essential curl dpkg-sig git iptables libapparmor-dev libcap-dev libsqlite3-dev lxc=1.0* mercurial pandoc parallel reprepro ruby1.9.1 ruby1.9.1-dev s3cmd=1.1.0* --no-install-recommends")

View File

@ -1,9 +1,6 @@
package parser package parser
import ( import "strings"
"fmt"
"strings"
)
// QuoteString walks characters (after trimming), escapes any quotes and // QuoteString walks characters (after trimming), escapes any quotes and
// escapes, then wraps the whole thing in quotes. Very useful for generating // escapes, then wraps the whole thing in quotes. Very useful for generating
@ -52,11 +49,14 @@ func (node *Node) Dump() string {
// performs the dispatch based on the two primal strings, cmd and args. Please // performs the dispatch based on the two primal strings, cmd and args. Please
// look at the dispatch table in parser.go to see how these dispatchers work. // look at the dispatch table in parser.go to see how these dispatchers work.
func fullDispatch(cmd, args string) (*Node, map[string]bool, error) { func fullDispatch(cmd, args string) (*Node, map[string]bool, error) {
if _, ok := dispatch[cmd]; !ok { fn := dispatch[cmd]
return nil, nil, fmt.Errorf("'%s' is not a valid dockerfile command", cmd)
// Ignore invalid Dockerfile instructions
if fn == nil {
fn = parseIgnore
} }
sexp, attrs, err := dispatch[cmd](args) sexp, attrs, err := fn(args)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }