add http support for git pull

usage: set the GIT_PULL_METHOD env var to http or https for starting the container
This commit is contained in:
yw-liu 2020-04-14 20:25:20 +08:00 committed by GitHub
parent c25879ee86
commit 34a6ec250f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -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
}