mirror of
https://github.com/docker/compose.git
synced 2026-08-28 04:18:05 +00:00
Add docker prune command and ACI implementation
Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
parent
7cf7b00584
commit
a5e34323e2
9 changed files with 169 additions and 14 deletions
69
cli/cmd/prune.go
Normal file
69
cli/cmd/prune.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
Copyright 2020 Docker Compose CLI authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/compose-cli/api/client"
|
||||
"github.com/docker/compose-cli/api/resources"
|
||||
)
|
||||
|
||||
type pruneOpts struct {
|
||||
force bool
|
||||
dryRun bool
|
||||
}
|
||||
|
||||
// PruneCommand deletes backend resources
|
||||
func PruneCommand() *cobra.Command {
|
||||
var opts pruneOpts
|
||||
cmd := &cobra.Command{
|
||||
Use: "prune",
|
||||
Short: "prune existing resources in current context",
|
||||
Args: cobra.MaximumNArgs(0),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runPrune(cmd.Context(), opts)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().BoolVar(&opts.force, "force", false, "Also prune running containers and Compose applications")
|
||||
cmd.Flags().BoolVar(&opts.dryRun, "dry-run", false, "List resources to be deleted, but do not delete them")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runPrune(ctx context.Context, opts pruneOpts) error {
|
||||
c, err := client.New(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "cannot connect to backend")
|
||||
}
|
||||
|
||||
ids, err := c.ResourceService().Prune(ctx, resources.PruneRequest{Force: opts.force, DryRun: opts.dryRun})
|
||||
if opts.dryRun {
|
||||
fmt.Println("resources that would be deleted:")
|
||||
} else {
|
||||
fmt.Println("deleted resources:")
|
||||
}
|
||||
for _, id := range ids {
|
||||
fmt.Println(id)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
@ -122,6 +122,7 @@ func main() {
|
|||
cmd.StopCommand(),
|
||||
cmd.KillCommand(),
|
||||
cmd.SecretCommand(),
|
||||
cmd.PruneCommand(),
|
||||
|
||||
// Place holders
|
||||
cmd.EcsCommand(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue