From 34a6ec250ff898280658245821aa056b4b9aa872 Mon Sep 17 00:00:00 2001 From: yw-liu <43599588+yw-liu@users.noreply.github.com> Date: Tue, 14 Apr 2020 20:25:20 +0800 Subject: [PATCH] add http support for git pull usage: set the GIT_PULL_METHOD env var to http or https for starting the container --- pkg/buildcontext/git.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/buildcontext/git.go b/pkg/buildcontext/git.go index 9908350b1..fe4eae1ac 100644 --- a/pkg/buildcontext/git.go +++ b/pkg/buildcontext/git.go @@ -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 +}