@@ -16,6 +16,9 @@ import (
1616 "github.com/docker/docker/api/types/filters"
1717 "github.com/docker/go-units"
1818 "github.com/moby/buildkit/client"
19+ gateway "github.com/moby/buildkit/frontend/gateway/client"
20+ pb "github.com/moby/buildkit/solver/pb"
21+ "github.com/moby/buildkit/util/apicaps"
1922 "github.com/pkg/errors"
2023 "github.com/spf13/cobra"
2124 "golang.org/x/sync/errgroup"
@@ -107,6 +110,17 @@ func runPrune(ctx context.Context, dockerCli command.Cli, opts pruneOptions) err
107110 if err != nil {
108111 return err
109112 }
113+ // check if the client supports newer prune options
114+ if opts .maxUsedSpace .Value () != 0 || opts .minFreeSpace .Value () != 0 {
115+ caps , err := loadLLBCaps (ctx , c )
116+ if err != nil {
117+ return errors .Wrap (err , "failed to load buildkit capabilities for prune" )
118+ }
119+ if caps .Supports (pb .CapGCFreeSpaceFilter ) != nil {
120+ return errors .New ("buildkit v0.17.0+ is required for max-used-space and min-free-space filters" )
121+ }
122+ }
123+
110124 popts := []client.PruneOption {
111125 client .WithKeepOpt (pi .KeepDuration , opts .reservedSpace .Value (), opts .maxUsedSpace .Value (), opts .minFreeSpace .Value ()),
112126 client .WithFilter (pi .Filter ),
@@ -133,6 +147,17 @@ func runPrune(ctx context.Context, dockerCli command.Cli, opts pruneOptions) err
133147 return nil
134148}
135149
150+ func loadLLBCaps (ctx context.Context , c * client.Client ) (apicaps.CapSet , error ) {
151+ var caps apicaps.CapSet
152+ _ , err := c .Build (ctx , client.SolveOpt {
153+ Internal : true ,
154+ }, "buildx" , func (ctx context.Context , c gateway.Client ) (* gateway.Result , error ) {
155+ caps = c .BuildOpts ().LLBCaps
156+ return nil , nil
157+ }, nil )
158+ return caps , err
159+ }
160+
136161func pruneCmd (dockerCli command.Cli , rootOpts * rootOptions ) * cobra.Command {
137162 options := pruneOptions {filter : opts .NewFilterOpt ()}
138163
0 commit comments