Skip to content

Commit

Permalink
✨ Add option --no-prune-children
Browse files Browse the repository at this point in the history
  • Loading branch information
charlyx committed May 14, 2019
1 parent fbfc033 commit 000b188
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/skaffold/app/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func AddRunCommonFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&opts.Namespace, "namespace", "n", "", "Run deployments in the specified namespace")
cmd.Flags().StringVarP(&opts.DefaultRepo, "default-repo", "d", "", "Default repository value (overrides global config)")
cmd.Flags().BoolVar(&opts.NoPrune, "no-prune", false, "Skip removing images and containers built by Skaffold")
cmd.Flags().BoolVar(&opts.NoPruneChildren, "no-prune-children", false, "Skip removing layers reused by Skaffold")
cmd.Flags().StringSliceVar(&opts.InsecureRegistries, "insecure-registry", nil, "Target registries for built images which are not secure")
}

Expand Down
12 changes: 12 additions & 0 deletions docs/content/en/docs/references/cli/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Flags:
--insecure-registry strings Target registries for built images which are not secure
-n, --namespace string Run deployments in the specified namespace
--no-prune Skip removing images and containers built by Skaffold
--no-prune-children Skip removing layers reused by Skaffold
-o, --output *flags.TemplateFlag Used in conjuction with --quiet flag. Format output with go-template. For full struct documentation, see https://godoc.org/github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/flags#BuildOutput (default {{json .}})
-p, --profile strings Activate profiles by name
-q, --quiet Suppress the build output and print image built on success. See --output to format output.
Expand All @@ -97,6 +98,7 @@ Env vars:
* `SKAFFOLD_INSECURE_REGISTRY` (same as `--insecure-registry`)
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_NO_PRUNE` (same as `--no-prune`)
* `SKAFFOLD_NO_PRUNE_CHILDREN` (same as `--no-prune-children`)
* `SKAFFOLD_OUTPUT` (same as `--output`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_QUIET` (same as `--quiet`)
Expand Down Expand Up @@ -236,6 +238,7 @@ Flags:
-l, --label strings Add custom labels to deployed objects. Set multiple times for multiple labels
-n, --namespace string Run deployments in the specified namespace
--no-prune Skip removing images and containers built by Skaffold
--no-prune-children Skip removing layers reused by Skaffold
--port-forward Port-forward exposed container ports within pods
-p, --profile strings Activate profiles by name
--rpc-http-port int tcp port to expose event REST API over HTTP (default 50052)
Expand All @@ -262,6 +265,7 @@ Env vars:
* `SKAFFOLD_LABEL` (same as `--label`)
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_NO_PRUNE` (same as `--no-prune`)
* `SKAFFOLD_NO_PRUNE_CHILDREN` (same as `--no-prune-children`)
* `SKAFFOLD_PORT_FORWARD` (same as `--port-forward`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
Expand All @@ -285,6 +289,7 @@ Flags:
--insecure-registry strings Target registries for built images which are not secure
-n, --namespace string Run deployments in the specified namespace
--no-prune Skip removing images and containers built by Skaffold
--no-prune-children Skip removing layers reused by Skaffold
-p, --profile strings Activate profiles by name
--rpc-http-port int tcp port to expose event REST API over HTTP (default 50052)
--rpc-port int tcp port to expose event API (default 50051)
Expand All @@ -304,6 +309,7 @@ Env vars:
* `SKAFFOLD_INSECURE_REGISTRY` (same as `--insecure-registry`)
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_NO_PRUNE` (same as `--no-prune`)
* `SKAFFOLD_NO_PRUNE_CHILDREN` (same as `--no-prune-children`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
* `SKAFFOLD_RPC_PORT` (same as `--rpc-port`)
Expand Down Expand Up @@ -331,6 +337,7 @@ Flags:
-l, --label strings Add custom labels to deployed objects. Set multiple times for multiple labels.
-n, --namespace string Run deployments in the specified namespace
--no-prune Skip removing images and containers built by Skaffold
--no-prune-children Skip removing layers reused by Skaffold
-p, --profile strings Activate profiles by name
--rpc-http-port int tcp port to expose event REST API over HTTP (default 50052)
--rpc-port int tcp port to expose event API (default 50051)
Expand Down Expand Up @@ -358,6 +365,7 @@ Env vars:
* `SKAFFOLD_LABEL` (same as `--label`)
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_NO_PRUNE` (same as `--no-prune`)
* `SKAFFOLD_NO_PRUNE_CHILDREN` (same as `--no-prune-children`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
* `SKAFFOLD_RPC_PORT` (same as `--rpc-port`)
Expand All @@ -384,6 +392,7 @@ Flags:
-l, --label strings Add custom labels to deployed objects. Set multiple times for multiple labels
-n, --namespace string Run deployments in the specified namespace
--no-prune Skip removing images and containers built by Skaffold
--no-prune-children Skip removing layers reused by Skaffold
--port-forward Port-forward exposed container ports within pods
-p, --profile strings Activate profiles by name
--rpc-http-port int tcp port to expose event REST API over HTTP (default 50052)
Expand Down Expand Up @@ -413,6 +422,7 @@ Env vars:
* `SKAFFOLD_LABEL` (same as `--label`)
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_NO_PRUNE` (same as `--no-prune`)
* `SKAFFOLD_NO_PRUNE_CHILDREN` (same as `--no-prune-children`)
* `SKAFFOLD_PORT_FORWARD` (same as `--port-forward`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
Expand Down Expand Up @@ -521,6 +531,7 @@ Flags:
-l, --label strings Add custom labels to deployed objects. Set multiple times for multiple labels.
-n, --namespace string Run deployments in the specified namespace
--no-prune Skip removing images and containers built by Skaffold
--no-prune-children Skip removing layers reused by Skaffold
-p, --profile strings Activate profiles by name
--rpc-http-port int tcp port to expose event REST API over HTTP (default 50052)
--rpc-port int tcp port to expose event API (default 50051)
Expand All @@ -547,6 +558,7 @@ Env vars:
* `SKAFFOLD_LABEL` (same as `--label`)
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_NO_PRUNE` (same as `--no-prune`)
* `SKAFFOLD_NO_PRUNE_CHILDREN` (same as `--no-prune-children`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
* `SKAFFOLD_RPC_PORT` (same as `--rpc-port`)
Expand Down
1 change: 1 addition & 0 deletions pkg/skaffold/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type SkaffoldOptions struct {
EnableRPC bool
Force bool
NoPrune bool
NoPruneChildren bool
CustomTag string
Namespace string
CacheFile string
Expand Down
13 changes: 12 additions & 1 deletion pkg/skaffold/docker/image_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,26 @@ import (
"fmt"
"io"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/docker/docker/api/types"
"github.com/pkg/errors"
)

var (
opts = &config.SkaffoldOptions{}
)

func Prune(ctx context.Context, out io.Writer, images []string, client LocalDaemon) error {
pruneChildren := true

if opts.NoPruneChildren {
pruneChildren = false
}

for _, id := range images {
resp, err := client.ImageRemove(ctx, id, types.ImageRemoveOptions{
Force: true,
PruneChildren: true,
PruneChildren: pruneChildren,
})
if err != nil {
return errors.Wrap(err, "pruning images")
Expand Down

0 comments on commit 000b188

Please sign in to comment.