act/pkg/container/docker_volume.go

54 lines
1 KiB
Go
Raw Normal View History

//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows))
2020-02-23 17:02:01 -06:00
package container
import (
"context"
"github.com/docker/docker/api/types/filters"
2020-02-23 17:02:01 -06:00
"github.com/nektos/act/pkg/common"
)
func NewDockerVolumeRemoveExecutor(volume string, force bool) common.Executor {
return func(ctx context.Context) error {
cli, err := GetDockerClient(ctx)
if err != nil {
return err
}
defer cli.Close()
list, err := cli.VolumeList(ctx, filters.NewArgs())
if err != nil {
return err
}
for _, vol := range list.Volumes {
if vol.Name == volume {
return removeExecutor(volume, force)(ctx)
}
}
// Volume not found - do nothing
return nil
}
}
func removeExecutor(volume string, force bool) common.Executor {
2020-02-23 17:02:01 -06:00
return func(ctx context.Context) error {
logger := common.Logger(ctx)
logger.Debugf("%sdocker volume rm %s", logPrefix, volume)
if common.Dryrun(ctx) {
return nil
}
cli, err := GetDockerClient(ctx)
2020-02-23 17:02:01 -06:00
if err != nil {
return err
}
defer cli.Close()
2020-02-23 17:02:01 -06:00
return cli.VolumeRemove(ctx, volume, force)
}
}