feat: env driver
Co-authored-by: Furkan Türkal <furkan.turkal@trendyol.com> Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>pull/1078/head
parent
29f97f6762
commit
3dc83e5dd8
@ -0,0 +1,70 @@
|
||||
package env
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/buildx/driver"
|
||||
"github.com/docker/buildx/util/progress"
|
||||
"github.com/moby/buildkit/client"
|
||||
buildkitclient "github.com/moby/buildkit/client"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Driver struct {
|
||||
factory driver.Factory
|
||||
driver.InitConfig
|
||||
BuldkitdAddr string
|
||||
BuildkitAPI *buildkitclient.Client
|
||||
}
|
||||
|
||||
func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Driver) Info(ctx context.Context) (*driver.Info, error) {
|
||||
if d.BuldkitdAddr == "" && d.Driver == "env" {
|
||||
return nil, errors.Errorf("buldkitd addr must not be empty")
|
||||
}
|
||||
|
||||
c, err := client.New(ctx, d.BuldkitdAddr)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(driver.ErrNotConnecting, err.Error())
|
||||
}
|
||||
|
||||
if _, err := c.ListWorkers(ctx); err != nil {
|
||||
return nil, errors.Wrapf(driver.ErrNotConnecting, err.Error())
|
||||
}
|
||||
|
||||
return &driver.Info{
|
||||
Status: driver.Running,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d *Driver) Stop(ctx context.Context, force bool) error {
|
||||
return fmt.Errorf("stop command is not implemented for this driver")
|
||||
}
|
||||
|
||||
func (d *Driver) Rm(ctx context.Context, force, rmVolume, rmDaemon bool) error {
|
||||
return fmt.Errorf("rm command is not implemented for this driver")
|
||||
}
|
||||
|
||||
func (d *Driver) Client(ctx context.Context) (*client.Client, error) {
|
||||
return client.New(ctx, d.BuldkitdAddr, client.WithSessionDialer(d.BuildkitAPI.Dialer()))
|
||||
}
|
||||
|
||||
func (d *Driver) Features() map[driver.Feature]bool {
|
||||
return map[driver.Feature]bool{}
|
||||
}
|
||||
|
||||
func (d *Driver) Factory() driver.Factory {
|
||||
return d.factory
|
||||
}
|
||||
|
||||
func (d *Driver) IsMobyDriver() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (d *Driver) Config() driver.InitConfig {
|
||||
return d.InitConfig
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package env
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/docker/buildx/driver"
|
||||
dockerclient "github.com/docker/docker/client"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const prioritySupported = 50
|
||||
const priorityUnsupported = 90
|
||||
|
||||
func init() {
|
||||
driver.Register(&factory{})
|
||||
}
|
||||
|
||||
type factory struct {
|
||||
}
|
||||
|
||||
func (*factory) Name() string {
|
||||
return "env"
|
||||
}
|
||||
|
||||
func (*factory) Usage() string {
|
||||
return "env"
|
||||
}
|
||||
|
||||
func (*factory) Priority(ctx context.Context, api dockerclient.APIClient) int {
|
||||
if api == nil {
|
||||
return priorityUnsupported
|
||||
}
|
||||
|
||||
return prioritySupported
|
||||
}
|
||||
|
||||
func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver, error) {
|
||||
if len(cfg.Files) > 0 {
|
||||
return nil, errors.Errorf("setting config file is not supported for remote driver")
|
||||
}
|
||||
|
||||
return &Driver{
|
||||
factory: f,
|
||||
InitConfig: cfg,
|
||||
BuldkitdAddr: cfg.BuldkitdAddr,
|
||||
BuildkitAPI: cfg.BuildkitAPI,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f *factory) AllowsInstances() bool {
|
||||
return true
|
||||
}
|
Loading…
Reference in New Issue