Browse code

Merge pull request #8434 from tiborvass/ignore_invalid_Dockerfile_instructions

Ignore unknown dockerfile instructions

Jessie Frazelle authored on 2014/10/08 06:45:51
Showing 5 changed files
... ...
@@ -45,21 +45,20 @@ var evaluateTable map[string]func(*Builder, []string, map[string]bool) error
45 45
 
46 46
 func init() {
47 47
 	evaluateTable = map[string]func(*Builder, []string, map[string]bool) error{
48
-		"env":            env,
49
-		"maintainer":     maintainer,
50
-		"add":            add,
51
-		"copy":           dispatchCopy, // copy() is a go builtin
52
-		"from":           from,
53
-		"onbuild":        onbuild,
54
-		"workdir":        workdir,
55
-		"docker-version": nullDispatch, // we don't care about docker-version
56
-		"run":            run,
57
-		"cmd":            cmd,
58
-		"entrypoint":     entrypoint,
59
-		"expose":         expose,
60
-		"volume":         volume,
61
-		"user":           user,
62
-		"insert":         insert,
48
+		"env":        env,
49
+		"maintainer": maintainer,
50
+		"add":        add,
51
+		"copy":       dispatchCopy, // copy() is a go builtin
52
+		"from":       from,
53
+		"onbuild":    onbuild,
54
+		"workdir":    workdir,
55
+		"run":        run,
56
+		"cmd":        cmd,
57
+		"entrypoint": entrypoint,
58
+		"expose":     expose,
59
+		"volume":     volume,
60
+		"user":       user,
61
+		"insert":     insert,
63 62
 	}
64 63
 }
65 64
 
... ...
@@ -43,21 +43,20 @@ func init() {
43 43
 	// functions. Errors are propogated up by Parse() and the resulting AST can
44 44
 	// be incorporated directly into the existing AST as a next.
45 45
 	dispatch = map[string]func(string) (*Node, map[string]bool, error){
46
-		"user":           parseString,
47
-		"onbuild":        parseSubCommand,
48
-		"workdir":        parseString,
49
-		"env":            parseEnv,
50
-		"maintainer":     parseString,
51
-		"docker-version": parseString,
52
-		"from":           parseString,
53
-		"add":            parseStringsWhitespaceDelimited,
54
-		"copy":           parseStringsWhitespaceDelimited,
55
-		"run":            parseMaybeJSON,
56
-		"cmd":            parseMaybeJSON,
57
-		"entrypoint":     parseMaybeJSON,
58
-		"expose":         parseStringsWhitespaceDelimited,
59
-		"volume":         parseMaybeJSONToList,
60
-		"insert":         parseIgnore,
46
+		"user":       parseString,
47
+		"onbuild":    parseSubCommand,
48
+		"workdir":    parseString,
49
+		"env":        parseEnv,
50
+		"maintainer": parseString,
51
+		"from":       parseString,
52
+		"add":        parseStringsWhitespaceDelimited,
53
+		"copy":       parseStringsWhitespaceDelimited,
54
+		"run":        parseMaybeJSON,
55
+		"cmd":        parseMaybeJSON,
56
+		"entrypoint": parseMaybeJSON,
57
+		"expose":     parseStringsWhitespaceDelimited,
58
+		"volume":     parseMaybeJSONToList,
59
+		"insert":     parseIgnore,
61 60
 	}
62 61
 }
63 62
 
... ...
@@ -1,4 +1,4 @@
1
-(docker-version "0.6.1")
1
+(docker-version)
2 2
 (from "ubuntu:14.04")
3 3
 (maintainer "Tianon Gravi <admwiggin@gmail.com> (@tianon)")
4 4
 (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")
... ...
@@ -1,9 +1,6 @@
1 1
 package parser
2 2
 
3
-import (
4
-	"fmt"
5
-	"strings"
6
-)
3
+import "strings"
7 4
 
8 5
 // QuoteString walks characters (after trimming), escapes any quotes and
9 6
 // escapes, then wraps the whole thing in quotes. Very useful for generating
... ...
@@ -52,11 +49,14 @@ func (node *Node) Dump() string {
52 52
 // performs the dispatch based on the two primal strings, cmd and args. Please
53 53
 // look at the dispatch table in parser.go to see how these dispatchers work.
54 54
 func fullDispatch(cmd, args string) (*Node, map[string]bool, error) {
55
-	if _, ok := dispatch[cmd]; !ok {
56
-		return nil, nil, fmt.Errorf("'%s' is not a valid dockerfile command", cmd)
55
+	fn := dispatch[cmd]
56
+
57
+	// Ignore invalid Dockerfile instructions
58
+	if fn == nil {
59
+		fn = parseIgnore
57 60
 	}
58 61
 
59
-	sexp, attrs, err := dispatch[cmd](args)
62
+	sexp, attrs, err := fn(args)
60 63
 	if err != nil {
61 64
 		return nil, nil, err
62 65
 	}
... ...
@@ -2447,3 +2447,15 @@ func TestBuildCmdJSONNoShDashC(t *testing.T) {
2447 2447
 
2448 2448
 	logDone("build - cmd should not have /bin/sh -c for json")
2449 2449
 }
2450
+
2451
+func TestBuildIgnoreInvalidInstruction(t *testing.T) {
2452
+	name := "testbuildignoreinvalidinstruction"
2453
+	defer deleteImages(name)
2454
+
2455
+	out, _, err := buildImageWithOut(name, "FROM busybox\nfoo bar", true)
2456
+	if err != nil {
2457
+		t.Fatal(err, out)
2458
+	}
2459
+
2460
+	logDone("build - ignore invalid Dockerfile instruction")
2461
+}