94bc8b319c
* updates to support newer version of docker sdk Bumps [github.com/docker/cli](https://github.com/docker/cli) from 24.0.2+incompatible to 24.0.4+incompatible. - [Commits](https://github.com/docker/cli/compare/v24.0.2...v24.0.4) --- updated-dependencies: - dependency-name: github.com/docker/cli dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * feat: upgrade to go 1.20 * feat: upgrade to go 1.20 * chore: use go version from go.mod --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows))
|
|
|
|
package container
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
"github.com/docker/docker/api/types/volume"
|
|
"github.com/nektos/act/pkg/common"
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|