vendor: github.com/moby/moby/api v1.52.0, moby/client v0.1.0
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
+20
-18
@@ -4,7 +4,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"maps"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
@@ -14,12 +16,12 @@ import (
|
||||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/moby/buildkit/client"
|
||||
gateway "github.com/moby/buildkit/frontend/gateway/client"
|
||||
pb "github.com/moby/buildkit/solver/pb"
|
||||
"github.com/moby/buildkit/util/apicaps"
|
||||
dclient "github.com/moby/moby/client"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/sync/errgroup"
|
||||
@@ -42,9 +44,7 @@ const (
|
||||
)
|
||||
|
||||
func runPrune(ctx context.Context, dockerCli command.Cli, opts pruneOptions) error {
|
||||
pruneFilters := opts.filter.Value()
|
||||
pruneFilters = command.PruneFilters(dockerCli, pruneFilters)
|
||||
|
||||
pruneFilters := command.PruneFilters(dockerCli, opts.filter.Value())
|
||||
pi, err := toBuildkitPruneInfo(pruneFilters)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -189,20 +189,22 @@ func pruneCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func toBuildkitPruneInfo(f filters.Args) (*client.PruneInfo, error) {
|
||||
var until time.Duration
|
||||
untilValues := f.Get("until") // canonical
|
||||
unusedForValues := f.Get("unused-for") // deprecated synonym for "until" filter
|
||||
// getFilter returns the list of values associated with the key
|
||||
func getFilter(f dclient.Filters, key string) []string {
|
||||
return slices.Collect(maps.Keys(f[key]))
|
||||
}
|
||||
|
||||
if len(untilValues) > 0 && len(unusedForValues) > 0 {
|
||||
return nil, errors.Errorf("conflicting filters %q and %q", "until", "unused-for")
|
||||
func toBuildkitPruneInfo(pruneFilters dclient.Filters) (*client.PruneInfo, error) {
|
||||
var until time.Duration
|
||||
if len(pruneFilters["until"]) > 0 && len(pruneFilters["unused-for"]) > 0 {
|
||||
return nil, errors.New(`conflicting filters "until" and "unused-for"`)
|
||||
}
|
||||
untilKey := "until"
|
||||
if len(unusedForValues) > 0 {
|
||||
untilKey = "unused-for"
|
||||
if len(pruneFilters["unused-for"]) > 0 {
|
||||
untilKey = "unused-for" // deprecated synonym for "until" filter
|
||||
}
|
||||
untilValues = append(untilValues, unusedForValues...)
|
||||
|
||||
untilValues := getFilter(pruneFilters, untilKey)
|
||||
switch len(untilValues) {
|
||||
case 0:
|
||||
// nothing to do
|
||||
@@ -213,16 +215,16 @@ func toBuildkitPruneInfo(f filters.Args) (*client.PruneInfo, error) {
|
||||
return nil, errors.Wrapf(err, "%q filter expects a duration (e.g., '24h')", untilKey)
|
||||
}
|
||||
default:
|
||||
return nil, errors.Errorf("filters expect only one value")
|
||||
return nil, errors.Errorf("%q filter expects only one value", untilKey)
|
||||
}
|
||||
|
||||
filters := make([]string, 0, f.Len())
|
||||
for _, filterKey := range f.Keys() {
|
||||
filters := make([]string, 0, len(pruneFilters))
|
||||
for filterKey := range pruneFilters {
|
||||
if filterKey == untilKey {
|
||||
continue
|
||||
}
|
||||
|
||||
values := f.Get(filterKey)
|
||||
values := getFilter(pruneFilters, filterKey)
|
||||
switch len(values) {
|
||||
case 0:
|
||||
filters = append(filters, filterKey)
|
||||
@@ -235,7 +237,7 @@ func toBuildkitPruneInfo(f filters.Args) (*client.PruneInfo, error) {
|
||||
filters = append(filters, filterKey+"=="+values[0])
|
||||
}
|
||||
default:
|
||||
return nil, errors.Errorf("filters expect only one value")
|
||||
return nil, errors.Errorf("%q filter expects only one value", filterKey)
|
||||
}
|
||||
}
|
||||
return &client.PruneInfo{
|
||||
|
||||
Reference in New Issue
Block a user