Return error if Dockerfile is empty
This commit is contained in:
parent
efde305c05
commit
f7ba1c34bb
2 changed files with 16 additions and 0 deletions
|
@ -2,6 +2,7 @@ package docker
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/dotcloud/docker/archive"
|
||||
"github.com/dotcloud/docker/auth"
|
||||
|
@ -16,6 +17,10 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrDockerfileEmpty = errors.New("Dockerfile cannot be empty")
|
||||
)
|
||||
|
||||
type BuildFile interface {
|
||||
Build(io.Reader) (string, error)
|
||||
CmdFrom(string) error
|
||||
|
@ -529,6 +534,9 @@ func (b *buildFile) Build(context io.Reader) (string, error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(fileBytes) == 0 {
|
||||
return "", ErrDockerfileEmpty
|
||||
}
|
||||
dockerfile := string(fileBytes)
|
||||
dockerfile = lineContinuation.ReplaceAllString(dockerfile, "")
|
||||
stepN := 0
|
||||
|
|
|
@ -630,3 +630,11 @@ func TestBuildFails(t *testing.T) {
|
|||
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 a new issue