mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #27412 from loftylabs/26249-make-unused-args-warning
Convert Unused ARG error to warning
This commit is contained in:
commit
f8d5d65fb8
4 changed files with 27 additions and 24 deletions
|
@ -271,15 +271,16 @@ func (b *Builder) build(stdout io.Writer, stderr io.Writer, out io.Writer) (stri
|
|||
}
|
||||
|
||||
// check if there are any leftover build-args that were passed but not
|
||||
// consumed during build. Return an error, if there are any.
|
||||
// consumed during build. Return a warning, if there are any.
|
||||
leftoverArgs := []string{}
|
||||
for arg := range b.options.BuildArgs {
|
||||
if !b.isBuildArgAllowed(arg) {
|
||||
leftoverArgs = append(leftoverArgs, arg)
|
||||
}
|
||||
}
|
||||
|
||||
if len(leftoverArgs) > 0 {
|
||||
return "", fmt.Errorf("One or more build-args %v were not consumed, failing build.", leftoverArgs)
|
||||
fmt.Fprintf(b.Stderr, "[Warning] One or more build-args %v were not consumed\n", leftoverArgs)
|
||||
}
|
||||
|
||||
if b.image == "" {
|
||||
|
|
|
@ -1286,12 +1286,12 @@ to create the directory in the Dockerfile. For example:
|
|||
ARG <name>[=<default value>]
|
||||
|
||||
The `ARG` instruction defines a variable that users can pass at build-time to
|
||||
the builder with the `docker build` command using the
|
||||
`--build-arg <varname>=<value>` flag. If a user specifies a build argument
|
||||
that was not defined in the Dockerfile, the build outputs an error.
|
||||
the builder with the `docker build` command using the `--build-arg
|
||||
<varname>=<value>` flag. If a user specifies a build argument that was not
|
||||
defined in the Dockerfile, the build outputs a warning.
|
||||
|
||||
```
|
||||
One or more build-args were not consumed, failing build.
|
||||
[Warning] One or more build-args [foo] were not consumed.
|
||||
```
|
||||
|
||||
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) {
|
|||
RUN echo $%s
|
||||
CMD echo $%s`, envKey, envKey)
|
||||
|
||||
errStr := "One or more build-args"
|
||||
if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err == nil {
|
||||
c.Fatalf("build succeeded, expected to fail. Output: %v", out)
|
||||
} else if !strings.Contains(out, errStr) {
|
||||
c.Fatalf("Unexpected error. output: %q, expected error: %q", out, errStr)
|
||||
warnStr := "[Warning] One or more build-args"
|
||||
|
||||
if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); !strings.Contains(out, warnStr) {
|
||||
c.Fatalf("build completed without warning: %q %q", out, err)
|
||||
} else if err != nil {
|
||||
c.Fatalf("build failed to complete: %q %q", out, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -326,10 +326,10 @@ A Dockerfile is similar to a Makefile.
|
|||
The `ARG` instruction defines a variable that users can pass at build-time to
|
||||
the builder with the `docker build` command using the `--build-arg
|
||||
<varname>=<value>` flag. If a user specifies a build argument that was not
|
||||
defined in the Dockerfile, the build outputs an error.
|
||||
defined in the Dockerfile, the build outputs a warning.
|
||||
|
||||
```
|
||||
One or more build-args were not consumed, failing build.
|
||||
[Warning] One or more build-args [foo] were not consumed
|
||||
```
|
||||
|
||||
The Dockerfile author can define a single variable by specifying `ARG` once or many
|
||||
|
@ -471,3 +471,4 @@ A Dockerfile is similar to a Makefile.
|
|||
*May 2014, Compiled by Zac Dover (zdover at redhat dot com) based on docker.com Dockerfile documentation.
|
||||
*Feb 2015, updated by Brian Goff (cpuguy83@gmail.com) for readability
|
||||
*Sept 2015, updated by Sally O'Malley (somalley@redhat.com)
|
||||
*Oct 2016, updated by Addam Hardy (addam.hardy@gmail.com)
|
||||
|
|
Loading…
Add table
Reference in a new issue