Fix container volumes being reused sometimes (#283)
This commit is contained in:
@@ -3,11 +3,34 @@ package container
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/nektos/act/pkg/common"
|
||||
)
|
||||
|
||||
// NewDockerVolumeRemoveExecutor function
|
||||
func NewDockerVolumeRemoveExecutor(volume string, force bool) common.Executor {
|
||||
return func(ctx context.Context) error {
|
||||
cli, err := GetDockerClient(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -23,5 +46,4 @@ func NewDockerVolumeRemoveExecutor(volume string, force bool) common.Executor {
|
||||
|
||||
return cli.VolumeRemove(ctx, volume, force)
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user