mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: update buildkit to v0.8
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
92
vendor/github.com/moby/buildkit/client/llb/source.go
generated
vendored
92
vendor/github.com/moby/buildkit/client/llb/source.go
generated
vendored
@ -5,12 +5,14 @@ import (
|
||||
_ "crypto/sha256" // for opencontainers/go-digest
|
||||
"encoding/json"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/moby/buildkit/solver/pb"
|
||||
"github.com/moby/buildkit/util/apicaps"
|
||||
"github.com/moby/buildkit/util/sshutil"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@ -197,15 +199,59 @@ type ImageInfo struct {
|
||||
RecordType string
|
||||
}
|
||||
|
||||
func Git(remote, ref string, opts ...GitOption) State {
|
||||
url := ""
|
||||
const (
|
||||
gitProtocolHTTP = iota + 1
|
||||
gitProtocolHTTPS
|
||||
gitProtocolSSH
|
||||
gitProtocolGit
|
||||
gitProtocolUnknown
|
||||
)
|
||||
|
||||
for _, prefix := range []string{
|
||||
"http://", "https://", "git://", "git@",
|
||||
} {
|
||||
var gitSSHRegex = regexp.MustCompile("^([a-z0-9]+@)?[^:]+:.*$")
|
||||
|
||||
func getGitProtocol(remote string) (string, int) {
|
||||
prefixes := map[string]int{
|
||||
"http://": gitProtocolHTTP,
|
||||
"https://": gitProtocolHTTPS,
|
||||
"git://": gitProtocolGit,
|
||||
"ssh://": gitProtocolSSH,
|
||||
}
|
||||
protocolType := gitProtocolUnknown
|
||||
for prefix, potentialType := range prefixes {
|
||||
if strings.HasPrefix(remote, prefix) {
|
||||
url = strings.Split(remote, "#")[0]
|
||||
remote = strings.TrimPrefix(remote, prefix)
|
||||
protocolType = potentialType
|
||||
}
|
||||
}
|
||||
|
||||
if protocolType == gitProtocolUnknown && gitSSHRegex.MatchString(remote) {
|
||||
protocolType = gitProtocolSSH
|
||||
}
|
||||
|
||||
// remove name from ssh
|
||||
if protocolType == gitProtocolSSH {
|
||||
parts := strings.SplitN(remote, "@", 2)
|
||||
if len(parts) == 2 {
|
||||
remote = parts[1]
|
||||
}
|
||||
}
|
||||
|
||||
return remote, protocolType
|
||||
}
|
||||
|
||||
func Git(remote, ref string, opts ...GitOption) State {
|
||||
url := strings.Split(remote, "#")[0]
|
||||
|
||||
var protocolType int
|
||||
remote, protocolType = getGitProtocol(remote)
|
||||
|
||||
var sshHost string
|
||||
if protocolType == gitProtocolSSH {
|
||||
parts := strings.SplitN(remote, ":", 2)
|
||||
if len(parts) == 2 {
|
||||
sshHost = parts[0]
|
||||
// keep remote consistent with http(s) version
|
||||
remote = parts[0] + "/" + parts[1]
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,6 +289,25 @@ func Git(remote, ref string, opts ...GitOption) State {
|
||||
addCap(&gi.Constraints, pb.CapSourceGitHTTPAuth)
|
||||
}
|
||||
}
|
||||
if protocolType == gitProtocolSSH {
|
||||
if gi.KnownSSHHosts != "" {
|
||||
attrs[pb.AttrKnownSSHHosts] = gi.KnownSSHHosts
|
||||
} else if sshHost != "" {
|
||||
keyscan, err := sshutil.SSHKeyScan(sshHost)
|
||||
if err == nil {
|
||||
// best effort
|
||||
attrs[pb.AttrKnownSSHHosts] = keyscan
|
||||
}
|
||||
}
|
||||
addCap(&gi.Constraints, pb.CapSourceGitKnownSSHHosts)
|
||||
|
||||
if gi.MountSSHSock == "" {
|
||||
attrs[pb.AttrMountSSHSock] = "default"
|
||||
} else {
|
||||
attrs[pb.AttrMountSSHSock] = gi.MountSSHSock
|
||||
}
|
||||
addCap(&gi.Constraints, pb.CapSourceGitMountSSHSock)
|
||||
}
|
||||
|
||||
addCap(&gi.Constraints, pb.CapSourceGit)
|
||||
|
||||
@ -265,6 +330,8 @@ type GitInfo struct {
|
||||
AuthTokenSecret string
|
||||
AuthHeaderSecret string
|
||||
addAuthCap bool
|
||||
KnownSSHHosts string
|
||||
MountSSHSock string
|
||||
}
|
||||
|
||||
func KeepGitDir() GitOption {
|
||||
@ -287,6 +354,19 @@ func AuthHeaderSecret(v string) GitOption {
|
||||
})
|
||||
}
|
||||
|
||||
func KnownSSHHosts(key string) GitOption {
|
||||
key = strings.TrimSuffix(key, "\n")
|
||||
return gitOptionFunc(func(gi *GitInfo) {
|
||||
gi.KnownSSHHosts = gi.KnownSSHHosts + key + "\n"
|
||||
})
|
||||
}
|
||||
|
||||
func MountSSHSock(sshID string) GitOption {
|
||||
return gitOptionFunc(func(gi *GitInfo) {
|
||||
gi.MountSSHSock = sshID
|
||||
})
|
||||
}
|
||||
|
||||
func Scratch() State {
|
||||
return NewState(nil)
|
||||
}
|
||||
|
Reference in New Issue
Block a user