Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builder: add prune options to the API #37651

Merged
merged 3 commits into from
Sep 4, 2018

Conversation

tiborvass
Copy link
Contributor

@tiborvass tiborvass commented Aug 15, 2018

Signed-off-by: Tibor Vass tibor@docker.com

type BuildCachePruneOptions struct {
All bool
KeepDuration time.Duration
KeepStorage float64 // in MB
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkihiroSuda @vdemeester I'm not sure if I want KeepStorage here or KeepBytes like in Buildkit API, though on the CLIs it's --keep-storage. Let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either is fine, but I think the type should be int64 in bytes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiborvass same as @AkihiroSuda 😝, KeepStorage is fine 😉


opts := types.BuildCachePruneOptions{
All: httputils.BoolValue(r, "all"),
KeepDuration: time.Duration(kd),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kd * time.Second

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or errors.Wrap(err, "keep-duration expects an integer number in milliseconds")

// BuildCachePruneOptions hold parameters to prune the build cache
type BuildCachePruneOptions struct {
All bool
KeepDuration time.Duration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna summarize a conversation that @tiborvass and I had offline. If we've understood the criteria for pruning correctly a given cache layer will be kept if it meets the KeepDuration criterion and meets the KeepStorage criterion. In other words keep rules are conjunctive and by De Morgan's law, purge rules are disjunctive 😜

If that's the case I would rename KeepDuration to KeepMaxAge. Duration implies that the cached item will be kept around for that amount of time, whereas max age implies it will be kept for a maximum of that amount of time given all other criteria are also met.

@tiborvass tiborvass force-pushed the new-builder-prune branch 2 times, most recently from ac354f6 to dc9b62f Compare August 17, 2018 08:35
@andrewhsu
Copy link
Member

@tiborvass Hmm...janky no likey:

integration/build/build_session_test.go:1::warning: file is not goimported (goimports)
api/server/router/build/build_routes.go:177:31:warning: invalid operation: mismatched types int and time.Duration (gosimple)
api/server/router/build/build_routes.go:178:17:warning: cannot use ks (variable of type float64) as int64 value in struct literal (interfacer)
api/server/router/build/build_routes.go:177:31:warning: invalid operation: mismatched types int and time.Duration (interfacer)
api/server/router/build/build_routes.go:178:17:warning: cannot use ks (variable of type float64) as int64 value in struct literal (unconvert)
api/server/router/build/build_routes.go:177:31:warning: invalid operation: mismatched types int and time.Duration (unconvert)
Build step 'Execute shell' marked build as failure

}

opts := types.BuildCachePruneOptions{
All: httputils.BoolValue(r, "all"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my clarification:
Isnt all mutually exclusive with the Keep* options?
Also, what happens when KeepDuration is met but KeepStorage isnt or vice versa?

@tiborvass tiborvass force-pushed the new-builder-prune branch 7 times, most recently from a39e158 to 88f575d Compare August 20, 2018 22:24
@tiborvass tiborvass changed the title builder: add prune options to the API + buildkit vendor builder: add prune options to the API Aug 20, 2018
@andrewhsu
Copy link
Member

Only one failure on z known to be flakey:

FAIL: docker_cli_swarm_test.go:1376: DockerSwarmSuite.TestSwarmClusterRotateUnlockKey

@andrewhsu
Copy link
Member

SGTM wrt getting apis for pruning things that are built

@tiborvass
Copy link
Contributor Author

For my clarification:
Isnt all mutually exclusive with the Keep* options?
Also, what happens when KeepDuration is met but KeepStorage isnt or vice versa?

@anusha-ragunathan There are different type of caches in buildkit: for regular cache, frontend images, internal images. By default only regular cache is pruned, but if you specify All then all types are pruned. So you can mix that with KeepMaxAge (renamed from KeepDuration) and KeepStorage. The rule is that if the cache matches keepmaxage AND keepstorage, then it is kept, otherwise it is purged. If you want to do an OR, you do 2 separate operations, one with keepmaxage, another one with keepstorage.

@tonistiigi
Copy link
Member

Talked with @tiborvass about this. The conclusion was to move the maxage to a filter, leave everything else as is as other fields are not really filters. For the gc, it is a list of these same options that just apply automatically and if the user wants to override they can do it with the config file initially.

@tiborvass tiborvass force-pushed the new-builder-prune branch 4 times, most recently from 3af5dbc to 5340314 Compare August 31, 2018 19:15
@tiborvass
Copy link
Contributor Author

@tonistiigi @AkihiroSuda @vdemeester So this round of changes include:

  • Changed max-age filter to unused-for because I realized the filter was backwards: we want to prune everything that wasn't used for .
  • Fixed a bug where prune would be equivalent to prune --all
  • Shows deleted IDs
  • Mutable was removed from BuildCache API, and Type and Shared were added.
  • mutable and immutable are no longer valid filters for prune, but type now is.

@tiborvass
Copy link
Contributor Author

Failures are unrelated.

}
ks, err := strconv.Atoi(r.FormValue("keep-storage"))
if err != nil {
return errors.Wrap(err, "keep-storage is in bytes and expects an integer")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: print values on parse errors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

Tibor Vass added 2 commits September 1, 2018 22:01
Signed-off-by: Tibor Vass <tibor@docker.com>
Signed-off-by: Tibor Vass <tibor@docker.com>
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Signed-off-by: Tibor Vass <tibor@docker.com>
@tiborvass
Copy link
Contributor Author

@tonistiigi I pushed your fix for Shared. Also updated the CLI branch: docker/cli#1327

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐯

@thaJeztah
Copy link
Member

Looks like we forgot to update the API changelog document in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet