mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: update buildkit to 539be170
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
22
vendor/github.com/moby/buildkit/client/llb/exec.go
generated
vendored
22
vendor/github.com/moby/buildkit/client/llb/exec.go
generated
vendored
@ -186,12 +186,18 @@ func (e *ExecOp) Marshal(ctx context.Context, c *Constraints) (digest.Digest, []
|
||||
return "", nil, nil, nil, err
|
||||
}
|
||||
|
||||
cgrpParent, err := getCgroupParent(e.base)(ctx, c)
|
||||
if err != nil {
|
||||
return "", nil, nil, nil, err
|
||||
}
|
||||
|
||||
meta := &pb.Meta{
|
||||
Args: args,
|
||||
Env: env.ToArray(),
|
||||
Cwd: cwd,
|
||||
User: user,
|
||||
Hostname: hostname,
|
||||
Args: args,
|
||||
Env: env.ToArray(),
|
||||
Cwd: cwd,
|
||||
User: user,
|
||||
Hostname: hostname,
|
||||
CgroupParent: cgrpParent,
|
||||
}
|
||||
|
||||
extraHosts, err := getExtraHosts(e.base)(ctx, c)
|
||||
@ -554,6 +560,12 @@ func AddUlimit(name UlimitName, soft int64, hard int64) RunOption {
|
||||
})
|
||||
}
|
||||
|
||||
func WithCgroupParent(cp string) RunOption {
|
||||
return runOptionFunc(func(ei *ExecInfo) {
|
||||
ei.State = ei.State.WithCgroupParent(cp)
|
||||
})
|
||||
}
|
||||
|
||||
func With(so ...StateOption) RunOption {
|
||||
return runOptionFunc(func(ei *ExecInfo) {
|
||||
ei.State = ei.State.With(so...)
|
||||
|
25
vendor/github.com/moby/buildkit/client/llb/marshal.go
generated
vendored
25
vendor/github.com/moby/buildkit/client/llb/marshal.go
generated
vendored
@ -12,9 +12,10 @@ import (
|
||||
// Definition is the LLB definition structure with per-vertex metadata entries
|
||||
// Corresponds to the Definition structure defined in solver/pb.Definition.
|
||||
type Definition struct {
|
||||
Def [][]byte
|
||||
Metadata map[digest.Digest]pb.OpMetadata
|
||||
Source *pb.Source
|
||||
Def [][]byte
|
||||
Metadata map[digest.Digest]pb.OpMetadata
|
||||
Source *pb.Source
|
||||
Constraints *Constraints
|
||||
}
|
||||
|
||||
func (def *Definition) ToPB() *pb.Definition {
|
||||
@ -38,6 +39,24 @@ func (def *Definition) FromPB(x *pb.Definition) {
|
||||
}
|
||||
}
|
||||
|
||||
func (def *Definition) Head() (digest.Digest, error) {
|
||||
if len(def.Def) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
last := def.Def[len(def.Def)-1]
|
||||
|
||||
var pop pb.Op
|
||||
if err := (&pop).Unmarshal(last); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(pop.Inputs) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
return pop.Inputs[0].Digest, nil
|
||||
}
|
||||
|
||||
func WriteTo(def *Definition, w io.Writer) error {
|
||||
b, err := def.ToPB().Marshal()
|
||||
if err != nil {
|
||||
|
96
vendor/github.com/moby/buildkit/client/llb/merge.go
generated
vendored
Normal file
96
vendor/github.com/moby/buildkit/client/llb/merge.go
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
package llb
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/moby/buildkit/solver/pb"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type MergeOp struct {
|
||||
MarshalCache
|
||||
inputs []Output
|
||||
output Output
|
||||
constraints Constraints
|
||||
}
|
||||
|
||||
func NewMerge(inputs []State, c Constraints) *MergeOp {
|
||||
op := &MergeOp{constraints: c}
|
||||
for _, input := range inputs {
|
||||
op.inputs = append(op.inputs, input.Output())
|
||||
}
|
||||
op.output = &output{vertex: op}
|
||||
return op
|
||||
}
|
||||
|
||||
func (m *MergeOp) Validate(ctx context.Context, constraints *Constraints) error {
|
||||
if len(m.inputs) < 2 {
|
||||
return errors.Errorf("merge must have at least 2 inputs")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MergeOp) Marshal(ctx context.Context, constraints *Constraints) (digest.Digest, []byte, *pb.OpMetadata, []*SourceLocation, error) {
|
||||
if m.Cached(constraints) {
|
||||
return m.Load()
|
||||
}
|
||||
if err := m.Validate(ctx, constraints); err != nil {
|
||||
return "", nil, nil, nil, err
|
||||
}
|
||||
|
||||
pop, md := MarshalConstraints(constraints, &m.constraints)
|
||||
pop.Platform = nil // merge op is not platform specific
|
||||
|
||||
op := &pb.MergeOp{}
|
||||
for _, input := range m.inputs {
|
||||
op.Inputs = append(op.Inputs, &pb.MergeInput{Input: pb.InputIndex(len(pop.Inputs))})
|
||||
pbInput, err := input.ToInput(ctx, constraints)
|
||||
if err != nil {
|
||||
return "", nil, nil, nil, err
|
||||
}
|
||||
pop.Inputs = append(pop.Inputs, pbInput)
|
||||
}
|
||||
pop.Op = &pb.Op_Merge{Merge: op}
|
||||
|
||||
dt, err := pop.Marshal()
|
||||
if err != nil {
|
||||
return "", nil, nil, nil, err
|
||||
}
|
||||
|
||||
m.Store(dt, md, m.constraints.SourceLocations, constraints)
|
||||
return m.Load()
|
||||
}
|
||||
|
||||
func (m *MergeOp) Output() Output {
|
||||
return m.output
|
||||
}
|
||||
|
||||
func (m *MergeOp) Inputs() []Output {
|
||||
return m.inputs
|
||||
}
|
||||
|
||||
func Merge(inputs []State, opts ...ConstraintsOpt) State {
|
||||
// filter out any scratch inputs, which have no effect when merged
|
||||
var filteredInputs []State
|
||||
for _, input := range inputs {
|
||||
if input.Output() != nil {
|
||||
filteredInputs = append(filteredInputs, input)
|
||||
}
|
||||
}
|
||||
if len(filteredInputs) == 0 {
|
||||
// a merge of only scratch results in scratch
|
||||
return Scratch()
|
||||
}
|
||||
if len(filteredInputs) == 1 {
|
||||
// a merge of a single non-empty input results in that non-empty input
|
||||
return filteredInputs[0]
|
||||
}
|
||||
|
||||
var c Constraints
|
||||
for _, o := range opts {
|
||||
o.SetConstraintsOption(&c)
|
||||
}
|
||||
addCap(&c, pb.CapMergeOp)
|
||||
return NewState(NewMerge(filteredInputs, c).Output())
|
||||
}
|
34
vendor/github.com/moby/buildkit/client/llb/meta.go
generated
vendored
34
vendor/github.com/moby/buildkit/client/llb/meta.go
generated
vendored
@ -15,13 +15,14 @@ import (
|
||||
type contextKeyT string
|
||||
|
||||
var (
|
||||
keyArgs = contextKeyT("llb.exec.args")
|
||||
keyDir = contextKeyT("llb.exec.dir")
|
||||
keyEnv = contextKeyT("llb.exec.env")
|
||||
keyExtraHost = contextKeyT("llb.exec.extrahost")
|
||||
keyHostname = contextKeyT("llb.exec.hostname")
|
||||
keyUlimit = contextKeyT("llb.exec.ulimit")
|
||||
keyUser = contextKeyT("llb.exec.user")
|
||||
keyArgs = contextKeyT("llb.exec.args")
|
||||
keyDir = contextKeyT("llb.exec.dir")
|
||||
keyEnv = contextKeyT("llb.exec.env")
|
||||
keyExtraHost = contextKeyT("llb.exec.extrahost")
|
||||
keyHostname = contextKeyT("llb.exec.hostname")
|
||||
keyUlimit = contextKeyT("llb.exec.ulimit")
|
||||
keyCgroupParent = contextKeyT("llb.exec.cgroup.parent")
|
||||
keyUser = contextKeyT("llb.exec.user")
|
||||
|
||||
keyPlatform = contextKeyT("llb.platform")
|
||||
keyNetwork = contextKeyT("llb.network")
|
||||
@ -263,6 +264,25 @@ func getUlimit(s State) func(context.Context, *Constraints) ([]pb.Ulimit, error)
|
||||
}
|
||||
}
|
||||
|
||||
func cgroupParent(cp string) StateOption {
|
||||
return func(s State) State {
|
||||
return s.WithValue(keyCgroupParent, cp)
|
||||
}
|
||||
}
|
||||
|
||||
func getCgroupParent(s State) func(context.Context, *Constraints) (string, error) {
|
||||
return func(ctx context.Context, c *Constraints) (string, error) {
|
||||
v, err := s.getValue(keyCgroupParent)(ctx, c)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if v != nil {
|
||||
return v.(string), nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
}
|
||||
|
||||
func Network(v pb.NetMode) StateOption {
|
||||
return func(s State) State {
|
||||
return s.WithValue(keyNetwork, v)
|
||||
|
28
vendor/github.com/moby/buildkit/client/llb/state.go
generated
vendored
28
vendor/github.com/moby/buildkit/client/llb/state.go
generated
vendored
@ -29,6 +29,18 @@ type Vertex interface {
|
||||
Inputs() []Output
|
||||
}
|
||||
|
||||
func NewConstraints(co ...ConstraintsOpt) *Constraints {
|
||||
defaultPlatform := platforms.Normalize(platforms.DefaultSpec())
|
||||
c := &Constraints{
|
||||
Platform: &defaultPlatform,
|
||||
LocalUniqueID: identity.NewID(),
|
||||
}
|
||||
for _, o := range co {
|
||||
o.SetConstraintsOption(c)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func NewState(o Output) State {
|
||||
s := State{
|
||||
out: o,
|
||||
@ -112,18 +124,12 @@ func (s State) SetMarshalDefaults(co ...ConstraintsOpt) State {
|
||||
}
|
||||
|
||||
func (s State) Marshal(ctx context.Context, co ...ConstraintsOpt) (*Definition, error) {
|
||||
c := NewConstraints(append(s.opts, co...)...)
|
||||
def := &Definition{
|
||||
Metadata: make(map[digest.Digest]pb.OpMetadata, 0),
|
||||
Metadata: make(map[digest.Digest]pb.OpMetadata, 0),
|
||||
Constraints: c,
|
||||
}
|
||||
|
||||
defaultPlatform := platforms.Normalize(platforms.DefaultSpec())
|
||||
c := &Constraints{
|
||||
Platform: &defaultPlatform,
|
||||
LocalUniqueID: identity.NewID(),
|
||||
}
|
||||
for _, o := range append(s.opts, co...) {
|
||||
o.SetConstraintsOption(c)
|
||||
}
|
||||
if s.Output() == nil || s.Output().Vertex(ctx, c) == nil {
|
||||
return def, nil
|
||||
}
|
||||
@ -401,6 +407,10 @@ func (s State) AddUlimit(name UlimitName, soft int64, hard int64) State {
|
||||
return ulimit(name, soft, hard)(s)
|
||||
}
|
||||
|
||||
func (s State) WithCgroupParent(cp string) State {
|
||||
return cgroupParent(cp)(s)
|
||||
}
|
||||
|
||||
func (s State) isFileOpCopyInput() {}
|
||||
|
||||
type output struct {
|
||||
|
Reference in New Issue
Block a user