mirror of https://github.com/docker/cli.git
Merge pull request #4346 from thaJeztah/build_errors
build: error if Dockerfile name is passed with Dockerfile from stdin
This commit is contained in:
commit
c96484a114
|
@ -34,8 +34,6 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var errStdinConflict = errors.New("invalid argument: can't use stdin for both build context and dockerfile")
|
||||
|
||||
type buildOptions struct {
|
||||
context string
|
||||
dockerfileName string
|
||||
|
@ -189,7 +187,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
|
|||
|
||||
if options.dockerfileFromStdin() {
|
||||
if options.contextFromStdin() {
|
||||
return errStdinConflict
|
||||
return errors.New("invalid argument: can't use stdin for both build context and dockerfile")
|
||||
}
|
||||
dockerfileCtx = dockerCli.In()
|
||||
}
|
||||
|
|
|
@ -155,6 +155,9 @@ func GetContextFromReader(rc io.ReadCloser, dockerfileName string) (out io.ReadC
|
|||
if dockerfileName == "-" {
|
||||
return nil, "", errors.New("build context is not an archive")
|
||||
}
|
||||
if dockerfileName != "" {
|
||||
return nil, "", errors.New("ambiguous Dockerfile source: both stdin and flag correspond to Dockerfiles")
|
||||
}
|
||||
|
||||
dockerfileDir, err := WriteTempDockerfile(rc)
|
||||
if err != nil {
|
||||
|
|
|
@ -152,6 +152,13 @@ func TestGetContextFromReaderString(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetContextFromReaderStringConflict(t *testing.T) {
|
||||
rdr, relDockerfile, err := GetContextFromReader(io.NopCloser(strings.NewReader(dockerfileContents)), "custom.Dockerfile")
|
||||
assert.Check(t, is.Equal(rdr, nil))
|
||||
assert.Check(t, is.Equal(relDockerfile, ""))
|
||||
assert.Check(t, is.ErrorContains(err, "ambiguous Dockerfile source: both stdin and flag correspond to Dockerfiles"))
|
||||
}
|
||||
|
||||
func TestGetContextFromReaderTar(t *testing.T) {
|
||||
contextDir := createTestTempDir(t)
|
||||
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents)
|
||||
|
|
Loading…
Reference in New Issue