diff --git a/api_test.go b/api_test.go index e070f02ba8..d24cf7cfda 100644 --- a/api_test.go +++ b/api_test.go @@ -445,7 +445,7 @@ func TestGetContainersChanges(t *testing.T) { } func TestGetContainersTop(t *testing.T) { - t.Skip("Fixme. Skipping test for now. Reported error when testing using dind: 'api_test.go:527: Expected 2 processes, found 0.'") + t.Skip("Fixme. Skipping test for now. Reported error when testing using dind: 'api_test.go:527: Expected 2 processes, found 0.'") runtime, err := newTestRuntime() if err != nil { t.Fatal(err) diff --git a/buildfile.go b/buildfile.go index c5878cf4d0..fcb5abae47 100644 --- a/buildfile.go +++ b/buildfile.go @@ -1,7 +1,6 @@ package docker import ( - "bufio" "encoding/json" "fmt" "github.com/dotcloud/docker/utils" @@ -458,6 +457,9 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error { return nil } +// Long lines can be split with a backslash +var lineContinuation = regexp.MustCompile(`\s*\\\s*\n`) + func (b *buildFile) Build(context io.Reader) (string, error) { // FIXME: @creack any reason for using /tmp instead of ""? // FIXME: @creack "name" is a terrible variable name @@ -470,22 +472,18 @@ func (b *buildFile) Build(context io.Reader) (string, error) { } defer os.RemoveAll(name) b.context = name - dockerfile, err := os.Open(path.Join(name, "Dockerfile")) - if err != nil { + filename := path.Join(name, "Dockerfile") + if _, err := os.Stat(filename); os.IsNotExist(err) { return "", fmt.Errorf("Can't build a directory with no Dockerfile") } - // FIXME: "file" is also a terrible variable name ;) - file := bufio.NewReader(dockerfile) + fileBytes, err := ioutil.ReadFile(filename) + if err != nil { + return "", err + } + dockerfile := string(fileBytes) + dockerfile = lineContinuation.ReplaceAllString(dockerfile, " ") stepN := 0 - for { - line, err := file.ReadString('\n') - if err != nil { - if err == io.EOF && line == "" { - break - } else if err != io.EOF { - return "", err - } - } + for _, line := range strings.Split(dockerfile, "\n") { line = strings.Trim(strings.Replace(line, "\t", " ", -1), " \t\r\n") // Skip comments and empty line if len(line) == 0 || line[0] == '#' { diff --git a/buildfile_test.go b/buildfile_test.go index a204240d3a..995b5b9f38 100644 --- a/buildfile_test.go +++ b/buildfile_test.go @@ -45,6 +45,34 @@ run [ "$(ls -d /var/run/sshd)" = "/var/run/sshd" ] nil, }, + // Exactly the same as above, except uses a line split with a \ to test + // multiline support. + { + ` +from {IMAGE} +run sh -c 'echo root:testpass \ + > /tmp/passwd' +run mkdir -p /var/run/sshd +run [ "$(cat /tmp/passwd)" = "root:testpass" ] +run [ "$(ls -d /var/run/sshd)" = "/var/run/sshd" ] +`, + nil, + nil, + }, + + // Line containing literal "\n" + { + ` +from {IMAGE} +run sh -c 'echo root:testpass > /tmp/passwd' +run echo "foo \n bar"; echo "baz" +run mkdir -p /var/run/sshd +run [ "$(cat /tmp/passwd)" = "root:testpass" ] +run [ "$(ls -d /var/run/sshd)" = "/var/run/sshd" ] +`, + nil, + nil, + }, { ` from {IMAGE} diff --git a/utils/utils_test.go b/utils/utils_test.go index be796b2381..9a55e7f62d 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -366,7 +366,6 @@ func TestParseRelease(t *testing.T) { assertParseRelease(t, "3.8.0-19-generic", &KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0, Flavor: "19-generic"}, 0) } - func TestDependencyGraphCircular(t *testing.T) { g1 := NewDependencyGraph() a := g1.NewNode("a") @@ -421,4 +420,4 @@ func TestDependencyGraph(t *testing.T) { if len(res[2]) != 1 || res[2][0] != "d" { t.Fatalf("Expected [d], found %v instead", res[2]) } -} \ No newline at end of file +}