mirror of https://github.com/docker/cli.git
Merge pull request #1527 from tiborvass/fix-system-prune-filters
prune: move image pruning before build cache pruning
This commit is contained in:
commit
e042b58f7d
|
@ -8,7 +8,9 @@ import (
|
|||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
units "github.com/docker/go-units"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -55,8 +57,25 @@ Are you sure you want to continue?`
|
|||
Are you sure you want to continue?`
|
||||
)
|
||||
|
||||
// cloneFilter is a temporary workaround that uses existing public APIs from the filters package to clone a filter.
|
||||
// TODO(tiborvass): remove this once filters.Args.Clone() is added.
|
||||
func cloneFilter(args filters.Args) (newArgs filters.Args, err error) {
|
||||
if args.Len() == 0 {
|
||||
return filters.NewArgs(), nil
|
||||
}
|
||||
b, err := args.MarshalJSON()
|
||||
if err != nil {
|
||||
return newArgs, err
|
||||
}
|
||||
err = newArgs.UnmarshalJSON(b)
|
||||
return newArgs, err
|
||||
}
|
||||
|
||||
func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) {
|
||||
pruneFilters := options.filter.Value()
|
||||
pruneFilters, err := cloneFilter(options.filter.Value())
|
||||
if err != nil {
|
||||
return 0, "", errors.Wrap(err, "could not copy filter in image prune")
|
||||
}
|
||||
pruneFilters.Add("dangling", fmt.Sprintf("%v", !options.all))
|
||||
pruneFilters = command.PruneFilters(dockerCli, pruneFilters)
|
||||
|
||||
|
|
|
@ -73,11 +73,10 @@ func runPrune(dockerCli command.Cli, options pruneOptions) error {
|
|||
if options.pruneVolumes {
|
||||
pruneFuncs = append(pruneFuncs, volume.RunPrune)
|
||||
}
|
||||
pruneFuncs = append(pruneFuncs, image.RunPrune)
|
||||
if options.pruneBuildCache {
|
||||
pruneFuncs = append(pruneFuncs, builder.CachePrune)
|
||||
}
|
||||
// FIXME: modify image.RunPrune to not modify options.filter, otherwise this has to be last in the list.
|
||||
pruneFuncs = append(pruneFuncs, image.RunPrune)
|
||||
|
||||
var spaceReclaimed uint64
|
||||
for _, pruneFn := range pruneFuncs {
|
||||
|
|
Loading…
Reference in New Issue