mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: update buildkit with typed errors support
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
95
vendor/github.com/moby/buildkit/client/llb/source.go
generated
vendored
95
vendor/github.com/moby/buildkit/client/llb/source.go
generated
vendored
@ -2,7 +2,7 @@ package llb
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "crypto/sha256"
|
||||
_ "crypto/sha256" // for opencontainers/go-digest
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strconv"
|
||||
@ -34,7 +34,7 @@ func NewSource(id string, attrs map[string]string, c Constraints) *SourceOp {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *SourceOp) Validate() error {
|
||||
func (s *SourceOp) Validate(ctx context.Context) error {
|
||||
if s.err != nil {
|
||||
return s.err
|
||||
}
|
||||
@ -44,12 +44,12 @@ func (s *SourceOp) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SourceOp) Marshal(constraints *Constraints) (digest.Digest, []byte, *pb.OpMetadata, error) {
|
||||
func (s *SourceOp) Marshal(ctx context.Context, constraints *Constraints) (digest.Digest, []byte, *pb.OpMetadata, []*SourceLocation, error) {
|
||||
if s.Cached(constraints) {
|
||||
return s.Load()
|
||||
}
|
||||
if err := s.Validate(); err != nil {
|
||||
return "", nil, nil, err
|
||||
if err := s.Validate(ctx); err != nil {
|
||||
return "", nil, nil, nil, err
|
||||
}
|
||||
|
||||
if strings.HasPrefix(s.id, "local://") {
|
||||
@ -74,10 +74,10 @@ func (s *SourceOp) Marshal(constraints *Constraints) (digest.Digest, []byte, *pb
|
||||
|
||||
dt, err := proto.Marshal()
|
||||
if err != nil {
|
||||
return "", nil, nil, err
|
||||
return "", nil, nil, nil, err
|
||||
}
|
||||
|
||||
s.Store(dt, md, constraints)
|
||||
s.Store(dt, md, s.constraints.SourceLocations, constraints)
|
||||
return s.Load()
|
||||
}
|
||||
|
||||
@ -92,7 +92,8 @@ func (s *SourceOp) Inputs() []Output {
|
||||
func Image(ref string, opts ...ImageOption) State {
|
||||
r, err := reference.ParseNormalizedNamed(ref)
|
||||
if err == nil {
|
||||
ref = reference.TagNameOnly(r).String()
|
||||
r = reference.TagNameOnly(r)
|
||||
ref = r.String()
|
||||
}
|
||||
var info ImageInfo
|
||||
for _, opt := range opts {
|
||||
@ -116,21 +117,35 @@ func Image(ref string, opts ...ImageOption) State {
|
||||
src := NewSource("docker-image://"+ref, attrs, info.Constraints) // controversial
|
||||
if err != nil {
|
||||
src.err = err
|
||||
}
|
||||
if info.metaResolver != nil {
|
||||
_, dt, err := info.metaResolver.ResolveImageConfig(context.TODO(), ref, ResolveImageConfigOpt{
|
||||
Platform: info.Constraints.Platform,
|
||||
ResolveMode: info.resolveMode.String(),
|
||||
})
|
||||
if err != nil {
|
||||
src.err = err
|
||||
} else {
|
||||
st, err := NewState(src.Output()).WithImageConfig(dt)
|
||||
if err == nil {
|
||||
return st
|
||||
}
|
||||
src.err = err
|
||||
} else if info.metaResolver != nil {
|
||||
if _, ok := r.(reference.Digested); ok || !info.resolveDigest {
|
||||
return NewState(src.Output()).Async(func(ctx context.Context, st State) (State, error) {
|
||||
_, dt, err := info.metaResolver.ResolveImageConfig(ctx, ref, ResolveImageConfigOpt{
|
||||
Platform: info.Constraints.Platform,
|
||||
ResolveMode: info.resolveMode.String(),
|
||||
})
|
||||
if err != nil {
|
||||
return State{}, err
|
||||
}
|
||||
return st.WithImageConfig(dt)
|
||||
})
|
||||
}
|
||||
return Scratch().Async(func(ctx context.Context, _ State) (State, error) {
|
||||
dgst, dt, err := info.metaResolver.ResolveImageConfig(context.TODO(), ref, ResolveImageConfigOpt{
|
||||
Platform: info.Constraints.Platform,
|
||||
ResolveMode: info.resolveMode.String(),
|
||||
})
|
||||
if err != nil {
|
||||
return State{}, err
|
||||
}
|
||||
if dgst != "" {
|
||||
r, err = reference.WithDigest(r, dgst)
|
||||
if err != nil {
|
||||
return State{}, err
|
||||
}
|
||||
}
|
||||
return NewState(NewSource("docker-image://"+r.String(), attrs, info.Constraints).Output()).WithImageConfig(dt)
|
||||
})
|
||||
}
|
||||
return NewState(src.Output())
|
||||
}
|
||||
@ -176,9 +191,10 @@ func (r ResolveMode) String() string {
|
||||
|
||||
type ImageInfo struct {
|
||||
constraintsWrapper
|
||||
metaResolver ImageMetaResolver
|
||||
resolveMode ResolveMode
|
||||
RecordType string
|
||||
metaResolver ImageMetaResolver
|
||||
resolveDigest bool
|
||||
resolveMode ResolveMode
|
||||
RecordType string
|
||||
}
|
||||
|
||||
func Git(remote, ref string, opts ...GitOption) State {
|
||||
@ -199,7 +215,10 @@ func Git(remote, ref string, opts ...GitOption) State {
|
||||
id += "#" + ref
|
||||
}
|
||||
|
||||
gi := &GitInfo{}
|
||||
gi := &GitInfo{
|
||||
AuthHeaderSecret: "GIT_AUTH_HEADER",
|
||||
AuthTokenSecret: "GIT_AUTH_TOKEN",
|
||||
}
|
||||
for _, o := range opts {
|
||||
o.SetGitOption(gi)
|
||||
}
|
||||
@ -212,6 +231,14 @@ func Git(remote, ref string, opts ...GitOption) State {
|
||||
attrs[pb.AttrFullRemoteURL] = url
|
||||
addCap(&gi.Constraints, pb.CapSourceGitFullURL)
|
||||
}
|
||||
if gi.AuthTokenSecret != "" {
|
||||
attrs[pb.AttrAuthTokenSecret] = gi.AuthTokenSecret
|
||||
addCap(&gi.Constraints, pb.CapSourceGitHTTPAuth)
|
||||
}
|
||||
if gi.AuthHeaderSecret != "" {
|
||||
attrs[pb.AttrAuthHeaderSecret] = gi.AuthHeaderSecret
|
||||
addCap(&gi.Constraints, pb.CapSourceGitHTTPAuth)
|
||||
}
|
||||
|
||||
addCap(&gi.Constraints, pb.CapSourceGit)
|
||||
|
||||
@ -230,7 +257,9 @@ func (fn gitOptionFunc) SetGitOption(gi *GitInfo) {
|
||||
|
||||
type GitInfo struct {
|
||||
constraintsWrapper
|
||||
KeepGitDir bool
|
||||
KeepGitDir bool
|
||||
AuthTokenSecret string
|
||||
AuthHeaderSecret string
|
||||
}
|
||||
|
||||
func KeepGitDir() GitOption {
|
||||
@ -239,6 +268,18 @@ func KeepGitDir() GitOption {
|
||||
})
|
||||
}
|
||||
|
||||
func AuthTokenSecret(v string) GitOption {
|
||||
return gitOptionFunc(func(gi *GitInfo) {
|
||||
gi.AuthTokenSecret = v
|
||||
})
|
||||
}
|
||||
|
||||
func AuthHeaderSecret(v string) GitOption {
|
||||
return gitOptionFunc(func(gi *GitInfo) {
|
||||
gi.AuthHeaderSecret = v
|
||||
})
|
||||
}
|
||||
|
||||
func Scratch() State {
|
||||
return NewState(nil)
|
||||
}
|
||||
|
Reference in New Issue
Block a user