Skip to content

feat(git): add proxyoptions to git #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions envbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/fatih/color"
"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/osfs"
"github.com/go-git/go-git/v5/plumbing/transport"
githttp "github.com/go-git/go-git/v5/plumbing/transport/http"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/remote"
Expand Down Expand Up @@ -196,6 +197,10 @@ type Options struct {
// This is optional!
GitPassword string `env:"GIT_PASSWORD"`

// GitHttpProxyURL is the url for the http proxy.
// This is optional!
GitHttpProxyURL string `env:"GIT_HTTP_PROXY_URL"`

// WorkspaceFolder is the path to the workspace folder
// that will be built. This is optional!
WorkspaceFolder string `env:"WORKSPACE_FOLDER"`
Expand Down Expand Up @@ -363,6 +368,17 @@ func Run(ctx context.Context, options Options) error {
Password: options.GitPassword,
}
}
if options.GitHttpProxyURL != "" {
gitHttpProxyURL, err := url.Parse(options.GitHttpProxyURL)
if err != nil {
return fmt.Errorf("parse git http proxy url: %w", err)
}
options.GitHttpProxyURL = gitHttpProxyURL.String()

cloneOpts.ProxyOptions = transport.ProxyOptions{
URL: options.GitHttpProxyURL,
}
}
cloneOpts.RepoURL = options.GitURL

cloned, fallbackErr = CloneRepo(ctx, cloneOpts)
Expand Down
2 changes: 2 additions & 0 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type CloneRepoOptions struct {
SingleBranch bool
Depth int
CABundle []byte
ProxyOptions transport.ProxyOptions
}

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