Skip to content

Commit c4618fb

Browse files
addamhruncom
authored andcommitted
BACKPORT: Convert Unused ARG error to warning
Upstream reference: moby@f150f42 Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1478024 Signed-off-by: Addam Hardy <addam.hardy@gmail.com> Signed-off-by: Antonio Murdaca <runcom@redhat.com>
1 parent 7b609eb commit c4618fb

4 files changed

Lines changed: 27 additions & 24 deletions

File tree

builder/dockerfile/builder.go

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

259259
// check if there are any leftover build-args that were passed but not
260-
// consumed during build. Return an error, if there are any.
260+
// consumed during build. Return a warning, if there are any.
261261
leftoverArgs := []string{}
262262
for arg := range b.options.BuildArgs {
263263
if !b.isBuildArgAllowed(arg) {
264264
leftoverArgs = append(leftoverArgs, arg)
265265
}
266266
}
267+
267268
if len(leftoverArgs) > 0 {
268-
return "", fmt.Errorf("One or more build-args %v were not consumed, failing build.", leftoverArgs)
269+
fmt.Fprintf(b.Stderr, "[Warning] One or more build-args %v were not consumed\n", leftoverArgs)
269270
}
270271

271272
if b.image == "" {

docs/reference/builder.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,12 +1245,12 @@ The output of the final `pwd` command in this `Dockerfile` would be
12451245
ARG <name>[=<default value>]
12461246

12471247
The `ARG` instruction defines a variable that users can pass at build-time to
1248-
the builder with the `docker build` command using the
1249-
`--build-arg <varname>=<value>` flag. If a user specifies a build argument
1250-
that was not defined in the Dockerfile, the build outputs an error.
1248+
the builder with the `docker build` command using the `--build-arg
1249+
<varname>=<value>` flag. If a user specifies a build argument that was not
1250+
defined in the Dockerfile, the build outputs a warning.
12511251

12521252
```
1253-
One or more build-args were not consumed, failing build.
1253+
[Warning] One or more build-args [foo] were not consumed.
12541254
```
12551255

12561256
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
@@ -6109,11 +6109,12 @@ func (s *DockerSuite) TestBuildBuildTimeArgUnconsumedArg(c *check.C) {
61096109
RUN echo $%s
61106110
CMD echo $%s`, envKey, envKey)
61116111

6112-
errStr := "One or more build-args"
6113-
if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err == nil {
6114-
c.Fatalf("build succeeded, expected to fail. Output: %v", out)
6115-
} else if !strings.Contains(out, errStr) {
6116-
c.Fatalf("Unexpected error. output: %q, expected error: %q", out, errStr)
6112+
warnStr := "[Warning] One or more build-args"
6113+
6114+
if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); !strings.Contains(out, warnStr) {
6115+
c.Fatalf("build completed without warning: %q %q", out, err)
6116+
} else if err != nil {
6117+
c.Fatalf("build failed to complete: %q %q", out, err)
61176118
}
61186119

61196120
}

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)