diff --git a/api.go b/api.go index 94dd94c404..58125c934e 100644 --- a/api.go +++ b/api.go @@ -10,6 +10,9 @@ import ( "io/ioutil" "log" "net/http" + "os" + "os/exec" + "path" "strconv" "strings" ) @@ -684,7 +687,7 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ repoName = remoteParts[0] } - var dockerfile, context io.ReadCloser + var dockerfile, context io.Reader if remoteURL == "" { d, _, err := r.FormFile("Dockerfile") @@ -703,7 +706,36 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ } } else { if utils.IsGIT(remoteURL) { - return fmt.Errorf("Builder from git is not yet supported") + if !strings.HasPrefix(remoteURL, "git://") { + remoteURL = "https://" + remoteURL + } + root, err := ioutil.TempDir("", "docker-build-git") + if err != nil { + return err + } + defer os.RemoveAll(root) + + if output, err := exec.Command("git", "clone", remoteURL, root).CombinedOutput(); err != nil { + return fmt.Errorf("Error trying to use git: %s (%s)", err, output) + } + + d, err := os.Open(path.Join(root, "Dockerfile")) + if err != nil { + if os.IsNotExist(err) { + return fmt.Errorf("No Dockerfile found in the repository") + } + return err + } else { + dockerfile = d + } + + c, err := Tar(root, Bzip2) + if err != nil { + return err + } else { + context = c + } + } else if utils.IsURL(remoteURL) { f, err := utils.Download(remoteURL, ioutil.Discard) if err != nil { diff --git a/commands.go b/commands.go index de0e6432f2..853f1cdebc 100644 --- a/commands.go +++ b/commands.go @@ -196,8 +196,9 @@ func (cli *DockerCli) CmdBuild(args ...string) error { return err } io.Copy(wField, file) - multipartBody = io.MultiReader(multipartBody, boundary) } + multipartBody = io.MultiReader(multipartBody, boundary) + v := &url.Values{} v.Set("t", *tag) if isRemote {