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:
parent
c25879ee86
commit
34a6ec250f
|
|
@ -25,6 +25,14 @@ import (
|
||||||
"gopkg.in/src-d/go-git.v4/plumbing"
|
"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.
|
// Git unifies calls to download and unpack the build context.
|
||||||
type Git struct {
|
type Git struct {
|
||||||
context string
|
context string
|
||||||
|
|
@ -35,7 +43,7 @@ func (g *Git) UnpackTarFromBuildContext() (string, error) {
|
||||||
directory := constants.BuildContextDir
|
directory := constants.BuildContextDir
|
||||||
parts := strings.Split(g.context, "#")
|
parts := strings.Split(g.context, "#")
|
||||||
options := git.CloneOptions{
|
options := git.CloneOptions{
|
||||||
URL: "https://" + parts[0],
|
URL: getGitPullMethod() + "://" + parts[0],
|
||||||
Progress: os.Stdout,
|
Progress: os.Stdout,
|
||||||
}
|
}
|
||||||
if len(parts) > 1 {
|
if len(parts) > 1 {
|
||||||
|
|
@ -44,3 +52,11 @@ func (g *Git) UnpackTarFromBuildContext() (string, error) {
|
||||||
_, err := git.PlainClone(directory, false, &options)
|
_, err := git.PlainClone(directory, false, &options)
|
||||||
return directory, err
|
return directory, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getGitPullMethod() string {
|
||||||
|
gitPullMethod := os.Getenv(gitPullMethodEnvKey)
|
||||||
|
if ok := supportedGitPullMethods[gitPullMethod]; !ok {
|
||||||
|
gitPullMethod = "https"
|
||||||
|
}
|
||||||
|
return gitPullMethod
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue