Skip to content

Commit

Permalink
Merge pull request #1400 from nkubala/prune
Browse files Browse the repository at this point in the history
Remove intermediate images and containers from local builds by default
  • Loading branch information
nkubala authored Apr 1, 2019
2 parents 01d8d7e + f19d89e commit 113cc47
Show file tree
Hide file tree
Showing 35 changed files with 814 additions and 87 deletions.
1 change: 1 addition & 0 deletions cmd/skaffold/app/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func AddRunDevFlags(cmd *cobra.Command) {
cmd.Flags().BoolVar(&opts.SkipTests, "skip-tests", false, "Whether to skip the tests after building")
cmd.Flags().BoolVar(&opts.CacheArtifacts, "cache-artifacts", false, "Set to true to enable caching of artifacts.")
cmd.Flags().StringVarP(&opts.CacheFile, "cache-file", "", "", "Specify the location of the cache file (default $HOME/.skaffold/cache)")
cmd.Flags().BoolVar(&opts.NoPrune, "no-prune", false, "Skip removing images and containers built by Skaffold")
}

func AddDevDebugFlags(cmd *cobra.Command) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ func delete(out io.Writer) error {
}
defer runner.RPCServerShutdown()

return runner.Cleanup(ctx, out)
return runner.Deployer.Cleanup(ctx, out)
}
16 changes: 15 additions & 1 deletion cmd/skaffold/app/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ func dev(out io.Writer, ui bool) error {
}()
}

prune := func() {}
if opts.Prune() {
defer func() {
prune()
}()
}

var (
app *tview.Application
output *config.Output
Expand Down Expand Up @@ -99,7 +106,14 @@ func dev(out io.Writer, ui bool) error {
if r.HasDeployed() {
cleanup = func() {
if err := r.Cleanup(context.Background(), out); err != nil {
logrus.Warnln("cleanup:", err)
logrus.Warnln("deployer cleanup:", err)
}
}
}
if r.HasBuilt() {
prune = func() {
if err := r.Prune(context.Background(), out); err != nil {
logrus.Warnln("builder cleanup:", err)
}
}
}
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 @@ -70,6 +70,7 @@ Flags:
--enable-rpc skaffold dev Enable gRPC for exposing Skaffold events (true by default for skaffold dev)
-f, --filename string Filename or URL to the pipeline file (default "skaffold.yaml")
-n, --namespace string Run deployments in the specified namespace
--no-prune Skip removing images and containers built 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/cmd#BuildOutput (default {{.}})
-p, --profile stringArray Activate profiles by name
-q, --quiet Suppress the build output and print image built on success. See --output to format output.
Expand All @@ -93,6 +94,7 @@ Env vars:
* `SKAFFOLD_ENABLE_RPC` (same as `--enable-rpc`)
* `SKAFFOLD_FILENAME` (same as `--filename`)
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_NO_PRUNE` (same as `--no-prune`)
* `SKAFFOLD_OUTPUT` (same as `--output`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_QUIET` (same as `--quiet`)
Expand Down Expand Up @@ -231,6 +233,7 @@ Flags:
-f, --filename string Filename or URL to the pipeline file (default "skaffold.yaml")
-l, --label stringArray 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
--port-forward Port-forward exposed container ports within pods (default true)
-p, --profile stringArray Activate profiles by name
--rpc-http-port int tcp port to expose event REST API over HTTP (default 50052)
Expand All @@ -256,6 +259,7 @@ Env vars:
* `SKAFFOLD_FILENAME` (same as `--filename`)
* `SKAFFOLD_LABEL` (same as `--label`)
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_NO_PRUNE` (same as `--no-prune`)
* `SKAFFOLD_PORT_FORWARD` (same as `--port-forward`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
Expand All @@ -279,6 +283,7 @@ Flags:
--enable-rpc skaffold dev Enable gRPC for exposing Skaffold events (true by default for skaffold dev)
-f, --filename string Filename or URL to the pipeline file (default "skaffold.yaml")
-n, --namespace string Run deployments in the specified namespace
--no-prune Skip removing images and containers built by Skaffold
-p, --profile stringArray 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 @@ -299,6 +304,7 @@ Env vars:
* `SKAFFOLD_ENABLE_RPC` (same as `--enable-rpc`)
* `SKAFFOLD_FILENAME` (same as `--filename`)
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_NO_PRUNE` (same as `--no-prune`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
* `SKAFFOLD_RPC_PORT` (same as `--rpc-port`)
Expand All @@ -322,6 +328,7 @@ Flags:
--images strings A list of pre-built images to deploy
-l, --label stringArray 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
-p, --profile stringArray 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 @@ -345,6 +352,7 @@ Env vars:
* `SKAFFOLD_IMAGES` (same as `--images`)
* `SKAFFOLD_LABEL` (same as `--label`)
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_NO_PRUNE` (same as `--no-prune`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
* `SKAFFOLD_RPC_PORT` (same as `--rpc-port`)
Expand All @@ -370,6 +378,7 @@ Flags:
-f, --filename string Filename or URL to the pipeline file (default "skaffold.yaml")
-l, --label stringArray 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
--port-forward Port-forward exposed container ports within pods (default true)
-p, --profile stringArray Activate profiles by name
--rpc-http-port int tcp port to expose event REST API over HTTP (default 50052)
Expand Down Expand Up @@ -398,6 +407,7 @@ Env vars:
* `SKAFFOLD_FILENAME` (same as `--filename`)
* `SKAFFOLD_LABEL` (same as `--label`)
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_NO_PRUNE` (same as `--no-prune`)
* `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 @@ -503,6 +513,7 @@ Flags:
-f, --filename string Filename or URL to the pipeline file (default "skaffold.yaml")
-l, --label stringArray 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
-p, --profile stringArray 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 @@ -526,6 +537,7 @@ Env vars:
* `SKAFFOLD_FILENAME` (same as `--filename`)
* `SKAFFOLD_LABEL` (same as `--label`)
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_NO_PRUNE` (same as `--no-prune`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
* `SKAFFOLD_RPC_PORT` (same as `--rpc-port`)
Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ type Builder interface {
Build(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latest.Artifact) ([]Artifact, error)

DependenciesForArtifact(ctx context.Context, artifact *latest.Artifact) ([]string, error)

// Prune removes images built with Skaffold
Prune(context.Context, io.Writer) error
}
Loading

0 comments on commit 113cc47

Please sign in to comment.