driver: add feature testing

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2019-04-10 18:57:54 -07:00
parent 68cad8e46b
commit 0788035da8
7 changed files with 77 additions and 6 deletions

View File

@ -24,6 +24,7 @@ var buildkitImage = "moby/buildkit:master" // TODO: make this verified and confi
type Driver struct {
driver.InitConfig
factory driver.Factory
version dockertypes.Version
}
@ -190,6 +191,20 @@ func (d *Driver) Client(ctx context.Context) (*client.Client, error) {
}))
}
func (d *Driver) Factory() driver.Factory {
return d.factory
}
func (d *Driver) Features() map[driver.Feature]bool {
return map[driver.Feature]bool{
driver.OCIExporter: true,
driver.DockerExporter: true,
driver.CacheExport: true,
driver.MultiPlatform: true,
}
}
func demuxConn(c net.Conn) net.Conn {
pr, pw := io.Pipe()
// TODO: rewrite parser with Reader() to avoid goroutine switch

View File

@ -42,5 +42,5 @@ func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver
return nil, errors.Wrapf(driver.ErrNotConnecting, err.Error())
}
return &Driver{InitConfig: cfg, version: v}, nil
return &Driver{factory: f, InitConfig: cfg, version: v}, nil
}

View File

@ -12,9 +12,8 @@ import (
"github.com/tonistiigi/buildx/util/progress"
)
var buildkitImage = "moby/buildkit:master" // TODO: make this verified and configuratble
type Driver struct {
factory driver.Factory
driver.InitConfig
version dockertypes.Version
}
@ -46,3 +45,19 @@ func (d *Driver) Client(ctx context.Context) (*client.Client, error) {
return d.DockerAPI.DialHijack(ctx, "/grpc", "h2c", nil)
}))
}
func (d *Driver) Features() map[driver.Feature]bool {
return map[driver.Feature]bool{
driver.OCIExporter: false,
driver.DockerExporter: false,
driver.CacheExport: false,
driver.MultiPlatform: false,
}
}
func (d *Driver) Factory() driver.Factory {
return d.factory
}
func (d *Driver) IsDefaultMobyDriver() {}

View File

@ -39,7 +39,7 @@ func (*factory) Priority(cfg driver.InitConfig) int {
return prioritySupported
}
func (*factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver, error) {
func (f *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")
}
@ -49,5 +49,5 @@ func (*factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver,
return nil, errors.Wrapf(driver.ErrNotConnecting, err.Error())
}
return &Driver{InitConfig: cfg, version: v}, nil
return &Driver{factory: f, InitConfig: cfg, version: v}, nil
}

View File

@ -27,11 +27,13 @@ type Info struct {
}
type Driver interface {
Factory() Factory
Bootstrap(context.Context, progress.Logger) error
Info(context.Context) (*Info, error)
Stop(ctx context.Context, force bool) error
Rm(ctx context.Context, force bool) error
Client(ctx context.Context) (*client.Client, error)
Features() map[Feature]bool
}
func Boot(ctx context.Context, d Driver, pw progress.Writer) (*client.Client, progress.Writer, error) {

9
driver/features.go Normal file
View File

@ -0,0 +1,9 @@
package driver
type Feature string
const OCIExporter Feature = "OCI exporter"
const DockerExporter Feature = "Docker exporter"
const CacheExport Feature = "cache export"
const MultiPlatform Feature = "multiple platforms"