mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
driver: add feature testing
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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() {}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
9
driver/features.go
Normal 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"
|
Reference in New Issue
Block a user