|
@@ -1,7 +1,6 @@
|
|
package docker
|
|
package docker
|
|
|
|
|
|
import (
|
|
import (
|
|
- "bufio"
|
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
"github.com/dotcloud/docker/utils"
|
|
"github.com/dotcloud/docker/utils"
|
|
@@ -458,6 +457,9 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error {
|
|
return nil
|
|
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) {
|
|
func (b *buildFile) Build(context io.Reader) (string, error) {
|
|
// FIXME: @creack any reason for using /tmp instead of ""?
|
|
// FIXME: @creack any reason for using /tmp instead of ""?
|
|
// FIXME: @creack "name" is a terrible variable name
|
|
// 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)
|
|
defer os.RemoveAll(name)
|
|
b.context = 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")
|
|
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
|
|
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")
|
|
line = strings.Trim(strings.Replace(line, "\t", " ", -1), " \t\r\n")
|
|
// Skip comments and empty line
|
|
// Skip comments and empty line
|
|
if len(line) == 0 || line[0] == '#' {
|
|
if len(line) == 0 || line[0] == '#' {
|