vendor: github.com/moby/buildkit 25bec7145b39 (v0.14.0-dev)

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2024-03-28 17:43:43 +01:00
parent 8abef59087
commit de5efcb03b
31 changed files with 402 additions and 232 deletions

View File

@ -25,7 +25,7 @@ func (nopLog) Logf(string, ...interface{}) {}
const (
shortLen = 12
defaultDockerdBinary = "dockerd"
DefaultDockerdBinary = "dockerd"
)
type Option func(*Daemon)
@ -43,6 +43,7 @@ type Daemon struct {
pidFile string
sockPath string
args []string
envs []string
}
var sockRoot = filepath.Join(os.TempDir(), "docker-integration")
@ -69,9 +70,10 @@ func NewDaemon(workingDir string, ops ...Option) (*Daemon, error) {
storageDriver: os.Getenv("DOCKER_GRAPHDRIVER"),
// dxr stands for docker-execroot (shortened for avoiding unix(7) path length limitation)
execRoot: filepath.Join(os.TempDir(), "dxr", id),
dockerdBinary: defaultDockerdBinary,
dockerdBinary: DefaultDockerdBinary,
Log: nopLog{},
sockPath: filepath.Join(sockRoot, id+".sock"),
envs: append([]string{}, os.Environ()...),
}
for _, op := range ops {
@ -81,6 +83,18 @@ func NewDaemon(workingDir string, ops ...Option) (*Daemon, error) {
return d, nil
}
func WithBinary(bin string) Option {
return func(d *Daemon) {
d.dockerdBinary = bin
}
}
func WithExtraEnv(envs []string) Option {
return func(d *Daemon) {
d.envs = append(d.envs, envs...)
}
}
func (d *Daemon) Sock() string {
return "unix://" + d.sockPath
}
@ -88,7 +102,7 @@ func (d *Daemon) Sock() string {
func (d *Daemon) StartWithError(daemonLogs map[string]*bytes.Buffer, providedArgs ...string) error {
dockerdBinary, err := exec.LookPath(d.dockerdBinary)
if err != nil {
return errors.Wrapf(err, "[%s] could not find docker binary in $PATH", d.id)
return errors.Wrapf(err, "[%s] could not find dockerd binary %q in $PATH", d.id, d.dockerdBinary)
}
if d.pidFile == "" {
@ -127,7 +141,7 @@ func (d *Daemon) StartWithError(daemonLogs map[string]*bytes.Buffer, providedArg
d.args = append(d.args, providedArgs...)
d.cmd = exec.Command(dockerdBinary, d.args...)
d.cmd.Env = append(os.Environ(), "DOCKER_SERVICE_PREFER_OFFLINE_IMAGE=1", "BUILDKIT_DEBUG_EXEC_OUTPUT=1", "BUILDKIT_DEBUG_PANIC_ON_ERROR=1")
d.cmd.Env = append(d.envs, "DOCKER_SERVICE_PREFER_OFFLINE_IMAGE=1", "BUILDKIT_DEBUG_EXEC_OUTPUT=1", "BUILDKIT_DEBUG_PANIC_ON_ERROR=1")
if daemonLogs != nil {
b := new(bytes.Buffer)

View File

@ -40,6 +40,7 @@ type Backend interface {
Rootless() bool
NetNSDetached() bool
Snapshotter() string
ExtraEnv() []string
Supports(feature string) bool
}

View File

@ -4,6 +4,9 @@ import (
"net"
"github.com/Microsoft/go-winio"
// include npipe connhelper for windows tests
_ "github.com/moby/buildkit/client/connhelper/npipe"
)
var socketScheme = "npipe://"

View File

@ -12,6 +12,7 @@ type backend struct {
rootless bool
netnsDetached bool
snapshotter string
extraEnv []string
unsupportedFeatures []string
isDockerd bool
}
@ -40,6 +41,10 @@ func (b backend) Snapshotter() string {
return b.snapshotter
}
func (b backend) ExtraEnv() []string {
return b.extraEnv
}
func (b backend) Supports(feature string) bool {
if enabledFeatures := os.Getenv("BUILDKIT_TEST_ENABLE_FEATURES"); enabledFeatures != "" {
for _, enabledFeature := range strings.Split(enabledFeatures, ",") {

View File

@ -244,6 +244,7 @@ disabled_plugins = ["cri"]
rootless: rootless,
netnsDetached: false,
snapshotter: c.Snapshotter,
extraEnv: c.ExtraEnv,
}, cl, nil
}

View File

@ -55,12 +55,12 @@ func InitDockerdWorker() {
}
type Moby struct {
ID string
IsRootless bool
ID string
Binary string
IsRootless bool
ContainerdSnapshotter bool
Unsupported []string
Unsupported []string
ExtraEnv []string
}
func (c Moby) Name() string {
@ -137,7 +137,13 @@ func (c Moby) New(ctx context.Context, cfg *integration.BackendConfig) (b integr
return nil, nil, err
}
d, err := dockerd.NewDaemon(workDir)
dockerdOpts := []dockerd.Option{
dockerd.WithExtraEnv(c.ExtraEnv),
}
if c.Binary != "" {
dockerdOpts = append(dockerdOpts, dockerd.WithBinary(c.Binary))
}
d, err := dockerd.NewDaemon(workDir, dockerdOpts...)
if err != nil {
return nil, nil, errors.Errorf("new daemon error: %q, %s", err, integration.FormatLogs(cfg.Logs))
}
@ -164,7 +170,7 @@ func (c Moby) New(ctx context.Context, cfg *integration.BackendConfig) (b integr
deferF.Append(d.StopWithError)
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))
return nil, nil, errors.Wrapf(err, "dockerd did not start up: %s", integration.FormatLogs(cfg.Logs))
}
dockerAPI, err := client.NewClientWithOpts(client.WithHost(d.Sock()))
@ -229,6 +235,7 @@ func (c Moby) New(ctx context.Context, cfg *integration.BackendConfig) (b integr
dockerAddress: d.Sock(),
rootless: c.IsRootless,
netnsDetached: false,
extraEnv: c.ExtraEnv,
isDockerd: true,
unsupportedFeatures: c.Unsupported,
}, cl, nil