commands: add implementations for create, use, rm, stop

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2019-04-12 16:39:06 -07:00
parent 0e72bf0049
commit bd3d5cd19e
20 changed files with 1695 additions and 101 deletions

View File

@ -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) {

View File

@ -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
}