mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: github.com/moby/buildkit v0.21.0-rc1
Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
2
vendor/github.com/moby/buildkit/client/llb/exec.go
generated
vendored
2
vendor/github.com/moby/buildkit/client/llb/exec.go
generated
vendored
@ -614,7 +614,7 @@ func Shlex(str string) RunOption {
|
||||
})
|
||||
}
|
||||
|
||||
func Shlexf(str string, v ...interface{}) RunOption {
|
||||
func Shlexf(str string, v ...any) RunOption {
|
||||
return runOptionFunc(func(ei *ExecInfo) {
|
||||
ei.State = shlexf(str, true, v...)(ei.State)
|
||||
})
|
||||
|
5
vendor/github.com/moby/buildkit/client/llb/marshal.go
generated
vendored
5
vendor/github.com/moby/buildkit/client/llb/marshal.go
generated
vendored
@ -2,6 +2,7 @@ package llb
|
||||
|
||||
import (
|
||||
"io"
|
||||
"slices"
|
||||
"sync"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
@ -84,7 +85,7 @@ func ReadFrom(r io.Reader) (*Definition, error) {
|
||||
|
||||
func MarshalConstraints(base, override *Constraints) (*pb.Op, *pb.OpMetadata) {
|
||||
c := *base
|
||||
c.WorkerConstraints = append([]string{}, c.WorkerConstraints...)
|
||||
c.WorkerConstraints = slices.Clone(c.WorkerConstraints)
|
||||
|
||||
if p := override.Platform; p != nil {
|
||||
c.Platform = p
|
||||
@ -105,7 +106,7 @@ func MarshalConstraints(base, override *Constraints) (*pb.Op, *pb.OpMetadata) {
|
||||
OSVersion: c.Platform.OSVersion,
|
||||
}
|
||||
if c.Platform.OSFeatures != nil {
|
||||
opPlatform.OSFeatures = append([]string{}, c.Platform.OSFeatures...)
|
||||
opPlatform.OSFeatures = slices.Clone(c.Platform.OSFeatures)
|
||||
}
|
||||
|
||||
return &pb.Op{
|
||||
|
18
vendor/github.com/moby/buildkit/client/llb/meta.go
generated
vendored
18
vendor/github.com/moby/buildkit/client/llb/meta.go
generated
vendored
@ -35,7 +35,7 @@ var (
|
||||
|
||||
// AddEnvf is the same as [AddEnv] but allows for a format string.
|
||||
// This is the equivalent of `[State.AddEnvf]`
|
||||
func AddEnvf(key, value string, v ...interface{}) StateOption {
|
||||
func AddEnvf(key, value string, v ...any) StateOption {
|
||||
return addEnvf(key, value, true, v...)
|
||||
}
|
||||
|
||||
@ -46,12 +46,12 @@ func AddEnv(key, value string) StateOption {
|
||||
return addEnvf(key, value, false)
|
||||
}
|
||||
|
||||
func addEnvf(key, value string, replace bool, v ...interface{}) StateOption {
|
||||
func addEnvf(key, value string, replace bool, v ...any) StateOption {
|
||||
if replace {
|
||||
value = fmt.Sprintf(value, v...)
|
||||
}
|
||||
return func(s State) State {
|
||||
return s.withValue(keyEnv, func(ctx context.Context, c *Constraints) (interface{}, error) {
|
||||
return s.withValue(keyEnv, func(ctx context.Context, c *Constraints) (any, error) {
|
||||
env, err := getEnv(s)(ctx, c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -69,16 +69,16 @@ func Dir(str string) StateOption {
|
||||
}
|
||||
|
||||
// Dirf is the same as [Dir] but allows for a format string.
|
||||
func Dirf(str string, v ...interface{}) StateOption {
|
||||
func Dirf(str string, v ...any) StateOption {
|
||||
return dirf(str, true, v...)
|
||||
}
|
||||
|
||||
func dirf(value string, replace bool, v ...interface{}) StateOption {
|
||||
func dirf(value string, replace bool, v ...any) StateOption {
|
||||
if replace {
|
||||
value = fmt.Sprintf(value, v...)
|
||||
}
|
||||
return func(s State) State {
|
||||
return s.withValue(keyDir, func(ctx context.Context, c *Constraints) (interface{}, error) {
|
||||
return s.withValue(keyDir, func(ctx context.Context, c *Constraints) (any, error) {
|
||||
if !path.IsAbs(value) {
|
||||
prev, err := getDir(s)(ctx, c)
|
||||
if err != nil {
|
||||
@ -213,7 +213,7 @@ func args(args ...string) StateOption {
|
||||
}
|
||||
}
|
||||
|
||||
func shlexf(str string, replace bool, v ...interface{}) StateOption {
|
||||
func shlexf(str string, replace bool, v ...any) StateOption {
|
||||
if replace {
|
||||
str = fmt.Sprintf(str, v...)
|
||||
}
|
||||
@ -248,7 +248,7 @@ func getPlatform(s State) func(context.Context, *Constraints) (*ocispecs.Platfor
|
||||
|
||||
func extraHost(host string, ip net.IP) StateOption {
|
||||
return func(s State) State {
|
||||
return s.withValue(keyExtraHost, func(ctx context.Context, c *Constraints) (interface{}, error) {
|
||||
return s.withValue(keyExtraHost, func(ctx context.Context, c *Constraints) (any, error) {
|
||||
v, err := getExtraHosts(s)(ctx, c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -278,7 +278,7 @@ type HostIP struct {
|
||||
|
||||
func ulimit(name UlimitName, soft int64, hard int64) StateOption {
|
||||
return func(s State) State {
|
||||
return s.withValue(keyUlimit, func(ctx context.Context, c *Constraints) (interface{}, error) {
|
||||
return s.withValue(keyUlimit, func(ctx context.Context, c *Constraints) (any, error) {
|
||||
v, err := getUlimit(s)(ctx, c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
77
vendor/github.com/moby/buildkit/client/llb/source.go
generated
vendored
77
vendor/github.com/moby/buildkit/client/llb/source.go
generated
vendored
@ -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://")
|
||||
}
|
||||
|
27
vendor/github.com/moby/buildkit/client/llb/state.go
generated
vendored
27
vendor/github.com/moby/buildkit/client/llb/state.go
generated
vendored
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"maps"
|
||||
"net"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/containerd/platforms"
|
||||
@ -59,8 +60,8 @@ func NewState(o Output) State {
|
||||
type State struct {
|
||||
out Output
|
||||
prev *State
|
||||
key interface{}
|
||||
value func(context.Context, *Constraints) (interface{}, error)
|
||||
key any
|
||||
value func(context.Context, *Constraints) (any, error)
|
||||
opts []ConstraintsOpt
|
||||
async *asyncState
|
||||
}
|
||||
@ -76,13 +77,13 @@ func (s State) ensurePlatform() State {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s State) WithValue(k, v interface{}) State {
|
||||
return s.withValue(k, func(context.Context, *Constraints) (interface{}, error) {
|
||||
func (s State) WithValue(k, v any) State {
|
||||
return s.withValue(k, func(context.Context, *Constraints) (any, error) {
|
||||
return v, nil
|
||||
})
|
||||
}
|
||||
|
||||
func (s State) withValue(k interface{}, v func(context.Context, *Constraints) (interface{}, error)) State {
|
||||
func (s State) withValue(k any, v func(context.Context, *Constraints) (any, error)) State {
|
||||
return State{
|
||||
out: s.Output(),
|
||||
prev: &s, // doesn't need to be original pointer
|
||||
@ -91,7 +92,7 @@ func (s State) withValue(k interface{}, v func(context.Context, *Constraints) (i
|
||||
}
|
||||
}
|
||||
|
||||
func (s State) Value(ctx context.Context, k interface{}, co ...ConstraintsOpt) (interface{}, error) {
|
||||
func (s State) Value(ctx context.Context, k any, co ...ConstraintsOpt) (any, error) {
|
||||
c := &Constraints{}
|
||||
for _, f := range co {
|
||||
f.SetConstraintsOption(c)
|
||||
@ -99,12 +100,12 @@ func (s State) Value(ctx context.Context, k interface{}, co ...ConstraintsOpt) (
|
||||
return s.getValue(k)(ctx, c)
|
||||
}
|
||||
|
||||
func (s State) getValue(k interface{}) func(context.Context, *Constraints) (interface{}, error) {
|
||||
func (s State) getValue(k any) func(context.Context, *Constraints) (any, error) {
|
||||
if s.key == k {
|
||||
return s.value
|
||||
}
|
||||
if s.async != nil {
|
||||
return func(ctx context.Context, c *Constraints) (interface{}, error) {
|
||||
return func(ctx context.Context, c *Constraints) (any, error) {
|
||||
target, err := s.async.Do(ctx, c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -271,7 +272,7 @@ func (s State) WithImageConfig(c []byte) (State, error) {
|
||||
OSVersion: img.OSVersion,
|
||||
}
|
||||
if img.OSFeatures != nil {
|
||||
plat.OSFeatures = append([]string{}, img.OSFeatures...)
|
||||
plat.OSFeatures = slices.Clone(img.OSFeatures)
|
||||
}
|
||||
s = s.Platform(plat)
|
||||
}
|
||||
@ -321,7 +322,7 @@ func (s State) AddEnv(key, value string) State {
|
||||
}
|
||||
|
||||
// AddEnvf is the same as [State.AddEnv] but with a format string.
|
||||
func (s State) AddEnvf(key, value string, v ...interface{}) State {
|
||||
func (s State) AddEnvf(key, value string, v ...any) State {
|
||||
return AddEnvf(key, value, v...)(s)
|
||||
}
|
||||
|
||||
@ -332,7 +333,7 @@ func (s State) Dir(str string) State {
|
||||
}
|
||||
|
||||
// Dirf is the same as [State.Dir] but with a format string.
|
||||
func (s State) Dirf(str string, v ...interface{}) State {
|
||||
func (s State) Dirf(str string, v ...any) State {
|
||||
return Dirf(str, v...)(s)
|
||||
}
|
||||
|
||||
@ -608,7 +609,7 @@ func WithCustomName(name string) ConstraintsOpt {
|
||||
})
|
||||
}
|
||||
|
||||
func WithCustomNamef(name string, a ...interface{}) ConstraintsOpt {
|
||||
func WithCustomNamef(name string, a ...any) ConstraintsOpt {
|
||||
return WithCustomName(fmt.Sprintf(name, a...))
|
||||
}
|
||||
|
||||
@ -746,6 +747,6 @@ func Require(filters ...string) ConstraintsOpt {
|
||||
})
|
||||
}
|
||||
|
||||
func nilValue(context.Context, *Constraints) (interface{}, error) {
|
||||
func nilValue(context.Context, *Constraints) (any, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
10
vendor/github.com/moby/buildkit/client/solve.go
generated
vendored
10
vendor/github.com/moby/buildkit/client/solve.go
generated
vendored
@ -142,9 +142,7 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runG
|
||||
}
|
||||
|
||||
contentStores := map[string]content.Store{}
|
||||
for key, store := range cacheOpt.contentStores {
|
||||
contentStores[key] = store
|
||||
}
|
||||
maps.Copy(contentStores, cacheOpt.contentStores)
|
||||
for key, store := range opt.OCIStores {
|
||||
key2 := "oci:" + key
|
||||
if _, ok := contentStores[key2]; ok {
|
||||
@ -361,7 +359,7 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runG
|
||||
}
|
||||
for _, storePath := range storesToUpdate {
|
||||
names := []ociindex.NameOrTag{ociindex.Tag("latest")}
|
||||
if t, ok := res.ExporterResponse["image.name"]; ok {
|
||||
if t, ok := res.ExporterResponse[exptypes.ExporterImageNameKey]; ok {
|
||||
inp := strings.Split(t, ",")
|
||||
names = make([]ociindex.NameOrTag, len(inp))
|
||||
for i, n := range inp {
|
||||
@ -538,9 +536,7 @@ func parseCacheOptions(ctx context.Context, isGateway bool, opt SolveOpt) (*cach
|
||||
func prepareMounts(opt *SolveOpt) (map[string]fsutil.FS, error) {
|
||||
// merge local mounts and fallback local directories together
|
||||
mounts := make(map[string]fsutil.FS)
|
||||
for k, mount := range opt.LocalMounts {
|
||||
mounts[k] = mount
|
||||
}
|
||||
maps.Copy(mounts, opt.LocalMounts)
|
||||
for k, dir := range opt.LocalDirs {
|
||||
mount, err := fsutil.NewFS(dir)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user