driver: basic types startpoint
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>pull/10/head
parent
3f4b9e1fcc
commit
8438557ff7
@ -0,0 +1,36 @@
|
||||
package driver
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/moby/buildkit/client"
|
||||
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Logger func(*client.SolveStatus)
|
||||
|
||||
type Status int
|
||||
|
||||
const (
|
||||
Terminated Status = iota
|
||||
Starting
|
||||
Running
|
||||
Stopping
|
||||
Stopped
|
||||
)
|
||||
|
||||
type Info struct {
|
||||
Status Status
|
||||
Platforms []specs.Platform
|
||||
}
|
||||
|
||||
var ErrNotRunning = errors.Errorf("driver not running")
|
||||
|
||||
type Driver interface {
|
||||
Bootstrap(context.Context, Logger) error
|
||||
Info(context.Context) (Info, error)
|
||||
Stop(ctx context.Context, force bool) error
|
||||
Rm(ctx context.Context, force bool) error
|
||||
Client() (client.Client, error)
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package driver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
|
||||
dockerclient "github.com/docker/docker/client"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Factory interface {
|
||||
Name() string
|
||||
Usage() string
|
||||
Priority() int // take initConfig?
|
||||
New(ctx context.Context, cfg InitConfig) (Driver, error)
|
||||
}
|
||||
|
||||
type BuildkitConfig struct {
|
||||
// Entitlements []string
|
||||
// Rootless bool
|
||||
}
|
||||
|
||||
type InitConfig struct {
|
||||
// This object needs updates to be generic for different drivers
|
||||
Name string
|
||||
DockerAPI dockerclient.APIClient
|
||||
BuildkitConfig BuildkitConfig
|
||||
Meta map[string]interface{}
|
||||
}
|
||||
|
||||
var drivers map[string]Factory
|
||||
|
||||
func Register(f Factory) {
|
||||
if drivers == nil {
|
||||
drivers = map[string]Factory{}
|
||||
}
|
||||
drivers[f.Name()] = f
|
||||
}
|
||||
|
||||
func GetDefaultDriver() (Factory, error) {
|
||||
if len(drivers) == 0 {
|
||||
return nil, errors.Errorf("no drivers available")
|
||||
}
|
||||
type p struct {
|
||||
f Factory
|
||||
priority int
|
||||
}
|
||||
dd := make([]p, 0, len(drivers))
|
||||
for _, f := range drivers {
|
||||
dd = append(dd, p{f: f, priority: f.Priority()})
|
||||
}
|
||||
sort.Slice(dd, func(i, j int) bool {
|
||||
return dd[i].priority < dd[j].priority
|
||||
})
|
||||
return dd[0].f, nil
|
||||
}
|
Loading…
Reference in New Issue