Files
act_runner/pkg/container/docker_volume.go
Steven Edwards 70c9e21c85 update go imports (#20)
* Replace nektos/act imports with actions-oss/act-cli

* Update go.mod to reference new repo

* Fix goimports "not properly formatted" complaints.

Replacing the imports left some out of alphabetical order.
2025-01-27 18:11:12 +01:00

55 lines
1.1 KiB
Go

//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd))
package container
import (
"context"
"github.com/actions-oss/act-cli/pkg/common"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/volume"
)
func NewDockerVolumeRemoveExecutor(volumeName 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, volume.ListOptions{Filters: filters.NewArgs()})
if err != nil {
return err
}
for _, vol := range list.Volumes {
if vol.Name == volumeName {
return removeExecutor(volumeName, force)(ctx)
}
}
// Volume not found - do nothing
return nil
}
}
func removeExecutor(volume string, force bool) common.Executor {
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)
if err != nil {
return err
}
defer cli.Close()
return cli.VolumeRemove(ctx, volume, force)
}
}