add http support for git pull
usage: set the GIT_PULL_METHOD env var to http or https for starting the container
@@ -25,6 +25,14 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing"
)
+const (
+ gitPullMethodEnvKey = "GIT_PULL_METHOD"
+)
+
+var (
+ supportedGitPullMethods = map[string]bool{"https":true, "http":true}
+)
+
// Git unifies calls to download and unpack the build context.
type Git struct {
context string
@@ -35,7 +43,7 @@ func (g *Git) UnpackTarFromBuildContext() (string, error) {
directory := constants.BuildContextDir
parts := strings.Split(g.context, "#")
options := git.CloneOptions{
- URL: "https://" + parts[0],
+ URL: getGitPullMethod() + "://" + parts[0],
Progress: os.Stdout,
}
if len(parts) > 1 {
@@ -44,3 +52,11 @@ func (g *Git) UnpackTarFromBuildContext() (string, error) {
_, err := git.PlainClone(directory, false, &options)
return directory, err
}
+
+func getGitPullMethod() string {
+ gitPullMethod := os.Getenv(gitPullMethodEnvKey)
+ if ok := supportedGitPullMethods[gitPullMethod]; !ok {
+ gitPullMethod = "https"
+ }
+ return gitPullMethod
+}
