mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
commands: add implementations for create, use, rm, stop
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
@ -11,8 +11,9 @@ import (
|
||||
type Factory interface {
|
||||
Name() string
|
||||
Usage() string
|
||||
Priority(cfg InitConfig) int
|
||||
Priority(context.Context, dockerclient.APIClient) int
|
||||
New(ctx context.Context, cfg InitConfig) (Driver, error)
|
||||
AllowsInstances() bool
|
||||
}
|
||||
|
||||
type BuildkitConfig struct {
|
||||
@ -37,7 +38,7 @@ func Register(f Factory) {
|
||||
drivers[f.Name()] = f
|
||||
}
|
||||
|
||||
func GetDefaultFactory(ic InitConfig) (Factory, error) {
|
||||
func GetDefaultFactory(ctx context.Context, c dockerclient.APIClient, instanceRequired bool) (Factory, error) {
|
||||
if len(drivers) == 0 {
|
||||
return nil, errors.Errorf("no drivers available")
|
||||
}
|
||||
@ -47,7 +48,10 @@ func GetDefaultFactory(ic InitConfig) (Factory, error) {
|
||||
}
|
||||
dd := make([]p, 0, len(drivers))
|
||||
for _, f := range drivers {
|
||||
dd = append(dd, p{f: f, priority: f.Priority(ic)})
|
||||
if instanceRequired && !f.AllowsInstances() {
|
||||
continue
|
||||
}
|
||||
dd = append(dd, p{f: f, priority: f.Priority(ctx, c)})
|
||||
}
|
||||
sort.Slice(dd, func(i, j int) bool {
|
||||
return dd[i].priority < dd[j].priority
|
||||
@ -55,6 +59,18 @@ func GetDefaultFactory(ic InitConfig) (Factory, error) {
|
||||
return dd[0].f, nil
|
||||
}
|
||||
|
||||
func GetFactory(name string, instanceRequired bool) Factory {
|
||||
for _, f := range drivers {
|
||||
if instanceRequired && !f.AllowsInstances() {
|
||||
continue
|
||||
}
|
||||
if f.Name() == name {
|
||||
return f
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetDriver(ctx context.Context, name string, f Factory, api dockerclient.APIClient) (Driver, error) {
|
||||
ic := InitConfig{
|
||||
DockerAPI: api,
|
||||
@ -62,7 +78,7 @@ func GetDriver(ctx context.Context, name string, f Factory, api dockerclient.API
|
||||
}
|
||||
if f == nil {
|
||||
var err error
|
||||
f, err = GetDefaultFactory(ic)
|
||||
f, err = GetDefaultFactory(ctx, api, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user