.github
.vscode
cmd
pkg
artifacts
common
container
testdata
docker_auth.go
docker_build.go
docker_images.go
docker_images_test.go
docker_logger.go
docker_pull.go
docker_pull_test.go
docker_run.go
docker_run_test.go
docker_volume.go
file_collector.go
file_collector_test.go
exprparser
model
runner
.actrc
.editorconfig
.gitignore
.golangci.yml
.goreleaser.yml
.markdownlint.yml
.mega-linter.yml
.mergify.yml
.prettierignore
.prettierrc.yml
CODEOWNERS
CONTRIBUTING.md
IMAGES.md
LICENSE
Makefile
README.md
VERIFICATION
act-cli.nuspec
codecov.yml
go.mod
go.sum
install.sh
main.go
* Close docker client! * Fix nil dereference * Update run_context.go * Bump Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
52 lines
991 B
Go
52 lines
991 B
Go
package container
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
"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 {
|
|
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)
|
|
}
|
|
}
|