mirror of https://github.com/docker/cli.git
build: error if Dockerfile name is passed with Dockerfile from stdin
When passing a Dockerfile through stdin, it's not possible to specify the name of the Dockerfile (using the `-f` option). When building with BuildKit enabled, an error is already produced for this case, but the classic builder silently ignored it. This patch adds an error for this situation: echo -e 'FROM busybox' | DOCKER_BUILDKIT=0 docker build -f some.Dockerfile - DEPRECATED: The legacy builder is deprecated and will be removed in a future release. BuildKit is currently disabled; enable it by removing the DOCKER_BUILDKIT=0 environment-variable. unable to prepare context: ambiguous Dockerfile source: both stdin and flag correspond to Dockerfiles Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
77dd05caad
commit
c2535aa467
|
@ -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