Browse code

Convert Unused ARG error to warning

Signed-off-by: Addam Hardy <addam.hardy@gmail.com>

Addam Hardy authored on 2016/10/16 12:37:15
Showing 4 changed files
... ...
@@ -271,15 +271,16 @@ func (b *Builder) build(stdout io.Writer, stderr io.Writer, out io.Writer) (stri
271 271
 	}
272 272
 
273 273
 	// check if there are any leftover build-args that were passed but not
274
-	// consumed during build. Return an error, if there are any.
274
+	// consumed during build. Return a warning, if there are any.
275 275
 	leftoverArgs := []string{}
276 276
 	for arg := range b.options.BuildArgs {
277 277
 		if !b.isBuildArgAllowed(arg) {
278 278
 			leftoverArgs = append(leftoverArgs, arg)
279 279
 		}
280 280
 	}
281
+
281 282
 	if len(leftoverArgs) > 0 {
282
-		return "", fmt.Errorf("One or more build-args %v were not consumed, failing build.", leftoverArgs)
283
+		fmt.Fprintf(b.Stderr, "[Warning] One or more build-args %v were not consumed\n", leftoverArgs)
283 284
 	}
284 285
 
285 286
 	if b.image == "" {
... ...
@@ -1286,12 +1286,12 @@ to create the directory in the Dockerfile. For example:
1286 1286
     ARG <name>[=<default value>]
1287 1287
 
1288 1288
 The `ARG` instruction defines a variable that users can pass at build-time to
1289
-the builder with the `docker build` command using the
1290
-`--build-arg <varname>=<value>` flag. If a user specifies a build argument
1291
-that was not defined in the Dockerfile, the build outputs an error.
1289
+the builder with the `docker build` command using the `--build-arg
1290
+<varname>=<value>` flag. If a user specifies a build argument that was not
1291
+defined in the Dockerfile, the build outputs a warning.
1292 1292
 
1293 1293
 ```
1294
-One or more build-args were not consumed, failing build.
1294
+[Warning] One or more build-args [foo] were not consumed.
1295 1295
 ```
1296 1296
 
1297 1297
 The Dockerfile author can define a single variable by specifying `ARG` once or many
... ...
@@ -6056,11 +6056,12 @@ func (s *DockerSuite) TestBuildBuildTimeArgUnconsumedArg(c *check.C) {
6056 6056
 		RUN echo $%s
6057 6057
 		CMD echo $%s`, envKey, envKey)
6058 6058
 
6059
-	errStr := "One or more build-args"
6060
-	if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err == nil {
6061
-		c.Fatalf("build succeeded, expected to fail. Output: %v", out)
6062
-	} else if !strings.Contains(out, errStr) {
6063
-		c.Fatalf("Unexpected error. output: %q, expected error: %q", out, errStr)
6059
+	warnStr := "[Warning] One or more build-args"
6060
+
6061
+	if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); !strings.Contains(out, warnStr) {
6062
+		c.Fatalf("build completed without warning: %q %q", out, err)
6063
+	} else if err != nil {
6064
+		c.Fatalf("build failed to complete: %q %q", out, err)
6064 6065
 	}
6065 6066
 
6066 6067
 }
... ...
@@ -26,7 +26,7 @@ For example:
26 26
 
27 27
 # DESCRIPTION
28 28
 
29
-A Dockerfile is a file that automates the steps of creating a Docker image. 
29
+A Dockerfile is a file that automates the steps of creating a Docker image.
30 30
 A Dockerfile is similar to a Makefile.
31 31
 
32 32
 # USAGE
... ...
@@ -71,10 +71,10 @@ A Dockerfile is similar to a Makefile.
71 71
   multiple images. Make a note of the last image ID output by the commit before
72 72
   each new **FROM** command.
73 73
 
74
-  -- If no tag is given to the **FROM** instruction, Docker applies the 
74
+  -- If no tag is given to the **FROM** instruction, Docker applies the
75 75
   `latest` tag. If the used tag does not exist, an error is returned.
76 76
 
77
-  -- If no digest is given to the **FROM** instruction, Docker applies the 
77
+  -- If no digest is given to the **FROM** instruction, Docker applies the
78 78
   `latest` tag. If the used tag does not exist, an error is returned.
79 79
 
80 80
 **MAINTAINER**
... ...
@@ -148,7 +148,7 @@ A Dockerfile is similar to a Makefile.
148 148
   ```
149 149
 
150 150
   -- To make the container run the same executable every time, use **ENTRYPOINT** in
151
-  combination with **CMD**. 
151
+  combination with **CMD**.
152 152
   If the user specifies arguments to `docker run`, the specified commands
153 153
   override the default in **CMD**.
154 154
   Do not confuse **RUN** with **CMD**. **RUN** runs a command and commits the result.
... ...
@@ -156,7 +156,7 @@ A Dockerfile is similar to a Makefile.
156 156
   the image.
157 157
 
158 158
 **LABEL**
159
-  -- `LABEL <key>=<value> [<key>=<value> ...]`or 
159
+  -- `LABEL <key>=<value> [<key>=<value> ...]`or
160 160
   ```
161 161
   LABEL <key>[ <value>]
162 162
   LABEL <key>[ <value>]
... ...
@@ -176,8 +176,8 @@ A Dockerfile is similar to a Makefile.
176 176
   ```
177 177
 
178 178
   An image can have more than one label. To specify multiple labels, separate
179
-  each key-value pair by a space. 
180
-  
179
+  each key-value pair by a space.
180
+
181 181
   Labels are additive including `LABEL`s in `FROM` images. As the system
182 182
   encounters and then applies a new label, new `key`s override any previous
183 183
   labels with identical keys.
... ...
@@ -194,7 +194,7 @@ A Dockerfile is similar to a Makefile.
194 194
 **ENV**
195 195
   -- `ENV <key> <value>`
196 196
   The **ENV** instruction sets the environment variable <key> to
197
-  the value `<value>`. This value is passed to all future 
197
+  the value `<value>`. This value is passed to all future
198 198
   **RUN**, **ENTRYPOINT**, and **CMD** instructions. This is
199 199
   functionally equivalent to prefixing the command with `<key>=<value>`.  The
200 200
   environment variables that are set with **ENV** persist when a container is run
... ...
@@ -243,7 +243,7 @@ A Dockerfile is similar to a Makefile.
243 243
   being built (the context of the build) or a remote file URL. The `<dest>` is an
244 244
   absolute path, or a path relative to **WORKDIR**, into which the source will
245 245
   be copied inside the target container. If you **COPY** an archive file it will
246
-  land in the container exactly as it appears in the build context without any 
246
+  land in the container exactly as it appears in the build context without any
247 247
   attempt to unpack it.  All new files and directories are created with mode **0755**
248 248
   and with the uid and gid of **0**.
249 249
 
... ...
@@ -326,10 +326,10 @@ A Dockerfile is similar to a Makefile.
326 326
   The `ARG` instruction defines a variable that users can pass at build-time to
327 327
   the builder with the `docker build` command using the `--build-arg
328 328
   <varname>=<value>` flag. If a user specifies a build argument that was not
329
-  defined in the Dockerfile, the build outputs an error.
329
+  defined in the Dockerfile, the build outputs a warning.
330 330
 
331 331
   ```
332
-  One or more build-args were not consumed, failing build.
332
+  [Warning] One or more build-args [foo] were not consumed
333 333
   ```
334 334
 
335 335
   The Dockerfile author can define a single variable by specifying `ARG` once or many
... ...
@@ -454,7 +454,7 @@ A Dockerfile is similar to a Makefile.
454 454
   you are defining an image to use as a base for building other images. For
455 455
   example, if you are defining an application build environment or a daemon that
456 456
   is customized with a user-specific configuration.  
457
-  
457
+
458 458
   Consider an image intended as a reusable python application builder. It must
459 459
   add application source code to a particular directory, and might need a build
460 460
   script called after that. You can't just call **ADD** and **RUN** now, because
... ...
@@ -470,4 +470,5 @@ A Dockerfile is similar to a Makefile.
470 470
 # HISTORY
471 471
 *May 2014, Compiled by Zac Dover (zdover at redhat dot com) based on docker.com Dockerfile documentation.
472 472
 *Feb 2015, updated by Brian Goff (cpuguy83@gmail.com) for readability
473
-*Sept 2015, updated by Sally O'Malley (somalley@redhat.com) 
473
+*Sept 2015, updated by Sally O'Malley (somalley@redhat.com)
474
+*Oct 2016, updated by Addam Hardy (addam.hardy@gmail.com)