vendor: update buildkit to master@cbfd4023383d

Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
Justin Chadwell
2023-09-07 12:13:54 +01:00
parent e018f8b6fb
commit e2ebab5f26
60 changed files with 1912 additions and 664 deletions

View File

@ -57,8 +57,8 @@ type Sandbox interface {
// BackendConfig is used to configure backends created by a worker.
type BackendConfig struct {
Logs map[string]*bytes.Buffer
ConfigFile string
Logs map[string]*bytes.Buffer
DaemonConfig []ConfigUpdater
}
type Worker interface {
@ -303,7 +303,7 @@ mirrors=["%s"]
`, in, mc)
}
func writeConfig(updaters []ConfigUpdater) (string, error) {
func WriteConfig(updaters []ConfigUpdater) (string, error) {
tmpdir, err := os.MkdirTemp("", "bktest_config")
if err != nil {
return "", err
@ -320,7 +320,7 @@ func writeConfig(updaters []ConfigUpdater) (string, error) {
if err := os.WriteFile(filepath.Join(tmpdir, buildkitdConfigFile), []byte(s), 0644); err != nil {
return "", err
}
return tmpdir, nil
return filepath.Join(tmpdir, buildkitdConfigFile), nil
}
func runMirror(t *testing.T, mirroredImages map[string]string) (host string, _ func() error, err error) {

View File

@ -7,12 +7,12 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"github.com/google/shlex"
"github.com/moby/buildkit/util/bklog"
"github.com/pkg/errors"
)
const buildkitdConfigFile = "buildkitd.toml"
@ -77,15 +77,14 @@ func newSandbox(ctx context.Context, w Worker, mirror string, mv matrixValue) (s
Logs: make(map[string]*bytes.Buffer),
}
var upt []ConfigUpdater
for _, v := range mv.values {
if u, ok := v.value.(ConfigUpdater); ok {
upt = append(upt, u)
cfg.DaemonConfig = append(cfg.DaemonConfig, u)
}
}
if mirror != "" {
upt = append(upt, withMirrorConfig(mirror))
cfg.DaemonConfig = append(cfg.DaemonConfig, withMirrorConfig(mirror))
}
deferF := &MultiCloser{}
@ -98,17 +97,6 @@ func newSandbox(ctx context.Context, w Worker, mirror string, mv matrixValue) (s
}
}()
if len(upt) > 0 {
dir, err := writeConfig(upt)
if err != nil {
return nil, nil, err
}
deferF.Append(func() error {
return os.RemoveAll(dir)
})
cfg.ConfigFile = filepath.Join(dir, buildkitdConfigFile)
}
b, closer, err := w.New(ctx, cfg)
if err != nil {
return nil, nil, err
@ -126,7 +114,7 @@ func newSandbox(ctx context.Context, w Worker, mirror string, mv matrixValue) (s
}
func RootlessSupported(uid int) bool {
cmd := exec.Command("sudo", "-E", "-u", fmt.Sprintf("#%d", uid), "-i", "--", "exec", "unshare", "-U", "true") //nolint:gosec // test utility
cmd := exec.Command("sudo", "-u", fmt.Sprintf("#%d", uid), "-i", "--", "exec", "unshare", "-U", "true") //nolint:gosec // test utility
b, err := cmd.CombinedOutput()
if err != nil {
bklog.L.Warnf("rootless mode is not supported on this host: %v (%s)", err, string(b))
@ -156,6 +144,13 @@ func FormatLogs(m map[string]*bytes.Buffer) string {
}
func CheckFeatureCompat(t *testing.T, sb Sandbox, features map[string]struct{}, reason ...string) {
t.Helper()
if err := HasFeatureCompat(t, sb, features, reason...); err != nil {
t.Skipf(err.Error())
}
}
func HasFeatureCompat(t *testing.T, sb Sandbox, features map[string]struct{}, reason ...string) error {
t.Helper()
if len(reason) == 0 {
t.Fatal("no reason provided")
@ -172,6 +167,7 @@ func CheckFeatureCompat(t *testing.T, sb Sandbox, features map[string]struct{},
}
}
if len(ereasons) > 0 {
t.Skipf("%s worker can not currently run this test due to missing features (%s)", sb.Name(), strings.Join(ereasons, ", "))
return errors.Errorf("%s worker can not currently run this test due to missing features (%s)", sb.Name(), strings.Join(ereasons, ", "))
}
return nil
}

View File

@ -168,7 +168,7 @@ disabled_plugins = ["cri"]
containerdArgs := []string{c.Containerd, "--config", configFile}
rootlessKitState := filepath.Join(tmpdir, "rootlesskit-containerd")
if rootless {
containerdArgs = append(append([]string{"sudo", "-E", "-u", fmt.Sprintf("#%d", c.UID), "-i",
containerdArgs = append(append([]string{"sudo", "-u", fmt.Sprintf("#%d", c.UID), "-i",
fmt.Sprintf("CONTAINERD_ROOTLESS_ROOTLESSKIT_STATE_DIR=%s", rootlessKitState),
// Integration test requires the access to localhost of the host network namespace.
// TODO: remove these configurations
@ -211,7 +211,7 @@ disabled_plugins = ["cri"]
if err != nil {
return nil, nil, err
}
buildkitdArgs = append([]string{"sudo", "-E", "-u", fmt.Sprintf("#%d", c.UID), "-i", "--", "exec",
buildkitdArgs = append([]string{"sudo", "-u", fmt.Sprintf("#%d", c.UID), "-i", "--", "exec",
"nsenter", "-U", "--preserve-credentials", "-m", "-t", fmt.Sprintf("%d", pid)},
append(buildkitdArgs, "--containerd-worker-snapshotter=native")...)
}

View File

@ -76,9 +76,27 @@ func (c Moby) New(ctx context.Context, cfg *integration.BackendConfig) (b integr
return nil, nil, err
}
bkcfg, err := config.LoadFile(cfg.ConfigFile)
deferF := &integration.MultiCloser{}
cl = deferF.F()
defer func() {
if err != nil {
deferF.F()()
cl = nil
}
}()
cfgFile, err := integration.WriteConfig(cfg.DaemonConfig)
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to load buildkit config file %s", cfg.ConfigFile)
return nil, nil, err
}
deferF.Append(func() error {
return os.RemoveAll(filepath.Dir(cfgFile))
})
bkcfg, err := config.LoadFile(cfgFile)
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to load buildkit config file %s", cfgFile)
}
dcfg := dockerd.Config{
@ -107,16 +125,6 @@ func (c Moby) New(ctx context.Context, cfg *integration.BackendConfig) (b integr
return nil, nil, errors.Wrapf(err, "failed to marshal dockerd config")
}
deferF := &integration.MultiCloser{}
cl = deferF.F()
defer func() {
if err != nil {
deferF.F()()
cl = nil
}
}()
var proxyGroup errgroup.Group
deferF.Append(proxyGroup.Wait)

View File

@ -61,3 +61,7 @@ var features = map[string]struct{}{
func CheckFeatureCompat(t *testing.T, sb integration.Sandbox, reason ...string) {
integration.CheckFeatureCompat(t, sb, features, reason...)
}
func HasFeatureCompat(t *testing.T, sb integration.Sandbox, reason ...string) error {
return integration.HasFeatureCompat(t, sb, features, reason...)
}

View File

@ -66,7 +66,7 @@ func (s *OCI) New(ctx context.Context, cfg *integration.BackendConfig) (integrat
return nil, nil, errors.Errorf("unsupported id pair: uid=%d, gid=%d", s.UID, s.GID)
}
// TODO: make sure the user exists and subuid/subgid are configured.
buildkitdArgs = append([]string{"sudo", "-E", "-u", fmt.Sprintf("#%d", s.UID), "-i", "--", "exec", "rootlesskit"}, buildkitdArgs...)
buildkitdArgs = append([]string{"sudo", "-u", fmt.Sprintf("#%d", s.UID), "-i", "--", "exec", "rootlesskit"}, buildkitdArgs...)
}
var extraEnv []string

View File

@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
@ -32,10 +33,6 @@ func runBuildkitd(ctx context.Context, conf *integration.BackendConfig, args []s
}
}()
if conf.ConfigFile != "" {
args = append(args, "--config="+conf.ConfigFile)
}
tmpdir, err := os.MkdirTemp("", "bktest_buildkitd")
if err != nil {
return "", nil, err
@ -49,14 +46,22 @@ func runBuildkitd(ctx context.Context, conf *integration.BackendConfig, args []s
if err := os.Chown(filepath.Join(tmpdir, "tmp"), uid, gid); err != nil {
return "", nil, err
}
deferF.Append(func() error { return os.RemoveAll(tmpdir) })
cfgfile, err := integration.WriteConfig(append(conf.DaemonConfig, withOTELSocketPath(getTraceSocketPath(tmpdir))))
if err != nil {
return "", nil, err
}
deferF.Append(func() error {
return os.RemoveAll(filepath.Dir(cfgfile))
})
args = append(args, "--config="+cfgfile)
address = getBuildkitdAddr(tmpdir)
args = append(args, "--root", tmpdir, "--addr", address, "--debug")
cmd := exec.Command(args[0], args[1:]...) //nolint:gosec // test utility
cmd.Env = append(os.Environ(), "BUILDKIT_DEBUG_EXEC_OUTPUT=1", "BUILDKIT_DEBUG_PANIC_ON_ERROR=1", "BUILDKIT_TRACE_SOCKET="+getTraceSocketPath(tmpdir), "TMPDIR="+filepath.Join(tmpdir, "tmp"))
cmd.Env = append(os.Environ(), "BUILDKIT_DEBUG_EXEC_OUTPUT=1", "BUILDKIT_DEBUG_PANIC_ON_ERROR=1", "TMPDIR="+filepath.Join(tmpdir, "tmp"))
cmd.Env = append(cmd.Env, extraEnv...)
cmd.SysProcAttr = getSysProcAttr()
@ -87,3 +92,17 @@ func runBuildkitd(ctx context.Context, conf *integration.BackendConfig, args []s
return address, cl, err
}
func withOTELSocketPath(socketPath string) integration.ConfigUpdater {
return otelSocketPath(socketPath)
}
type otelSocketPath string
func (osp otelSocketPath) UpdateConfigFile(in string) string {
return fmt.Sprintf(`%s
[otel]
socketPath = %q
`, in, osp)
}