mirror of https://github.com/docker/cli.git
Merge pull request #1295 from tiborvass/cmd-builder-prune-no-options
builder: Implement `builder prune` to prune build cache
This commit is contained in:
commit
b3d8c5deda
|
@ -0,0 +1,22 @@
|
||||||
|
package builder
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/docker/cli/cli"
|
||||||
|
"github.com/docker/cli/cli/command"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewBuilderCommand returns a cobra command for `builder` subcommands
|
||||||
|
func NewBuilderCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "builder",
|
||||||
|
Short: "Manage builds",
|
||||||
|
Args: cli.NoArgs,
|
||||||
|
RunE: command.ShowHelp(dockerCli.Err()),
|
||||||
|
}
|
||||||
|
cmd.AddCommand(
|
||||||
|
NewPruneCommand(dockerCli),
|
||||||
|
)
|
||||||
|
return cmd
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package builder
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/docker/cli/cli"
|
||||||
|
"github.com/docker/cli/cli/command"
|
||||||
|
units "github.com/docker/go-units"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewPruneCommand returns a new cobra prune command for images
|
||||||
|
func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "prune",
|
||||||
|
Short: "Remove build cache",
|
||||||
|
Args: cli.NoArgs,
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
report, err := dockerCli.Client().BuildCachePrune(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(report.SpaceReclaimed)))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
Annotations: map[string]string{"version": "1.39"},
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
|
"github.com/docker/cli/cli/command/builder"
|
||||||
"github.com/docker/cli/cli/command/checkpoint"
|
"github.com/docker/cli/cli/command/checkpoint"
|
||||||
"github.com/docker/cli/cli/command/config"
|
"github.com/docker/cli/cli/command/config"
|
||||||
"github.com/docker/cli/cli/command/container"
|
"github.com/docker/cli/cli/command/container"
|
||||||
|
@ -40,6 +41,9 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
|
||||||
image.NewImageCommand(dockerCli),
|
image.NewImageCommand(dockerCli),
|
||||||
image.NewBuildCommand(dockerCli),
|
image.NewBuildCommand(dockerCli),
|
||||||
|
|
||||||
|
// builder
|
||||||
|
builder.NewBuilderCommand(dockerCli),
|
||||||
|
|
||||||
// manifest
|
// manifest
|
||||||
manifest.NewManifestCommand(dockerCli),
|
manifest.NewManifestCommand(dockerCli),
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue