mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-24 12:18:06 +08:00
history: add support for exporting multiple and all records
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
78
util/desktop/bundle/content.go
Normal file
78
util/desktop/bundle/content.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package bundle
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/containerd/containerd/v2/core/content"
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
)
|
||||
|
||||
type nsFallbackStore struct {
|
||||
main content.Store
|
||||
fb content.Store
|
||||
}
|
||||
|
||||
var _ content.Store = &nsFallbackStore{}
|
||||
|
||||
func (c *nsFallbackStore) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
|
||||
info, err := c.main.Info(ctx, dgst)
|
||||
if err != nil {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
return c.fb.Info(ctx, dgst)
|
||||
}
|
||||
}
|
||||
return info, err
|
||||
}
|
||||
|
||||
func (c *nsFallbackStore) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) {
|
||||
return c.main.Update(ctx, info, fieldpaths...)
|
||||
}
|
||||
|
||||
func (c *nsFallbackStore) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error {
|
||||
seen := make(map[digest.Digest]struct{})
|
||||
err := c.main.Walk(ctx, func(i content.Info) error {
|
||||
seen[i.Digest] = struct{}{}
|
||||
return fn(i)
|
||||
}, filters...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.fb.Walk(ctx, func(i content.Info) error {
|
||||
if _, ok := seen[i.Digest]; ok {
|
||||
return nil
|
||||
}
|
||||
return fn(i)
|
||||
}, filters...)
|
||||
}
|
||||
|
||||
func (c *nsFallbackStore) Delete(ctx context.Context, dgst digest.Digest) error {
|
||||
return c.main.Delete(ctx, dgst)
|
||||
}
|
||||
|
||||
func (c *nsFallbackStore) Status(ctx context.Context, ref string) (content.Status, error) {
|
||||
return c.main.Status(ctx, ref)
|
||||
}
|
||||
|
||||
func (c *nsFallbackStore) ListStatuses(ctx context.Context, filters ...string) ([]content.Status, error) {
|
||||
return c.main.ListStatuses(ctx, filters...)
|
||||
}
|
||||
|
||||
func (c *nsFallbackStore) Abort(ctx context.Context, ref string) error {
|
||||
return c.main.Abort(ctx, ref)
|
||||
}
|
||||
|
||||
func (c *nsFallbackStore) ReaderAt(ctx context.Context, desc ocispecs.Descriptor) (content.ReaderAt, error) {
|
||||
ra, err := c.main.ReaderAt(ctx, desc)
|
||||
if err != nil {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
return c.fb.ReaderAt(ctx, desc)
|
||||
}
|
||||
}
|
||||
return ra, err
|
||||
}
|
||||
|
||||
func (c *nsFallbackStore) Writer(ctx context.Context, opts ...content.WriterOpt) (content.Writer, error) {
|
||||
return c.main.Writer(ctx, opts...)
|
||||
}
|
@@ -32,8 +32,23 @@ type Record struct {
|
||||
StateGroup *localstate.StateGroup `json:"stateGroup,omitempty"`
|
||||
}
|
||||
|
||||
func Export(ctx context.Context, c *client.Client, w io.Writer, records []*Record) error {
|
||||
store := proxy.NewContentStore(c.ContentClient())
|
||||
func Export(ctx context.Context, c []*client.Client, w io.Writer, records []*Record) error {
|
||||
var store content.Store
|
||||
for _, c := range c {
|
||||
s := proxy.NewContentStore(c.ContentClient())
|
||||
if store == nil {
|
||||
store = s
|
||||
break
|
||||
}
|
||||
store = &nsFallbackStore{
|
||||
main: store,
|
||||
fb: s,
|
||||
}
|
||||
}
|
||||
if store == nil {
|
||||
return errors.New("no buildkit client found")
|
||||
}
|
||||
|
||||
mp := contentutil.NewMultiProvider(store)
|
||||
|
||||
desc, err := export(ctx, mp, records)
|
||||
|
@@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/containerd/containerd/v2/core/content"
|
||||
"github.com/docker/buildx/util/otelutil"
|
||||
@@ -17,15 +18,22 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
sensitiveKeys = []string{"ghtoken", "token", "access_key_id", "secret_access_key", "session_token"}
|
||||
reAttrs = regexp.MustCompile(`(?i)(` + strings.Join(sensitiveKeys, "|") + `)=[^ ,]+`)
|
||||
reGhs = regexp.MustCompile(`ghs_[A-Za-z0-9]{36}`)
|
||||
reOnce sync.Once
|
||||
reAttrs, reGhs, reGhpat *regexp.Regexp
|
||||
)
|
||||
|
||||
func sanitizeCommand(value string) string {
|
||||
reOnce.Do(func() {
|
||||
sensitiveKeys := []string{"ghtoken", "token", "access_key_id", "secret_access_key", "session_token"}
|
||||
reAttrs = regexp.MustCompile(`(?i)(` + strings.Join(sensitiveKeys, "|") + `)=[^ ,]+`)
|
||||
reGhs = regexp.MustCompile(`(?:ghu|ghs)_[A-Za-z0-9]{36}`)
|
||||
reGhpat = regexp.MustCompile(`github_pat_\w{82}`)
|
||||
})
|
||||
|
||||
value = reAttrs.ReplaceAllString(value, "${1}=xxxxx")
|
||||
// reGhs is just double proofing. Not really needed.
|
||||
// reGhs/reGhpat is just double proofing. Not really needed.
|
||||
value = reGhs.ReplaceAllString(value, "xxxxx")
|
||||
value = reGhpat.ReplaceAllString(value, "xxxxx")
|
||||
return value
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user