Skip to content

Consolidate logic for detection of remote git urls #1708

@jedevc

Description

@jedevc

🐛 Moves from moby/buildkit#3755

We have a few locations of testing if a URL is a valid Git URL:

buildx/bake/remote.go

Lines 86 to 94 in 33388d6

func IsRemoteURL(url string) bool {
if _, _, ok := detectHTTPContext(url); ok {
return true
}
if _, ok := detectGitContext(url); ok {
return true
}
return false
}

buildx/bake/bake.go

Lines 1043 to 1045 in 33388d6

func isRemoteResource(str string) bool {
return urlutil.IsGitURL(str) || urlutil.IsURL(str)
}

if urlutil.IsGitURL(v.Path) || urlutil.IsURL(v.Path) || strings.HasPrefix(v.Path, "docker-image://") || strings.HasPrefix(v.Path, "target:") {

However, since moby/buildkit@8bfeafa, the logic for parsing Git URLs has changed, and the corresponding logic in Buildx has not been updated - we should use these BuildKit helpers.

gitutil.ParseGitRef (from buildkit) does not produce the same results as urlutil.IsGitURL (from moby):

  • gitutil.ParseGitRef does not recognize slashes right after the name such as [email protected]/docker/buildx.git (note /docker instead of :docker), while urlutil.IsGitURL (this use to work before moby/buildkit@8bfeafa, I have no idea why or how though). cc @AkihiroSuda do you know why this behavior would have broken after that commit? I can't identify what part caused the issue 👀
  • gitutil.ParseGitRef recognize git:// urls such as ssh://[email protected]:docker/buildx.git, while urlutil.IsGitURL does not seem to.

Because of the disparity in these functions, buildx will incorrectly identify URLs as git-urls, and buildkit will fail to handle them correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions