mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
deps: update buildkit, vendor changes
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
This commit is contained in:
5
vendor/github.com/moby/buildkit/util/testutil/integration/registry.go
generated
vendored
5
vendor/github.com/moby/buildkit/util/testutil/integration/registry.go
generated
vendored
@ -67,8 +67,9 @@ http:
|
||||
}
|
||||
deferF.Append(stop)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
ctx, cancel := context.WithCancelCause(context.Background())
|
||||
ctx, _ = context.WithTimeoutCause(ctx, 5*time.Second, errors.WithStack(context.DeadlineExceeded))
|
||||
defer cancel(errors.WithStack(context.Canceled))
|
||||
url, err = detectPort(ctx, rc)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
|
7
vendor/github.com/moby/buildkit/util/testutil/integration/run.go
generated
vendored
7
vendor/github.com/moby/buildkit/util/testutil/integration/run.go
generated
vendored
@ -423,3 +423,10 @@ func prepareValueMatrix(tc testConf) []matrixValue {
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// Skips tests on Windows
|
||||
func SkipOnPlatform(t *testing.T, goos string) {
|
||||
if runtime.GOOS == goos {
|
||||
t.Skipf("Skipped on %s", goos)
|
||||
}
|
||||
}
|
||||
|
2
vendor/github.com/moby/buildkit/util/testutil/integration/sandbox.go
generated
vendored
2
vendor/github.com/moby/buildkit/util/testutil/integration/sandbox.go
generated
vendored
@ -99,7 +99,7 @@ func newSandbox(ctx context.Context, w Worker, mirror string, mv matrixValue) (s
|
||||
|
||||
b, closer, err := w.New(ctx, cfg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, errors.Wrap(err, "creating worker")
|
||||
}
|
||||
deferF.Append(closer)
|
||||
|
||||
|
15
vendor/github.com/moby/buildkit/util/testutil/integration/util.go
generated
vendored
15
vendor/github.com/moby/buildkit/util/testutil/integration/util.go
generated
vendored
@ -5,7 +5,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
@ -100,13 +99,11 @@ func StartCmd(cmd *exec.Cmd, logs map[string]*bytes.Buffer) (func() error, error
|
||||
}, nil
|
||||
}
|
||||
|
||||
func WaitUnix(address string, d time.Duration, cmd *exec.Cmd) error {
|
||||
address = strings.TrimPrefix(address, "unix://")
|
||||
addr, err := net.ResolveUnixAddr("unix", address)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed resolving unix addr: %s", address)
|
||||
}
|
||||
|
||||
// WaitSocket will dial a socket opened by a command passed in as cmd.
|
||||
// On Linux this socket is typically a Unix socket,
|
||||
// while on Windows this will be a named pipe.
|
||||
func WaitSocket(address string, d time.Duration, cmd *exec.Cmd) error {
|
||||
address = strings.TrimPrefix(address, socketScheme)
|
||||
step := 50 * time.Millisecond
|
||||
i := 0
|
||||
for {
|
||||
@ -114,7 +111,7 @@ func WaitUnix(address string, d time.Duration, cmd *exec.Cmd) error {
|
||||
return errors.Errorf("process exited: %s", cmd.String())
|
||||
}
|
||||
|
||||
if conn, err := net.DialUnix("unix", nil, addr); err == nil {
|
||||
if conn, err := dialPipe(address); err == nil {
|
||||
conn.Close()
|
||||
break
|
||||
}
|
||||
|
23
vendor/github.com/moby/buildkit/util/testutil/integration/util_unix.go
generated
vendored
Normal file
23
vendor/github.com/moby/buildkit/util/testutil/integration/util_unix.go
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var socketScheme = "unix://"
|
||||
|
||||
// abstracted function to handle pipe dialing on unix.
|
||||
// some simplification has been made to discard
|
||||
// laddr for unix -- left as nil.
|
||||
func dialPipe(address string) (net.Conn, error) {
|
||||
addr, err := net.ResolveUnixAddr("unix", address)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed resolving unix addr: %s", address)
|
||||
}
|
||||
return net.DialUnix("unix", nil, addr)
|
||||
}
|
15
vendor/github.com/moby/buildkit/util/testutil/integration/util_windows.go
generated
vendored
Normal file
15
vendor/github.com/moby/buildkit/util/testutil/integration/util_windows.go
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/Microsoft/go-winio"
|
||||
)
|
||||
|
||||
var socketScheme = "npipe://"
|
||||
|
||||
// abstracted function to handle pipe dialing on windows.
|
||||
// some simplification has been made to discard timeout param.
|
||||
func dialPipe(address string) (net.Conn, error) {
|
||||
return winio.DialPipe(address, nil)
|
||||
}
|
26
vendor/github.com/moby/buildkit/util/testutil/workers/containerd.go
generated
vendored
26
vendor/github.com/moby/buildkit/util/testutil/workers/containerd.go
generated
vendored
@ -88,9 +88,11 @@ func (c *Containerd) New(ctx context.Context, cfg *integration.BackendConfig) (b
|
||||
if err := integration.LookupBinary(c.Containerd); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if err := integration.LookupBinary("buildkitd"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if err := requireRoot(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -117,6 +119,7 @@ func (c *Containerd) New(ctx context.Context, cfg *integration.BackendConfig) (b
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if rootless {
|
||||
if err := os.Chown(tmpdir, c.UID, c.GID); err != nil {
|
||||
return nil, nil, err
|
||||
@ -125,7 +128,7 @@ func (c *Containerd) New(ctx context.Context, cfg *integration.BackendConfig) (b
|
||||
|
||||
deferF.Append(func() error { return os.RemoveAll(tmpdir) })
|
||||
|
||||
address := filepath.Join(tmpdir, "containerd.sock")
|
||||
address := getContainerdSock(tmpdir)
|
||||
config := fmt.Sprintf(`root = %q
|
||||
state = %q
|
||||
# CRI plugins listens on 10010/tcp for stream server.
|
||||
@ -137,8 +140,11 @@ disabled_plugins = ["cri"]
|
||||
|
||||
[debug]
|
||||
level = "debug"
|
||||
address = %q
|
||||
`, filepath.Join(tmpdir, "root"), filepath.Join(tmpdir, "state"), address, filepath.Join(tmpdir, "debug.sock"))
|
||||
address = %q`,
|
||||
filepath.Join(tmpdir, "root"),
|
||||
filepath.Join(tmpdir, "state"),
|
||||
address, getContainerdDebugSock(tmpdir),
|
||||
)
|
||||
|
||||
var snBuildkitdArgs []string
|
||||
if c.Snapshotter != "" {
|
||||
@ -185,19 +191,23 @@ disabled_plugins = ["cri"]
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if err := integration.WaitUnix(address, 10*time.Second, cmd); err != nil {
|
||||
if err := integration.WaitSocket(address, 10*time.Second, cmd); err != nil {
|
||||
ctdStop()
|
||||
return nil, nil, errors.Wrapf(err, "containerd did not start up: %s", integration.FormatLogs(cfg.Logs))
|
||||
}
|
||||
deferF.Append(ctdStop)
|
||||
|
||||
buildkitdArgs := append([]string{"buildkitd",
|
||||
"--oci-worker=false",
|
||||
// handles only windows case, no effect on unix
|
||||
address = normalizeAddress(address)
|
||||
buildkitdArgs := []string{
|
||||
"buildkitd",
|
||||
"--containerd-worker-gc=false",
|
||||
"--containerd-worker=true",
|
||||
"--containerd-worker-addr", address,
|
||||
"--containerd-worker-labels=org.mobyproject.buildkit.worker.sandbox=true", // Include use of --containerd-worker-labels to trigger https://github.com/moby/buildkit/pull/603
|
||||
}, snBuildkitdArgs...)
|
||||
}
|
||||
buildkitdArgs = applyBuildkitdPlatformFlags(buildkitdArgs)
|
||||
buildkitdArgs = append(buildkitdArgs, snBuildkitdArgs...)
|
||||
|
||||
if runtime.GOOS != "windows" && c.Snapshotter != "native" {
|
||||
c.ExtraEnv = append(c.ExtraEnv, "BUILDKIT_DEBUG_FORCE_OVERLAY_DIFF=true")
|
||||
@ -266,7 +276,7 @@ func runStargzSnapshotter(cfg *integration.BackendConfig) (address string, cl fu
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err = integration.WaitUnix(address, 10*time.Second, cmd); err != nil {
|
||||
if err = integration.WaitSocket(address, 10*time.Second, cmd); err != nil {
|
||||
snStop()
|
||||
return "", nil, errors.Wrapf(err, "containerd-stargz-grpc did not start up: %s", integration.FormatLogs(cfg.Logs))
|
||||
}
|
||||
|
2
vendor/github.com/moby/buildkit/util/testutil/workers/dockerd.go
generated
vendored
2
vendor/github.com/moby/buildkit/util/testutil/workers/dockerd.go
generated
vendored
@ -159,7 +159,7 @@ func (c Moby) New(ctx context.Context, cfg *integration.BackendConfig) (b integr
|
||||
}
|
||||
deferF.Append(d.StopWithError)
|
||||
|
||||
if err := integration.WaitUnix(d.Sock(), 5*time.Second, nil); err != nil {
|
||||
if err := integration.WaitSocket(d.Sock(), 5*time.Second, nil); err != nil {
|
||||
return nil, nil, errors.Errorf("dockerd did not start up: %q, %s", err, integration.FormatLogs(cfg.Logs))
|
||||
}
|
||||
|
||||
|
23
vendor/github.com/moby/buildkit/util/testutil/workers/oci.go
generated
vendored
23
vendor/github.com/moby/buildkit/util/testutil/workers/oci.go
generated
vendored
@ -4,31 +4,18 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/moby/buildkit/util/bklog"
|
||||
"github.com/moby/buildkit/util/testutil/integration"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// InitOCIWorker registers an integration test worker, which enables the --oci-worker
|
||||
// flag in the test buildkitd instance and disables the --containerd-worker flag. This
|
||||
// integration test worker is not supported on Windows.
|
||||
func InitOCIWorker() {
|
||||
integration.Register(&OCI{ID: "oci"})
|
||||
|
||||
// the rootless uid is defined in Dockerfile
|
||||
if s := os.Getenv("BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR"); s != "" {
|
||||
var uid, gid int
|
||||
if _, err := fmt.Sscanf(s, "%d:%d", &uid, &gid); err != nil {
|
||||
bklog.L.Fatalf("unexpected BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR: %q", s)
|
||||
}
|
||||
if integration.RootlessSupported(uid) {
|
||||
integration.Register(&OCI{ID: "oci-rootless", UID: uid, GID: gid})
|
||||
}
|
||||
}
|
||||
|
||||
if s := os.Getenv("BUILDKIT_INTEGRATION_SNAPSHOTTER"); s != "" {
|
||||
integration.Register(&OCI{ID: "oci-snapshotter-" + s, Snapshotter: s})
|
||||
}
|
||||
// calling platform specific
|
||||
initOCIWorker()
|
||||
}
|
||||
|
||||
type OCI struct {
|
||||
|
31
vendor/github.com/moby/buildkit/util/testutil/workers/oci_unix.go
generated
vendored
Normal file
31
vendor/github.com/moby/buildkit/util/testutil/workers/oci_unix.go
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package workers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/moby/buildkit/util/bklog"
|
||||
"github.com/moby/buildkit/util/testutil/integration"
|
||||
)
|
||||
|
||||
func initOCIWorker() {
|
||||
integration.Register(&OCI{ID: "oci"})
|
||||
|
||||
// the rootless uid is defined in Dockerfile
|
||||
if s := os.Getenv("BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR"); s != "" {
|
||||
var uid, gid int
|
||||
if _, err := fmt.Sscanf(s, "%d:%d", &uid, &gid); err != nil {
|
||||
bklog.L.Fatalf("unexpected BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR: %q", s)
|
||||
}
|
||||
if integration.RootlessSupported(uid) {
|
||||
integration.Register(&OCI{ID: "oci-rootless", UID: uid, GID: gid})
|
||||
}
|
||||
}
|
||||
|
||||
if s := os.Getenv("BUILDKIT_INTEGRATION_SNAPSHOTTER"); s != "" {
|
||||
integration.Register(&OCI{ID: "oci-snapshotter-" + s, Snapshotter: s})
|
||||
}
|
||||
}
|
7
vendor/github.com/moby/buildkit/util/testutil/workers/oci_windows.go
generated
vendored
Normal file
7
vendor/github.com/moby/buildkit/util/testutil/workers/oci_windows.go
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
package workers
|
||||
|
||||
import "github.com/moby/buildkit/util/bklog"
|
||||
|
||||
func initOCIWorker() {
|
||||
bklog.L.Info("OCI Worker not supported on Windows.")
|
||||
}
|
23
vendor/github.com/moby/buildkit/util/testutil/workers/sysprocattr_unix.go
generated
vendored
23
vendor/github.com/moby/buildkit/util/testutil/workers/sysprocattr_unix.go
generated
vendored
@ -1,23 +0,0 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package workers
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func getSysProcAttr() *syscall.SysProcAttr {
|
||||
return &syscall.SysProcAttr{
|
||||
Setsid: true, // stretch sudo needs this for sigterm
|
||||
}
|
||||
}
|
||||
|
||||
func getBuildkitdAddr(tmpdir string) string {
|
||||
return "unix://" + filepath.Join(tmpdir, "buildkitd.sock")
|
||||
}
|
||||
|
||||
func getTraceSocketPath(tmpdir string) string {
|
||||
return filepath.Join(tmpdir, "otel-grpc.sock")
|
||||
}
|
21
vendor/github.com/moby/buildkit/util/testutil/workers/sysprocattr_windows.go
generated
vendored
21
vendor/github.com/moby/buildkit/util/testutil/workers/sysprocattr_windows.go
generated
vendored
@ -1,21 +0,0 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package workers
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func getSysProcAttr() *syscall.SysProcAttr {
|
||||
return &syscall.SysProcAttr{}
|
||||
}
|
||||
|
||||
func getBuildkitdAddr(tmpdir string) string {
|
||||
return "//./pipe/buildkitd-" + filepath.Base(tmpdir)
|
||||
}
|
||||
|
||||
func getTraceSocketPath(tmpdir string) string {
|
||||
return `\\.\pipe\buildkit-otel-grpc-` + filepath.Base(tmpdir)
|
||||
}
|
157
vendor/github.com/moby/buildkit/util/testutil/workers/util.go
generated
vendored
157
vendor/github.com/moby/buildkit/util/testutil/workers/util.go
generated
vendored
@ -1,98 +1,17 @@
|
||||
package workers
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/moby/buildkit/util/testutil/integration"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func requireRoot() error {
|
||||
if os.Getuid() != 0 {
|
||||
return errors.Wrap(integration.ErrRequirements, "requires root")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func runBuildkitd(ctx context.Context, conf *integration.BackendConfig, args []string, logs map[string]*bytes.Buffer, uid, gid int, extraEnv []string) (address string, cl func() error, err error) {
|
||||
deferF := &integration.MultiCloser{}
|
||||
cl = deferF.F()
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
deferF.F()()
|
||||
cl = nil
|
||||
}
|
||||
}()
|
||||
|
||||
tmpdir, err := os.MkdirTemp("", "bktest_buildkitd")
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := os.Chown(tmpdir, uid, gid); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Join(tmpdir, "tmp"), 0711); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
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", "TMPDIR="+filepath.Join(tmpdir, "tmp"))
|
||||
cmd.Env = append(cmd.Env, extraEnv...)
|
||||
cmd.SysProcAttr = getSysProcAttr()
|
||||
|
||||
stop, err := integration.StartCmd(cmd, logs)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
deferF.Append(stop)
|
||||
|
||||
if err := integration.WaitUnix(address, 15*time.Second, cmd); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
deferF.Append(func() error {
|
||||
f, err := os.Open("/proc/self/mountinfo")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to open mountinfo")
|
||||
}
|
||||
defer f.Close()
|
||||
s := bufio.NewScanner(f)
|
||||
for s.Scan() {
|
||||
if strings.Contains(s.Text(), tmpdir) {
|
||||
return errors.Errorf("leaked mountpoint for %s", tmpdir)
|
||||
}
|
||||
}
|
||||
return s.Err()
|
||||
})
|
||||
|
||||
return address, cl, err
|
||||
}
|
||||
|
||||
func withOTELSocketPath(socketPath string) integration.ConfigUpdater {
|
||||
return otelSocketPath(socketPath)
|
||||
}
|
||||
@ -106,3 +25,79 @@ func (osp otelSocketPath) UpdateConfigFile(in string) string {
|
||||
socketPath = %q
|
||||
`, in, osp)
|
||||
}
|
||||
|
||||
func runBuildkitd(
|
||||
ctx context.Context,
|
||||
conf *integration.BackendConfig,
|
||||
args []string,
|
||||
logs map[string]*bytes.Buffer,
|
||||
uid, gid int,
|
||||
extraEnv []string,
|
||||
) (address string, cl func() error, err error) {
|
||||
deferF := &integration.MultiCloser{}
|
||||
cl = deferF.F()
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
deferF.F()()
|
||||
cl = nil
|
||||
}
|
||||
}()
|
||||
|
||||
tmpdir, err := os.MkdirTemp("", "bktest_buildkitd")
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if err := chown(tmpdir, uid, gid); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Join(tmpdir, "tmp"), 0711); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if err := 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",
|
||||
"TMPDIR="+filepath.Join(tmpdir, "tmp"))
|
||||
cmd.Env = append(cmd.Env, extraEnv...)
|
||||
cmd.SysProcAttr = getSysProcAttr()
|
||||
|
||||
stop, err := integration.StartCmd(cmd, logs)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
deferF.Append(stop)
|
||||
|
||||
if err := integration.WaitSocket(address, 15*time.Second, cmd); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
// separated out since it's not required in windows
|
||||
deferF.Append(func() error {
|
||||
return mountInfo(tmpdir)
|
||||
})
|
||||
|
||||
return address, cl, err
|
||||
}
|
||||
|
74
vendor/github.com/moby/buildkit/util/testutil/workers/util_unix.go
generated
vendored
Normal file
74
vendor/github.com/moby/buildkit/util/testutil/workers/util_unix.go
generated
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package workers
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/moby/buildkit/util/testutil/integration"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func applyBuildkitdPlatformFlags(args []string) []string {
|
||||
return append(args, "--oci-worker=false")
|
||||
}
|
||||
|
||||
func requireRoot() error {
|
||||
if os.Getuid() != 0 {
|
||||
return errors.Wrap(integration.ErrRequirements, "requires root")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getSysProcAttr() *syscall.SysProcAttr {
|
||||
return &syscall.SysProcAttr{
|
||||
Setsid: true, // stretch sudo needs this for sigterm
|
||||
}
|
||||
}
|
||||
|
||||
func getBuildkitdAddr(tmpdir string) string {
|
||||
return "unix://" + filepath.Join(tmpdir, "buildkitd.sock")
|
||||
}
|
||||
|
||||
func getTraceSocketPath(tmpdir string) string {
|
||||
return filepath.Join(tmpdir, "otel-grpc.sock")
|
||||
}
|
||||
|
||||
func getContainerdSock(tmpdir string) string {
|
||||
return filepath.Join(tmpdir, "containerd.sock")
|
||||
}
|
||||
|
||||
func getContainerdDebugSock(tmpdir string) string {
|
||||
return filepath.Join(tmpdir, "debug.sock")
|
||||
}
|
||||
|
||||
func mountInfo(tmpdir string) error {
|
||||
f, err := os.Open("/proc/self/mountinfo")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to open mountinfo")
|
||||
}
|
||||
defer f.Close()
|
||||
s := bufio.NewScanner(f)
|
||||
for s.Scan() {
|
||||
if strings.Contains(s.Text(), tmpdir) {
|
||||
return errors.Errorf("leaked mountpoint for %s", tmpdir)
|
||||
}
|
||||
}
|
||||
return s.Err()
|
||||
}
|
||||
|
||||
// moved here since os.Chown is not supported on Windows.
|
||||
// see no-op counterpart in util_windows.go
|
||||
func chown(name string, uid, gid int) error {
|
||||
return os.Chown(name, uid, gid)
|
||||
}
|
||||
|
||||
func normalizeAddress(address string) string {
|
||||
// for parity with windows, no effect for unix
|
||||
return address
|
||||
}
|
53
vendor/github.com/moby/buildkit/util/testutil/workers/util_windows.go
generated
vendored
Normal file
53
vendor/github.com/moby/buildkit/util/testutil/workers/util_windows.go
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
package workers
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func applyBuildkitdPlatformFlags(args []string) []string {
|
||||
return args
|
||||
}
|
||||
|
||||
func requireRoot() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getSysProcAttr() *syscall.SysProcAttr {
|
||||
return &syscall.SysProcAttr{}
|
||||
}
|
||||
|
||||
func getBuildkitdAddr(tmpdir string) string {
|
||||
return "npipe:////./pipe/buildkitd-" + filepath.Base(tmpdir)
|
||||
}
|
||||
|
||||
func getTraceSocketPath(tmpdir string) string {
|
||||
return `\\.\pipe\buildkit-otel-grpc-` + filepath.Base(tmpdir)
|
||||
}
|
||||
|
||||
func getContainerdSock(tmpdir string) string {
|
||||
return `\\.\pipe\containerd-` + filepath.Base(tmpdir)
|
||||
}
|
||||
|
||||
func getContainerdDebugSock(tmpdir string) string {
|
||||
return `\\.\pipe\containerd-` + filepath.Base(tmpdir) + `debug`
|
||||
}
|
||||
|
||||
// no-op for parity with unix
|
||||
func mountInfo(tmpdir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func chown(name string, uid, gid int) error {
|
||||
// Chown not supported on Windows
|
||||
return nil
|
||||
}
|
||||
|
||||
func normalizeAddress(address string) string {
|
||||
address = filepath.ToSlash(address)
|
||||
if !strings.HasPrefix(address, "npipe://") {
|
||||
address = "npipe://" + address
|
||||
}
|
||||
return address
|
||||
}
|
Reference in New Issue
Block a user