vendor: github.com/moby/buildkit v0.21.0-rc1

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
Jonathan A. Sternberg
2025-04-09 10:28:03 -05:00
parent a34cdff84e
commit 8fb1157b5f
221 changed files with 6530 additions and 3986 deletions

View File

@ -5,6 +5,7 @@ import (
"context"
"fmt"
"maps"
"math"
"math/rand"
"os"
"os/exec"
@ -12,6 +13,7 @@ import (
"reflect"
"runtime"
"sort"
"strconv"
"strings"
"sync"
"testing"
@ -58,7 +60,7 @@ type Sandbox interface {
PrintLogs(*testing.T)
ClearLogs()
NewRegistry() (string, error)
Value(string) interface{} // chosen matrix value
Value(string) any // chosen matrix value
Name() string
CDISpecDir() string
}
@ -129,10 +131,10 @@ func List() []Worker {
// tests.
type TestOpt func(*testConf)
func WithMatrix(key string, m map[string]interface{}) TestOpt {
func WithMatrix(key string, m map[string]any) TestOpt {
return func(tc *testConf) {
if tc.matrix == nil {
tc.matrix = map[string]map[string]interface{}{}
tc.matrix = map[string]map[string]any{}
}
tc.matrix[key] = m
}
@ -148,7 +150,7 @@ func WithMirroredImages(m map[string]string) TestOpt {
}
type testConf struct {
matrix map[string]map[string]interface{}
matrix map[string]map[string]any
mirroredImages map[string]string
}
@ -161,6 +163,29 @@ func Run(t *testing.T, testCases []Test, opt ...TestOpt) {
t.Skip("skipping integration tests")
}
var sliceSplit int
if filter, ok := lookupTestFilter(); ok {
parts := strings.Split(filter, "/")
if len(parts) >= 2 {
const prefix = "slice="
if strings.HasPrefix(parts[1], prefix) {
conf := strings.TrimPrefix(parts[1], prefix)
offsetS, totalS, ok := strings.Cut(conf, "-")
if !ok {
t.Fatalf("invalid slice=%q", conf)
}
offset, err := strconv.Atoi(offsetS)
require.NoError(t, err)
total, err := strconv.Atoi(totalS)
require.NoError(t, err)
if offset < 1 || total < 1 || offset > total {
t.Fatalf("invalid slice=%q", conf)
}
sliceSplit = total
}
}
}
var tc testConf
for _, o := range opt {
o(&tc)
@ -182,9 +207,14 @@ func Run(t *testing.T, testCases []Test, opt ...TestOpt) {
})
for _, br := range list {
for _, tc := range testCases {
for i, tc := range testCases {
for _, mv := range matrix {
fn := tc.Name()
if sliceSplit > 0 {
pageLimit := int(math.Ceil(float64(len(testCases)) / float64(sliceSplit)))
sliceName := fmt.Sprintf("slice=%d-%d/", i/pageLimit+1, sliceSplit)
fn = sliceName + fn
}
name := fn + "/worker=" + br.Name() + mv.functionSuffix()
func(fn, testName string, br Worker, tc Test, mv matrixValue) {
ok := t.Run(testName, func(t *testing.T) {
@ -221,7 +251,7 @@ func Run(t *testing.T, testCases []Test, opt ...TestOpt) {
}
}
func getFunctionName(i interface{}) string {
func getFunctionName(i any) string {
fullname := runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
dot := strings.LastIndex(fullname, ".") + 1
return strings.Title(fullname[dot:]) //nolint:staticcheck // ignoring "SA1019: strings.Title is deprecated", as for our use we don't need full unicode support
@ -330,37 +360,80 @@ func lazyMirrorRunnerFunc(t *testing.T, images map[string]string) func() string
var mirror string
return func() string {
once.Do(func() {
host, cleanup, err := runMirror(t, images)
m, err := RunMirror()
require.NoError(t, err)
t.Cleanup(func() { _ = cleanup() })
mirror = host
require.NoError(t, m.AddImages(t, images))
t.Cleanup(func() { _ = m.Close() })
mirror = m.Host
})
return mirror
}
}
func runMirror(t *testing.T, mirroredImages map[string]string) (host string, _ func() error, err error) {
type Mirror struct {
Host string
dir string
cleanup func() error
}
func (m *Mirror) lock() (*flock.Flock, error) {
if m.dir == "" {
return nil, nil
}
if err := os.MkdirAll(m.dir, 0700); err != nil {
return nil, err
}
lock := flock.New(filepath.Join(m.dir, "lock"))
if err := lock.Lock(); err != nil {
return nil, err
}
return lock, nil
}
func (m *Mirror) Close() error {
if m.cleanup != nil {
return m.cleanup()
}
return nil
}
func (m *Mirror) AddImages(t *testing.T, images map[string]string) (err error) {
lock, err := m.lock()
if err != nil {
return err
}
defer func() {
if lock != nil {
lock.Unlock()
}
}()
if err := copyImagesLocal(t, m.Host, images); err != nil {
return err
}
return nil
}
func RunMirror() (_ *Mirror, err error) {
mirrorDir := os.Getenv("BUILDKIT_REGISTRY_MIRROR_DIR")
var lock *flock.Flock
if mirrorDir != "" {
if err := os.MkdirAll(mirrorDir, 0700); err != nil {
return "", nil, err
}
lock = flock.New(filepath.Join(mirrorDir, "lock"))
if err := lock.Lock(); err != nil {
return "", nil, err
}
defer func() {
if err != nil {
lock.Unlock()
}
}()
m := &Mirror{
dir: mirrorDir,
}
mirror, cleanup, err := NewRegistry(mirrorDir)
lock, err := m.lock()
if err != nil {
return "", nil, err
return nil, err
}
defer func() {
if err != nil {
lock.Unlock()
}
}()
host, cleanup, err := NewRegistry(mirrorDir)
if err != nil {
return nil, err
}
defer func() {
if err != nil {
@ -368,17 +441,16 @@ func runMirror(t *testing.T, mirroredImages map[string]string) (host string, _ f
}
}()
if err := copyImagesLocal(t, mirror, mirroredImages); err != nil {
return "", nil, err
}
m.Host = host
m.cleanup = cleanup
if mirrorDir != "" {
if lock != nil {
if err := lock.Unlock(); err != nil {
return "", nil, err
return nil, err
}
}
return mirror, cleanup, err
return m, err
}
type matrixValue struct {
@ -400,10 +472,10 @@ func (mv matrixValue) functionSuffix() string {
type matrixValueChoice struct {
name string
value interface{}
value any
}
func newMatrixValue(key, name string, v interface{}) matrixValue {
func newMatrixValue(key, name string, v any) matrixValue {
return matrixValue{
fn: []string{key},
values: map[string]matrixValueChoice{
@ -463,3 +535,13 @@ func UnixOrWindows[T any](unix, windows T) T {
}
return unix
}
func lookupTestFilter() (string, bool) {
const prefix = "-test.run="
for _, arg := range os.Args {
if strings.HasPrefix(arg, prefix) {
return strings.TrimPrefix(arg, prefix), true
}
}
return "", false
}

View File

@ -86,7 +86,7 @@ func (sb *sandbox) Cmd(args ...string) *exec.Cmd {
return cmd
}
func (sb *sandbox) Value(k string) interface{} {
func (sb *sandbox) Value(k string) any {
return sb.mv.values[k].value
}
@ -197,7 +197,7 @@ func RootlessSupported(uid int) bool {
return true
}
func PrintLogs(logs map[string]*bytes.Buffer, f func(args ...interface{})) {
func PrintLogs(logs map[string]*bytes.Buffer, f func(args ...any)) {
for name, l := range logs {
f(name)
s := bufio.NewScanner(l)