Browse code

Revert "Fix dockerfile parser with empty line after escape"

This reverts commit 3e1b539e8d0ed4abf695b0a8c42346fba6d5a6b0.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 6e0666e622a8b1fc19c19eb490d218eebca15edc)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>

Vincent Demeester authored on 2016/12/02 22:15:55
Showing 11 changed files
... ...
@@ -176,17 +176,10 @@ func Parse(rwc io.Reader, d *Directive) (*Node, error) {
176 176
 				newline := scanner.Text()
177 177
 				currentLine++
178 178
 
179
-				// If escape followed by a comment line then stop
180
-				// Note here that comment line starts with `#` at
181
-				// the first pos of the line
182
-				if stripComments(newline) == "" {
183
-					break
179
+				if stripComments(strings.TrimSpace(newline)) == "" {
180
+					continue
184 181
 				}
185 182
 
186
-				// If escape followed by an empty line then stop
187
-				if strings.TrimSpace(newline) == "" {
188
-					break
189
-				}
190 183
 				line, child, err = ParseLine(line+newline, d, false)
191 184
 				if err != nil {
192 185
 					return nil, err
... ...
@@ -150,8 +150,8 @@ func TestLineInformation(t *testing.T) {
150 150
 		t.Fatalf("Error parsing dockerfile %s: %v", testFileLineInfo, err)
151 151
 	}
152 152
 
153
-	if ast.StartLine != 5 || ast.EndLine != 27 {
154
-		fmt.Fprintf(os.Stderr, "Wrong root line information: expected(%d-%d), actual(%d-%d)\n", 5, 27, ast.StartLine, ast.EndLine)
153
+	if ast.StartLine != 5 || ast.EndLine != 31 {
154
+		fmt.Fprintf(os.Stderr, "Wrong root line information: expected(%d-%d), actual(%d-%d)\n", 5, 31, ast.StartLine, ast.EndLine)
155 155
 		t.Fatalf("Root line information doesn't match result.")
156 156
 	}
157 157
 	if len(ast.Children) != 3 {
... ...
@@ -161,7 +161,7 @@ func TestLineInformation(t *testing.T) {
161 161
 	expected := [][]int{
162 162
 		{5, 5},
163 163
 		{11, 12},
164
-		{17, 27},
164
+		{17, 31},
165 165
 	}
166 166
 	for i, child := range ast.Children {
167 167
 		if child.StartLine != expected[i][0] || child.EndLine != expected[i][1] {
... ...
@@ -16,11 +16,15 @@ ENV GOPATH \
16 16
 # Install the packages we need, clean up after them and us
17 17
 RUN apt-get update \
18 18
 	&& dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.clean \
19
+
20
+
19 21
     && apt-get install -y --no-install-recommends git golang ca-certificates \
20 22
     && apt-get clean \
21 23
     && rm -rf /var/lib/apt/lists \
24
+
22 25
 	&& go get -v github.com/brimstone/consuldock \
23 26
     && mv $GOPATH/bin/consuldock /usr/local/bin/consuldock \
27
+
24 28
 	&& dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.dirty \
25 29
 	&& apt-get remove --purge -y $(diff /tmp/dpkg.clean /tmp/dpkg.dirty | awk '/^>/ {print $2}') \
26 30
 	&& rm /tmp/dpkg.* \
... ...
@@ -16,8 +16,10 @@ RUN apt-get update \
16 16
     && apt-get install -y --no-install-recommends git golang ca-certificates \
17 17
     && apt-get clean \
18 18
     && rm -rf /var/lib/apt/lists \
19
+
19 20
 	&& go get -v github.com/brimstone/consuldock \
20 21
     && mv $GOPATH/bin/consuldock /usr/local/bin/consuldock \
22
+
21 23
 	&& dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.dirty \
22 24
 	&& apt-get remove --purge -y $(diff /tmp/dpkg.clean /tmp/dpkg.dirty | awk '/^>/ {print $2}') \
23 25
 	&& rm /tmp/dpkg.* \
... ...
@@ -23,12 +23,14 @@ RUN apt-get update \
23 23
     && apt-get install -y --no-install-recommends unzip wget \
24 24
     && apt-get clean \
25 25
     && rm -rf /var/lib/apt/lists \
26
+
26 27
     && cd /tmp \
27 28
     && wget https://dl.bintray.com/mitchellh/consul/0.3.1_web_ui.zip \
28 29
        -O web_ui.zip \
29 30
     && unzip web_ui.zip \
30 31
     && mv dist /webui \
31 32
     && rm web_ui.zip \
33
+
32 34
 	&& dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.dirty \
33 35
 	&& apt-get remove --purge -y $(diff /tmp/dpkg.clean /tmp/dpkg.dirty | awk '/^>/ {print $2}') \
34 36
 	&& rm /tmp/dpkg.*
... ...
@@ -40,8 +42,10 @@ RUN apt-get update \
40 40
     && apt-get install -y --no-install-recommends git golang ca-certificates build-essential \
41 41
     && apt-get clean \
42 42
     && rm -rf /var/lib/apt/lists \
43
+
43 44
 	&& go get -v github.com/hashicorp/consul \
44 45
 	&& mv $GOPATH/bin/consul /usr/bin/consul \
46
+
45 47
 	&& dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.dirty \
46 48
 	&& apt-get remove --purge -y $(diff /tmp/dpkg.clean /tmp/dpkg.dirty | awk '/^>/ {print $2}') \
47 49
 	&& rm /tmp/dpkg.* \
... ...
@@ -27,5 +27,8 @@ bye\
27 27
 frog
28 28
 
29 29
 RUN echo hello \
30
-# this is a comment that breaks escape continuation
31
-RUN echo this is some more useful stuff
30
+# this is a comment
31
+
32
+# this is a comment with a blank line surrounding it
33
+
34
+this is some more useful stuff
... ...
@@ -6,5 +6,4 @@
6 6
 (run "echo hi   world  goodnight")
7 7
 (run "echo goodbyefrog")
8 8
 (run "echo goodbyefrog")
9
-(run "echo hello")
10
-(run "echo this is some more useful stuff")
9
+(run "echo hello this is some more useful stuff")
11 10
deleted file mode 100644
... ...
@@ -1,15 +0,0 @@
1
-FROM busybox
2
-
3
-# The following will create two instructions
4
-# `Run foo`
5
-# `bar`
6
-# because empty line will break the escape.
7
-# The parser will generate the following:
8
-# (from "busybox")
9
-# (run "foo")
10
-# (bar "")
11
-# And `bar` will return an error instruction later
12
-# Note: Parse() will not immediately error out.
13
-RUN foo \
14
-
15
-bar
16 1
deleted file mode 100644
... ...
@@ -1,3 +0,0 @@
1
-(from "busybox")
2
-(run "foo")
3
-(bar "")
... ...
@@ -6,7 +6,9 @@ RUN apt-get \update && \
6 6
 ADD \conf\\" /.znc
7 7
 
8 8
 RUN foo \
9
+
9 10
 bar \
11
+
10 12
 baz
11 13
 
12 14
 CMD [ "\/usr\\\"/bin/znc", "-f", "-r" ]
... ...
@@ -3610,8 +3610,8 @@ RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1001:1001/do
3610 3610
 
3611 3611
 # Switch back to root and double check that worked exactly as we might expect it to
3612 3612
 USER root
3613
-# Add a "supplementary" group for our dockerio user
3614 3613
 RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '0:0/root:root/0 10:root wheel' ] && \
3614
+        # Add a "supplementary" group for our dockerio user
3615 3615
 	echo 'supplementary:x:1002:dockerio' >> /etc/group
3616 3616
 
3617 3617
 # ... and then go verify that we get it like we expect
... ...
@@ -7141,41 +7141,6 @@ func (s *DockerSuite) TestBuildNetContainer(c *check.C) {
7141 7141
 	c.Assert(strings.TrimSpace(host), check.Equals, "foobar")
7142 7142
 }
7143 7143
 
7144
-// Test case for #24693
7145
-func (s *DockerSuite) TestBuildRunEmptyLineAfterEscape(c *check.C) {
7146
-	name := "testbuildemptylineafterescape"
7147
-	_, out, err := buildImageWithOut(name,
7148
-		`
7149
-FROM busybox
7150
-RUN echo x \
7151
-
7152
-RUN echo y
7153
-RUN echo z
7154
-# Comment requires the '#' to start from position 1
7155
-# RUN echo w
7156
-`, true)
7157
-	c.Assert(err, checker.IsNil)
7158
-	c.Assert(out, checker.Contains, "Step 1/4 : FROM busybox")
7159
-	c.Assert(out, checker.Contains, "Step 2/4 : RUN echo x")
7160
-	c.Assert(out, checker.Contains, "Step 3/4 : RUN echo y")
7161
-	c.Assert(out, checker.Contains, "Step 4/4 : RUN echo z")
7162
-
7163
-	// With comment, see #24693
7164
-	name = "testbuildcommentandemptylineafterescape"
7165
-	_, out, err = buildImageWithOut(name,
7166
-		`
7167
-FROM busybox
7168
-RUN echo grafana && \
7169
-    echo raintank \
7170
-#echo env-load
7171
-RUN echo vegeta
7172
-`, true)
7173
-	c.Assert(err, checker.IsNil)
7174
-	c.Assert(out, checker.Contains, "Step 1/3 : FROM busybox")
7175
-	c.Assert(out, checker.Contains, "Step 2/3 : RUN echo grafana &&     echo raintank")
7176
-	c.Assert(out, checker.Contains, "Step 3/3 : RUN echo vegeta")
7177
-}
7178
-
7179 7144
 func (s *DockerSuite) TestBuildSquashParent(c *check.C) {
7180 7145
 	testRequires(c, ExperimentalDaemon)
7181 7146
 	dockerFile := `