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:
@ -171,11 +171,28 @@ func (d *Driver) Info(ctx context.Context) (*driver.Info, error) {
|
||||
}
|
||||
|
||||
func (d *Driver) Stop(ctx context.Context, force bool) error {
|
||||
return errors.Errorf("stop not implemented for %T", d)
|
||||
info, err := d.Info(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.Status == driver.Running {
|
||||
return d.DockerAPI.ContainerStop(ctx, d.Name, nil)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Driver) Rm(ctx context.Context, force bool) error {
|
||||
return errors.Errorf("rm not implemented for %T", d)
|
||||
info, err := d.Info(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.Status != driver.Terminated {
|
||||
return d.DockerAPI.ContainerRemove(ctx, d.Name, dockertypes.ContainerRemoveOptions{
|
||||
RemoveVolumes: true,
|
||||
Force: true,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Driver) Client(ctx context.Context) (*client.Client, error) {
|
||||
|
@ -3,6 +3,7 @@ package docker
|
||||
import (
|
||||
"context"
|
||||
|
||||
dockerclient "github.com/docker/docker/client"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tonistiigi/buildx/driver"
|
||||
)
|
||||
@ -25,8 +26,8 @@ func (*factory) Usage() string {
|
||||
return "docker-container"
|
||||
}
|
||||
|
||||
func (*factory) Priority(cfg driver.InitConfig) int {
|
||||
if cfg.DockerAPI == nil {
|
||||
func (*factory) Priority(ctx context.Context, api dockerclient.APIClient) int {
|
||||
if api == nil {
|
||||
return priorityUnsupported
|
||||
}
|
||||
return prioritySupported
|
||||
@ -44,3 +45,7 @@ func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver
|
||||
|
||||
return &Driver{factory: f, InitConfig: cfg, version: v}, nil
|
||||
}
|
||||
|
||||
func (f *factory) AllowsInstances() bool {
|
||||
return true
|
||||
}
|
||||
|
Reference in New Issue
Block a user