Skip to content

Commit

Permalink
Merge pull request #1532 from tiborvass/18.09-fix-system-prune-filters
Browse files Browse the repository at this point in the history
[18.09] prune: move image pruning before build cache pruning
  • Loading branch information
andrewhsu authored Nov 27, 2018
2 parents 1274f23 + 4a4a1f3 commit 7059d06
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 20 additions & 1 deletion cli/command/image/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions cli/command/system/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7059d06

Please sign in to comment.