Skip to content

Commit f150f42

Browse files
committed
Convert Unused ARG error to warning
Signed-off-by: Addam Hardy <addam.hardy@gmail.com>
1 parent d8d3314 commit f150f42

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

builder/dockerfile/builder.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,16 @@ func (b *Builder) build(stdout io.Writer, stderr io.Writer, out io.Writer) (stri
271271
}
272272

273273
// 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.
275275
leftoverArgs := []string{}
276276
for arg := range b.options.BuildArgs {
277277
if !b.isBuildArgAllowed(arg) {
278278
leftoverArgs = append(leftoverArgs, arg)
279279
}
280280
}
281+
281282
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)
283284
}
284285

285286
if b.image == "" {

docs/reference/builder.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,12 +1286,12 @@ to create the directory in the Dockerfile. For example:
12861286
ARG <name>[=<default value>]
12871287

12881288
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.
12921292

12931293
```
1294-
One or more build-args were not consumed, failing build.
1294+
[Warning] One or more build-args [foo] were not consumed.
12951295
```
12961296

12971297
The Dockerfile author can define a single variable by specifying `ARG` once or many

integration-cli/docker_cli_build_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6056,11 +6056,12 @@ func (s *DockerSuite) TestBuildBuildTimeArgUnconsumedArg(c *check.C) {
60566056
RUN echo $%s
60576057
CMD echo $%s`, envKey, envKey)
60586058

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)
60646065
}
60656066

60666067
}

man/Dockerfile.5.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ For example:
2626

2727
# DESCRIPTION
2828

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.
3030
A Dockerfile is similar to a Makefile.
3131

3232
# USAGE
@@ -71,10 +71,10 @@ A Dockerfile is similar to a Makefile.
7171
multiple images. Make a note of the last image ID output by the commit before
7272
each new **FROM** command.
7373

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
7575
`latest` tag. If the used tag does not exist, an error is returned.
7676

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
7878
`latest` tag. If the used tag does not exist, an error is returned.
7979

8080
**MAINTAINER**
@@ -148,15 +148,15 @@ A Dockerfile is similar to a Makefile.
148148
```
149149

150150
-- To make the container run the same executable every time, use **ENTRYPOINT** in
151-
combination with **CMD**.
151+
combination with **CMD**.
152152
If the user specifies arguments to `docker run`, the specified commands
153153
override the default in **CMD**.
154154
Do not confuse **RUN** with **CMD**. **RUN** runs a command and commits the result.
155155
**CMD** executes nothing at build time, but specifies the intended command for
156156
the image.
157157

158158
**LABEL**
159-
-- `LABEL <key>=<value> [<key>=<value> ...]`or
159+
-- `LABEL <key>=<value> [<key>=<value> ...]`or
160160
```
161161
LABEL <key>[ <value>]
162162
LABEL <key>[ <value>]
@@ -176,8 +176,8 @@ A Dockerfile is similar to a Makefile.
176176
```
177177

178178
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+
181181
Labels are additive including `LABEL`s in `FROM` images. As the system
182182
encounters and then applies a new label, new `key`s override any previous
183183
labels with identical keys.
@@ -194,7 +194,7 @@ A Dockerfile is similar to a Makefile.
194194
**ENV**
195195
-- `ENV <key> <value>`
196196
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
198198
**RUN**, **ENTRYPOINT**, and **CMD** instructions. This is
199199
functionally equivalent to prefixing the command with `<key>=<value>`. The
200200
environment variables that are set with **ENV** persist when a container is run
@@ -243,7 +243,7 @@ A Dockerfile is similar to a Makefile.
243243
being built (the context of the build) or a remote file URL. The `<dest>` is an
244244
absolute path, or a path relative to **WORKDIR**, into which the source will
245245
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
247247
attempt to unpack it. All new files and directories are created with mode **0755**
248248
and with the uid and gid of **0**.
249249

@@ -326,10 +326,10 @@ A Dockerfile is similar to a Makefile.
326326
The `ARG` instruction defines a variable that users can pass at build-time to
327327
the builder with the `docker build` command using the `--build-arg
328328
<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.
330330

331331
```
332-
One or more build-args were not consumed, failing build.
332+
[Warning] One or more build-args [foo] were not consumed
333333
```
334334

335335
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.
454454
you are defining an image to use as a base for building other images. For
455455
example, if you are defining an application build environment or a daemon that
456456
is customized with a user-specific configuration.
457-
457+
458458
Consider an image intended as a reusable python application builder. It must
459459
add application source code to a particular directory, and might need a build
460460
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.
470470
# HISTORY
471471
*May 2014, Compiled by Zac Dover (zdover at redhat dot com) based on docker.com Dockerfile documentation.
472472
*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)

0 commit comments

Comments
 (0)