Skip to content

Commit e75f22a

Browse files
feat(git): add proxyoptions to git (#106)
1 parent 9676742 commit e75f22a

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

envbuilder.go

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
"github.com/fatih/color"
4444
"github.com/go-git/go-billy/v5"
4545
"github.com/go-git/go-billy/v5/osfs"
46+
"github.com/go-git/go-git/v5/plumbing/transport"
4647
githttp "github.com/go-git/go-git/v5/plumbing/transport/http"
4748
v1 "github.com/google/go-containerregistry/pkg/v1"
4849
"github.com/google/go-containerregistry/pkg/v1/remote"
@@ -196,6 +197,10 @@ type Options struct {
196197
// This is optional!
197198
GitPassword string `env:"GIT_PASSWORD"`
198199

200+
// GitHTTPProxyURL is the url for the http proxy.
201+
// This is optional!
202+
GitHTTPProxyURL string `env:"GIT_HTTP_PROXY_URL"`
203+
199204
// WorkspaceFolder is the path to the workspace folder
200205
// that will be built. This is optional!
201206
WorkspaceFolder string `env:"WORKSPACE_FOLDER"`
@@ -363,6 +368,11 @@ func Run(ctx context.Context, options Options) error {
363368
Password: options.GitPassword,
364369
}
365370
}
371+
if options.GitHTTPProxyURL != "" {
372+
cloneOpts.ProxyOptions = transport.ProxyOptions{
373+
URL: options.GitHTTPProxyURL,
374+
}
375+
}
366376
cloneOpts.RepoURL = options.GitURL
367377

368378
cloned, fallbackErr = CloneRepo(ctx, cloneOpts)

envbuilder_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func TestSystemOptions(t *testing.T) {
3232
"GIT_CLONE_DEPTH": "1",
3333
"GIT_URL": "https://github.com/coder/coder",
3434
"WORKSPACE_FOLDER": "/workspaces/coder",
35+
"GIT_HTTP_PROXY_URL": "http://company-proxy.com:8081",
3536
}
3637
env := envbuilder.OptionsFromEnv(func(s string) (string, bool) {
3738
return opts[s], true
@@ -47,4 +48,5 @@ func TestSystemOptions(t *testing.T) {
4748
require.Equal(t, 1, env.GitCloneDepth)
4849
require.Equal(t, "https://github.com/coder/coder", env.GitURL)
4950
require.Equal(t, "/workspaces/coder", env.WorkspaceFolder)
51+
require.Equal(t, "http://company-proxy.com:8081", env.GitHTTPProxyURL)
5052
}

git.go

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type CloneRepoOptions struct {
2626
SingleBranch bool
2727
Depth int
2828
CABundle []byte
29+
ProxyOptions transport.ProxyOptions
2930
}
3031

3132
// CloneRepo will clone the repository at the given URL into the given path.
@@ -78,6 +79,7 @@ func CloneRepo(ctx context.Context, opts CloneRepoOptions) (bool, error) {
7879
Depth: opts.Depth,
7980
SingleBranch: opts.SingleBranch,
8081
CABundle: opts.CABundle,
82+
ProxyOptions: opts.ProxyOptions,
8183
})
8284
if errors.Is(err, git.ErrRepositoryAlreadyExists) {
8385
return false, nil

0 commit comments

Comments
 (0)