github.com/pdmccormick/importable-docker-buildx@v0.0.0-20240426161518-e47091289030/driver/docker/factory.go (about) 1 package docker 2 3 import ( 4 "context" 5 6 "github.com/docker/buildx/driver" 7 dockerclient "github.com/docker/docker/client" 8 "github.com/pkg/errors" 9 ) 10 11 const prioritySupported = 10 12 const priorityUnsupported = 99 13 14 func init() { 15 driver.Register(&factory{}) 16 } 17 18 type factory struct { 19 } 20 21 func (*factory) Name() string { 22 return "docker" 23 } 24 25 func (*factory) Usage() string { 26 return "docker" 27 } 28 29 func (*factory) Priority(ctx context.Context, endpoint string, api dockerclient.APIClient, dialMeta map[string][]string) int { 30 if api == nil { 31 return priorityUnsupported 32 } 33 34 c, err := api.DialHijack(ctx, "/grpc", "h2c", dialMeta) 35 if err != nil { 36 return priorityUnsupported 37 } 38 c.Close() 39 40 return prioritySupported 41 } 42 43 func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver, error) { 44 if cfg.DockerAPI == nil { 45 return nil, errors.Errorf("docker driver requires docker API access") 46 } 47 if len(cfg.Files) > 0 { 48 return nil, errors.Errorf("setting config file is not supported for docker driver, use dockerd configuration file") 49 } 50 51 return &Driver{factory: f, InitConfig: cfg}, nil 52 } 53 54 func (f *factory) AllowsInstances() bool { 55 return false 56 }