Skip to content

Commit 21c1789

Browse files
authored
remove docker package (#275)
docker package was used to check for git urls. implemented the fork inside locations.go instead of pulling entire package.
1 parent 9445150 commit 21c1789

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

cmd/locations.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package cmd
33
import (
44
"context"
55
"path/filepath"
6+
"regexp"
67
"strings"
78
"time"
89

9-
"github.com/docker/docker/builder/remotecontext/urlutil"
1010
"github.com/pkg/errors"
1111
"github.com/rs/zerolog/log"
1212

@@ -35,7 +35,7 @@ var ErrCannotUseQueryWithFilePath = errors.New("relative and absolute file paths
3535

3636
func maybeCloneGitUrl(ctx context.Context, repoManager cloner, repoRefreshDuration time.Duration, location, vcsUsername string) (string, error) {
3737
result := strings.SplitN(location, "?", 2)
38-
if !urlutil.IsGitURL(result[0]) {
38+
if !isGitURL(result[0]) {
3939
if len(result) > 1 {
4040
return "", ErrCannotUseQueryWithFilePath
4141
}
@@ -82,3 +82,26 @@ func maybeCloneGitUrl(ctx context.Context, repoManager cloner, repoRefreshDurati
8282

8383
return path, nil
8484
}
85+
86+
func isGitURL(str string) bool {
87+
if IsURL(str) && urlPathWithFragmentSuffix.MatchString(str) {
88+
return true
89+
}
90+
for _, prefix := range []string{"git://", "github.com/", "git@"} {
91+
if strings.HasPrefix(str, prefix) {
92+
return true
93+
}
94+
}
95+
return false
96+
}
97+
98+
// urlPathWithFragmentSuffix matches fragments to use as Git reference and build
99+
// context from the Git repository. See IsGitURL for details.
100+
var urlPathWithFragmentSuffix = regexp.MustCompile(`\.git(?:#.+)?$`)
101+
102+
// IsURL returns true if the provided str is an HTTP(S) URL by checking if it
103+
// has a http:// or https:// scheme. No validation is performed to verify if the
104+
// URL is well-formed.
105+
func IsURL(str string) bool {
106+
return strings.HasPrefix(str, "https://") || strings.HasPrefix(str, "http://")
107+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ require (
1515
github.com/cenkalti/backoff/v4 v4.3.0
1616
github.com/chainguard-dev/git-urls v1.0.2
1717
github.com/creasty/defaults v1.7.0
18-
github.com/docker/docker v27.2.1+incompatible
1918
github.com/ghodss/yaml v1.0.0
2019
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399
2120
github.com/go-logr/zerologr v1.2.3
@@ -120,6 +119,7 @@ require (
120119
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
121120
github.com/distribution/reference v0.5.0 // indirect
122121
github.com/docker/distribution v2.8.3+incompatible // indirect
122+
github.com/docker/docker v27.2.1+incompatible // indirect
123123
github.com/docker/go-connections v0.4.0 // indirect
124124
github.com/docker/go-units v0.5.0 // indirect
125125
github.com/emicklei/go-restful/v3 v3.10.2 // indirect

0 commit comments

Comments
 (0)