system prune: delegate version check
Move the version-check for pruners to the pruner, which can return a [ErrNotImplemented] error to indicate they won't be run with the API version that's used. This helps separating concerns, and doesn't enforce knowledge about what's supported by each content-type onto the system prune command. [ErrNotImplemented]: https://pkg.go.dev/github.com/docker/docker@v28.3.3+incompatible/errdefs#ErrNotImplemented Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@ -14,6 +14,7 @@ import (
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/moby/moby/api/types/build"
|
||||
"github.com/moby/moby/api/types/versions"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -112,6 +113,10 @@ type cancelledErr struct{ error }
|
||||
|
||||
func (cancelledErr) Cancelled() {}
|
||||
|
||||
type errNotImplemented struct{ error }
|
||||
|
||||
func (errNotImplemented) NotImplemented() {}
|
||||
|
||||
// CachePrune executes a prune command for build cache
|
||||
//
|
||||
// Deprecated: this function was only used internally and will be removed in the next release.
|
||||
@ -122,6 +127,10 @@ func CachePrune(ctx context.Context, dockerCli command.Cli, all bool, filter opt
|
||||
// pruneFn prunes the build cache for use in "docker system prune" and
|
||||
// returns the amount of space reclaimed and a detailed output string.
|
||||
func pruneFn(ctx context.Context, dockerCLI command.Cli, options pruner.PruneOptions) (uint64, string, error) {
|
||||
if ver := dockerCLI.Client().ClientVersion(); ver != "" && versions.LessThan(ver, "1.31") {
|
||||
// Not supported on older daemons.
|
||||
return 0, "", errNotImplemented{errors.New("builder prune requires API version 1.31 or greater")}
|
||||
}
|
||||
if !options.Confirmed {
|
||||
// Dry-run: perform validation and produce confirmation before pruning.
|
||||
var confirmMsg string
|
||||
|
||||
Reference in New Issue
Block a user