mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Implement build from git
This commit is contained in:
parent
a11e61677c
commit
12c9b9b3c9
2 changed files with 36 additions and 3 deletions
36
api.go
36
api.go
|
@ -10,6 +10,9 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -684,7 +687,7 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ
|
||||||
repoName = remoteParts[0]
|
repoName = remoteParts[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
var dockerfile, context io.ReadCloser
|
var dockerfile, context io.Reader
|
||||||
|
|
||||||
if remoteURL == "" {
|
if remoteURL == "" {
|
||||||
d, _, err := r.FormFile("Dockerfile")
|
d, _, err := r.FormFile("Dockerfile")
|
||||||
|
@ -703,7 +706,36 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if utils.IsGIT(remoteURL) {
|
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) {
|
} else if utils.IsURL(remoteURL) {
|
||||||
f, err := utils.Download(remoteURL, ioutil.Discard)
|
f, err := utils.Download(remoteURL, ioutil.Discard)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -196,8 +196,9 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
io.Copy(wField, file)
|
io.Copy(wField, file)
|
||||||
multipartBody = io.MultiReader(multipartBody, boundary)
|
|
||||||
}
|
}
|
||||||
|
multipartBody = io.MultiReader(multipartBody, boundary)
|
||||||
|
|
||||||
v := &url.Values{}
|
v := &url.Values{}
|
||||||
v.Set("t", *tag)
|
v.Set("t", *tag)
|
||||||
if isRemote {
|
if isRemote {
|
||||||
|
|
Loading…
Reference in a new issue