mirror of https://github.com/docker/docs.git
Return error if Dockerfile is empty
This commit is contained in:
parent
efde305c05
commit
f7ba1c34bb
|
@ -2,6 +2,7 @@ package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/archive"
|
"github.com/dotcloud/docker/archive"
|
||||||
"github.com/dotcloud/docker/auth"
|
"github.com/dotcloud/docker/auth"
|
||||||
|
@ -16,6 +17,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrDockerfileEmpty = errors.New("Dockerfile cannot be empty")
|
||||||
|
)
|
||||||
|
|
||||||
type BuildFile interface {
|
type BuildFile interface {
|
||||||
Build(io.Reader) (string, error)
|
Build(io.Reader) (string, error)
|
||||||
CmdFrom(string) error
|
CmdFrom(string) error
|
||||||
|
@ -529,6 +534,9 @@ func (b *buildFile) Build(context io.Reader) (string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
if len(fileBytes) == 0 {
|
||||||
|
return "", ErrDockerfileEmpty
|
||||||
|
}
|
||||||
dockerfile := string(fileBytes)
|
dockerfile := string(fileBytes)
|
||||||
dockerfile = lineContinuation.ReplaceAllString(dockerfile, "")
|
dockerfile = lineContinuation.ReplaceAllString(dockerfile, "")
|
||||||
stepN := 0
|
stepN := 0
|
||||||
|
|
|
@ -630,3 +630,11 @@ func TestBuildFails(t *testing.T) {
|
||||||
t.Fatalf("StatusCode %d unexpected, should be 23", sterr.Code)
|
t.Fatalf("StatusCode %d unexpected, should be 23", sterr.Code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildFailsDockerfileEmpty(t *testing.T) {
|
||||||
|
_, err := buildImage(testContextTemplate{``, nil, nil}, t, nil, true)
|
||||||
|
|
||||||
|
if err != docker.ErrDockerfileEmpty {
|
||||||
|
t.Fatal("Expected: %v, got: %v", docker.ErrDockerfileEmpty, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue