mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-30 19:22:09 +00:00
the license change from MIT to GPLv3+ is a breaking change Refs forgejo/runner#773 <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - other - [PR](https://code.forgejo.org/forgejo/runner/pulls/940): <!--number 940 --><!--line 0 --><!--description Y2hvcmU6IGJ1bXAgdmVyc2lvbiB0byB2MTE=-->chore: bump version to v11<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/940 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
|
|
|
|
package container
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
|
|
"code.forgejo.org/forgejo/runner/v11/act/common"
|
|
"github.com/docker/docker/api/types/filters"
|
|
"github.com/docker/docker/api/types/volume"
|
|
)
|
|
|
|
func NewDockerVolumesRemoveExecutor(volumeNames []string) 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 slices.Contains(volumeNames, vol.Name) {
|
|
if err := removeExecutor(vol.Name)(ctx); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func removeExecutor(volume string) 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()
|
|
|
|
force := false
|
|
return cli.VolumeRemove(ctx, volume, force)
|
|
}
|
|
}
|