vendor: github.com/moby/buildkit v0.21.0-rc1

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
Jonathan A. Sternberg
2025-04-09 10:28:03 -05:00
parent a34cdff84e
commit 8fb1157b5f
221 changed files with 6530 additions and 3986 deletions

View File

@ -360,13 +360,6 @@ func AuthTokenSecret(v string) GitOption {
})
}
func AuthHeaderSecret(v string) GitOption {
return gitOptionFunc(func(gi *GitInfo) {
gi.AuthHeaderSecret = v
gi.addAuthCap = true
})
}
func KnownSSHHosts(key string) GitOption {
key = strings.TrimSuffix(key, "\n")
return gitOptionFunc(func(gi *GitInfo) {
@ -380,6 +373,29 @@ func MountSSHSock(sshID string) GitOption {
})
}
// AuthOption can be used with either HTTP or Git sources.
type AuthOption interface {
GitOption
HTTPOption
}
// AuthHeaderSecret returns an AuthOption that defines the name of a
// secret to use for HTTP based authentication.
func AuthHeaderSecret(secretName string) AuthOption {
return struct {
GitOption
HTTPOption
}{
GitOption: gitOptionFunc(func(gi *GitInfo) {
gi.AuthHeaderSecret = secretName
gi.addAuthCap = true
}),
HTTPOption: httpOptionFunc(func(hi *HTTPInfo) {
hi.AuthHeaderSecret = secretName
}),
}
}
// Scratch returns a state that represents an empty filesystem.
func Scratch() State {
return NewState(nil)
@ -595,6 +611,14 @@ func HTTP(url string, opts ...HTTPOption) State {
attrs[pb.AttrHTTPGID] = strconv.Itoa(hi.GID)
addCap(&hi.Constraints, pb.CapSourceHTTPUIDGID)
}
if hi.AuthHeaderSecret != "" {
attrs[pb.AttrHTTPAuthHeaderSecret] = hi.AuthHeaderSecret
addCap(&hi.Constraints, pb.CapSourceHTTPAuth)
}
if hi.Header != nil {
hi.Header.setAttrs(attrs)
addCap(&hi.Constraints, pb.CapSourceHTTPHeader)
}
addCap(&hi.Constraints, pb.CapSourceHTTP)
source := NewSource(url, attrs, hi.Constraints)
@ -603,11 +627,13 @@ func HTTP(url string, opts ...HTTPOption) State {
type HTTPInfo struct {
constraintsWrapper
Checksum digest.Digest
Filename string
Perm int
UID int
GID int
Checksum digest.Digest
Filename string
Perm int
UID int
GID int
AuthHeaderSecret string
Header *HTTPHeader
}
type HTTPOption interface {
@ -645,6 +671,33 @@ func Chown(uid, gid int) HTTPOption {
})
}
// Header returns an [HTTPOption] that ensures additional request headers will
// be sent when retrieving the HTTP source.
func Header(header HTTPHeader) HTTPOption {
return httpOptionFunc(func(hi *HTTPInfo) {
hi.Header = &header
})
}
type HTTPHeader struct {
Accept string
UserAgent string
}
func (hh *HTTPHeader) setAttrs(attrs map[string]string) {
if hh.Accept != "" {
attrs[hh.attr("accept")] = hh.Accept
}
if hh.UserAgent != "" {
attrs[hh.attr("user-agent")] = hh.UserAgent
}
}
func (hh *HTTPHeader) attr(name string) string {
return pb.AttrHTTPHeaderPrefix + name
}
func platformSpecificSource(id string) bool {
return strings.HasPrefix(id, "docker-image://") || strings.HasPrefix(id, "oci-layout://")
}