From 000b188e9f7bac3b021e86edf74e99d6cbbea084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Henri=20GU=C3=89RIN?= Date: Sun, 12 May 2019 21:33:33 +0200 Subject: [PATCH] :sparkles: Add option `--no-prune-children` --- cmd/skaffold/app/cmd/cmd.go | 1 + docs/content/en/docs/references/cli/_index.md | 12 ++++++++++++ pkg/skaffold/config/options.go | 1 + pkg/skaffold/docker/image_util.go | 13 ++++++++++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/cmd/skaffold/app/cmd/cmd.go b/cmd/skaffold/app/cmd/cmd.go index f97ffc9169b..c4c1d0a6461 100644 --- a/cmd/skaffold/app/cmd/cmd.go +++ b/cmd/skaffold/app/cmd/cmd.go @@ -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") } diff --git a/docs/content/en/docs/references/cli/_index.md b/docs/content/en/docs/references/cli/_index.md index 51ffca854dc..ccf0bf6588b 100644 --- a/docs/content/en/docs/references/cli/_index.md +++ b/docs/content/en/docs/references/cli/_index.md @@ -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. @@ -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`) @@ -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) @@ -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`) @@ -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) @@ -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`) @@ -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) @@ -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`) @@ -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) @@ -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`) @@ -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) @@ -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`) diff --git a/pkg/skaffold/config/options.go b/pkg/skaffold/config/options.go index 0736730f2ab..796f0b9ffa3 100644 --- a/pkg/skaffold/config/options.go +++ b/pkg/skaffold/config/options.go @@ -34,6 +34,7 @@ type SkaffoldOptions struct { EnableRPC bool Force bool NoPrune bool + NoPruneChildren bool CustomTag string Namespace string CacheFile string diff --git a/pkg/skaffold/docker/image_util.go b/pkg/skaffold/docker/image_util.go index 25a7098577d..054da96e2dc 100644 --- a/pkg/skaffold/docker/image_util.go +++ b/pkg/skaffold/docker/image_util.go @@ -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")