1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #8468 from laktek/master

Fix URL check in build from Git.
This commit is contained in:
Jessie Frazelle 2014-10-31 14:43:21 -07:00
commit 9cc71b4597
4 changed files with 27 additions and 3 deletions

View file

@ -117,7 +117,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
root := cmd.Arg(0)
if utils.IsGIT(root) {
remoteURL := cmd.Arg(0)
if !strings.HasPrefix(remoteURL, "git://") && !strings.HasPrefix(remoteURL, "git@") && !utils.IsURL(remoteURL) {
if !utils.ValidGitTransport(remoteURL) {
remoteURL = "https://" + remoteURL
}

View file

@ -5,7 +5,6 @@ import (
"io/ioutil"
"os"
"os/exec"
"strings"
"github.com/docker/docker/daemon"
"github.com/docker/docker/engine"
@ -59,7 +58,7 @@ func (b *BuilderJob) CmdBuild(job *engine.Job) engine.Status {
if remoteURL == "" {
context = ioutil.NopCloser(job.Stdin)
} else if utils.IsGIT(remoteURL) {
if !strings.HasPrefix(remoteURL, "git://") {
if !utils.ValidGitTransport(remoteURL) {
remoteURL = "https://" + remoteURL
}
root, err := ioutil.TempDir("", "docker-build-git")

View file

@ -304,6 +304,10 @@ func IsGIT(str string) bool {
return strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "github.com/") || strings.HasPrefix(str, "git@github.com:") || (strings.HasSuffix(str, ".git") && IsURL(str))
}
func ValidGitTransport(str string) bool {
return strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@") || IsURL(str)
}
var (
localHostRx = regexp.MustCompile(`(?m)^nameserver 127[^\n]+\n*`)
)

View file

@ -97,3 +97,24 @@ func TestReadSymlinkedDirectoryToFile(t *testing.T) {
t.Errorf("failed to remove symlink: %s", err)
}
}
func TestValidGitTransport(t *testing.T) {
for _, url := range []string{
"git://github.com/docker/docker",
"git@github.com:docker/docker.git",
"https://github.com/docker/docker.git",
"http://github.com/docker/docker.git",
} {
if ValidGitTransport(url) == false {
t.Fatalf("%q should be detected as valid Git prefix", url)
}
}
for _, url := range []string{
"github.com/docker/docker",
} {
if ValidGitTransport(url) == true {
t.Fatalf("%q should not be detected as valid Git prefix", url)
}
}
}