diff --git a/driver/docker/driver.go b/driver/docker/driver.go new file mode 100644 index 00000000..f7356b77 --- /dev/null +++ b/driver/docker/driver.go @@ -0,0 +1,35 @@ +package docker + +import ( + "context" + + dockertypes "github.com/docker/docker/api/types" + "github.com/moby/buildkit/client" + "github.com/pkg/errors" + "github.com/tonistiigi/buildx/driver" +) + +type Driver struct { + config driver.InitConfig + version dockertypes.Version +} + +func (d *Driver) Bootstrap(context.Context, driver.Logger) error { + return errors.Errorf("bootstrap not implemented for %T", d) +} + +func (d *Driver) Info(context.Context) (driver.Info, error) { + return driver.Info{}, errors.Errorf("info not implemented for %T", d) +} + +func (d *Driver) Stop(ctx context.Context, force bool) error { + return errors.Errorf("stop not implemented for %T", d) +} + +func (d *Driver) Rm(ctx context.Context, force bool) error { + return errors.Errorf("rm not implemented for %T", d) +} + +func (d *Driver) Client() (*client.Client, error) { + return nil, errors.Errorf("client not implemented for %T", d) +} diff --git a/driver/docker/factory.go b/driver/docker/factory.go new file mode 100644 index 00000000..f9905754 --- /dev/null +++ b/driver/docker/factory.go @@ -0,0 +1,40 @@ +package docker + +import ( + "context" + + "github.com/pkg/errors" + "github.com/tonistiigi/buildx/driver" +) + +func init() { + driver.Register(&factory{}) +} + +type factory struct { +} + +func (*factory) Name() string { + return "docker" +} + +func (*factory) Usage() string { + return "docker" +} + +func (*factory) Priority() int { + return 30 +} + +func (*factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver, error) { + if cfg.DockerAPI == nil { + return nil, errors.Errorf("docker driver requires docker API access") + } + + v, err := cfg.DockerAPI.ServerVersion(ctx) + if err != nil { + return nil, errors.Wrapf(driver.ErrNotConnecting, err.Error()) + } + + return &Driver{config: cfg, version: v}, nil +} diff --git a/driver/driver.go b/driver/driver.go index b01d724c..e90f7877 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -8,6 +8,9 @@ import ( "github.com/pkg/errors" ) +var ErrNotRunning = errors.Errorf("driver not running") +var ErrNotConnecting = errors.Errorf("driver not connection") + type Logger func(*client.SolveStatus) type Status int @@ -25,12 +28,10 @@ type Info struct { Platforms []specs.Platform } -var ErrNotRunning = errors.Errorf("driver not running") - type Driver interface { Bootstrap(context.Context, Logger) error Info(context.Context) (Info, error) Stop(ctx context.Context, force bool) error Rm(ctx context.Context, force bool) error - Client() (client.Client, error) + Client() (*client.Client, error) }