vendor: update buildkit to 539be170

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2021-12-15 22:09:13 -08:00
parent 59533bbb5c
commit 9c3be32bc9
581 changed files with 24648 additions and 16682 deletions

View File

@ -148,3 +148,8 @@ func (g *gatewayClientForBuild) ExecProcess(ctx context.Context, opts ...grpc.Ca
ctx = buildid.AppendToOutgoingContext(ctx, g.buildID)
return g.gateway.ExecProcess(ctx, opts...)
}
func (g *gatewayClientForBuild) Warn(ctx context.Context, in *gatewayapi.WarnRequest, opts ...grpc.CallOption) (*gatewayapi.WarnResponse, error) {
ctx = buildid.AppendToOutgoingContext(ctx, g.buildID)
return g.gateway.Warn(ctx, in)
}

View File

@ -43,6 +43,7 @@ func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error
}
needDialer := true
needWithInsecure := true
tlsServerName := ""
var unary []grpc.UnaryClientInterceptor
var stream []grpc.StreamClientInterceptor
@ -63,6 +64,7 @@ func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error
}
gopts = append(gopts, opt)
needWithInsecure = false
tlsServerName = credInfo.ServerName
}
if wt, ok := o.(*withTracer); ok {
customTracer = true
@ -106,14 +108,23 @@ func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error
address = appdefaults.Address
}
// grpc-go uses a slightly different naming scheme: https://github.com/grpc/grpc/blob/master/doc/naming.md
// This will end up setting rfc non-complient :authority header to address string (e.g. tcp://127.0.0.1:1234).
// So, here sets right authority header via WithAuthority DialOption.
addressURL, err := url.Parse(address)
if err != nil {
return nil, err
// Setting :authority pseudo header
// - HTTP/2 (RFC7540) defines :authority pseudo header includes
// the authority portion of target URI but it must not include
// userinfo part (i.e. url.Host).
// ref: https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.3
// - However, when TLS specified, grpc-go requires it must match
// with its servername specified for certificate validation.
authority := tlsServerName
if authority == "" {
// authority as hostname from target address
uri, err := url.Parse(address)
if err != nil {
return nil, err
}
authority = uri.Host
}
gopts = append(gopts, grpc.WithAuthority(addressURL.Host))
gopts = append(gopts, grpc.WithAuthority(authority))
unary = append(unary, grpcerrors.UnaryClientInterceptor)
stream = append(stream, grpcerrors.StreamClientInterceptor)

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows
package client

View File

@ -18,7 +18,7 @@ type UsageInfo struct {
CreatedAt time.Time
LastUsedAt *time.Time
UsageCount int
Parent string
Parents []string
Description string
RecordType UsageRecordType
Shared bool
@ -44,7 +44,7 @@ func (c *Client) DiskUsage(ctx context.Context, opts ...DiskUsageOption) ([]*Usa
Mutable: d.Mutable,
InUse: d.InUse,
Size: d.Size_,
Parent: d.Parent,
Parents: d.Parents,
CreatedAt: d.CreatedAt,
Description: d.Description,
UsageCount: int(d.UsageCount),

View File

@ -3,6 +3,7 @@ package client
import (
"time"
"github.com/moby/buildkit/solver/pb"
digest "github.com/opencontainers/go-digest"
)
@ -34,10 +35,21 @@ type VertexLog struct {
Timestamp time.Time
}
type VertexWarning struct {
Vertex digest.Digest
Level int
Short []byte
Detail [][]byte
URL string
SourceInfo *pb.SourceInfo
Range []*pb.Range
}
type SolveStatus struct {
Vertexes []*Vertex
Statuses []*VertexStatus
Logs []*VertexLog
Warnings []*VertexWarning
}
type SolveResponse struct {

View File

@ -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...)

View File

@ -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
View 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())
}

View File

@ -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)

View File

@ -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 {

View File

@ -42,7 +42,7 @@ func (c *Client) Prune(ctx context.Context, ch chan UsageInfo, opts ...PruneOpti
Mutable: d.Mutable,
InUse: d.InUse,
Size: d.Size_,
Parent: d.Parent,
Parents: d.Parents,
CreatedAt: d.CreatedAt,
Description: d.Description,
UsageCount: int(d.UsageCount),

View File

@ -292,6 +292,17 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runG
Timestamp: v.Timestamp,
})
}
for _, v := range resp.Warnings {
s.Warnings = append(s.Warnings, &VertexWarning{
Vertex: v.Vertex,
Level: int(v.Level),
Short: v.Short,
Detail: v.Detail,
URL: v.Url,
SourceInfo: v.Info,
Range: v.Ranges,
})
}
if statusChan != nil {
statusChan <- &s
}