소스 검색

Merge pull request #3294 from discordianfish/3293-better-error-dockerfile-empty

Return error if Dockerfile is empty
Michael Crosby 11 년 전
부모
커밋
57e19b1475
2개의 변경된 파일16개의 추가작업 그리고 0개의 파일을 삭제
  1. 8 0
      buildfile.go
  2. 8 0
      integration/buildfile_test.go

+ 8 - 0
buildfile.go

@@ -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

+ 8 - 0
integration/buildfile_test.go

@@ -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)
+	}
+}