api/types/build: move build cache prune options from api to client#50772
Conversation
d5de104 to
63f159d
Compare
client/build_prune.go
Outdated
| MinFreeSpace int64 | ||
| Filters filters.Args | ||
|
|
||
| KeepStorage int64 // Deprecated: deprecated in API 1.48. |
There was a problem hiding this comment.
Wondering if there's any mapping possible from the above options to the old option.
i.e., thinking if we can somehow keep the KeepStorage an internal implementation detail and set it automatically based on the other options when talking to an older API.
Actually, I"m not even sure now if we even use any of these (bear with me);
When running with buildx installed, docker builder prune is executed by buildx;
docker builder prune --help
Usage: docker buildx prune
Remove build cache
Options:
-a, --all Include internal/frontend images
--builder string Override the configured builder instance (default "desktop-linux")
-D, --debug Enable debug logging
--filter filter Provide filter values (e.g., "until=24h")
-f, --force Do not prompt for confirmation
--max-used-space bytes Maximum amount of disk space allowed to keep for cache
--min-free-space bytes Target amount of free disk space after pruning
--reserved-space bytes Amount of disk space always allowed to keep for cache
--verbose Provide a more verbose outputWhen buildx is missing, or explicitly disabled, only then we get the docker builder prune command from the CLI itself;
DOCKER_BUILDKIT=0 docker builder prune --help
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
BuildKit is currently disabled; enable it by removing the DOCKER_BUILDKIT=0
environment-variable.
Usage: docker builder prune
Remove build cache
Options:
-a, --all Remove all unused build cache, not just dangling ones
--filter filter Provide filter values (e.g. "until=24h")
-f, --force Do not prompt for confirmation
--keep-storage bytes Amount of disk space to keep for cacheBut I don't think "pruning build cache" makes sense if you don't have buildkit 🤔
so are we never using it?
Well, we are, but only as part of docker system prune, because that also calls the "builder prune" endpoint through the REST API;
https://github.com/docker/cli/blob/v28.3.3/cli/command/system/prune.go#L44-L45
https://github.com/docker/cli/blob/v28.3.3/cli/command/system/prune.go#L96-L98
But honestly, not even sure if that should be called if BuildKit is disabled (only if enabled), and it does not allow options to be passed, or only very limited.
When running docker buildx prune (or the docker builder prune alias) with BuildKit enabled (so now docker buildx is executed), I don't think we even hit the REST API. This could also mean that running docker buildx prune won't trigger docker daemon events 🤔 https://github.com/docker/buildx/blob/v0.27.0/commands/prune.go#L43-L47
(thinking about #50725 where Docker Desktop didn't receive some events)
There was a problem hiding this comment.
LOL, maybe @crazy-max or @jsternberg has some ideas on this; basically: does the docker builder prune command (i.e., the one in the docker CLI that's only available with either buildx missing or DOCKER_BUILDKIT=0 have any purpose?
We should probably keep the client part to back the docker system prune command, but even for that ... maybe we can make docker system prune shell out to docker buildx prune as one of the steps and skip the REST API - but we'd miss the daemon events (on the /events endpoint) 🤔
51702ef to
d01ecdb
Compare
| if opts.ReservedSpace == 0 && opts.KeepStorage != 0 { | ||
| opts.ReservedSpace = opts.KeepStorage | ||
| } |
There was a problem hiding this comment.
Do we need to account for old clients setting that option?
@crazy-max if you have time to look along (also see my comment further up, which made my head spin a little 😅)
There was a problem hiding this comment.
It seems that is covered in the router code. Ref:
From what I see KeepStorage was not being set server side.
There was a problem hiding this comment.
Ah; derp; missed that one. It was late 😂
d01ecdb to
3e8a7d6
Compare
|
Okay, I improved my understanding for the state of I have updated the API documentation to correctly reflect |
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
3e8a7d6 to
7e2ee18
Compare
|
Rebased to resolve vendor conflicts. |
|
Had another peek at the CLI, but it looks like the deprecated Which means that;
I'm not exactly sure what new options are equivalent of the old options though, which I think was the reason I didn't update the CLI code I linked above 😂 🙈 |
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
7e2ee18 to
26e335b
Compare
@thaJeztah, I can help follow-up on that.
The daemon backend has this logic in place now. Anything prior to API 1.48 will parse
Makes sense, pushed that change to the client and added a task when it can be removed. |
thaJeztah
left a comment
There was a problem hiding this comment.
I can help follow-up on that.
Thanks! I think at the time I wasn't 100% sure what the replacement was, so jotted down that "TODO"; looks like it's just swapping for ReservedSpace, correct?
Makes sense, pushed that change to the client and added a task when it can be removed.
Thanks!
LGTM
| if opts.ReservedSpace != 0 { | ||
| query.Set("reserved-space", strconv.Itoa(int(opts.ReservedSpace))) | ||
| // Prior to API v1.48, 'keep-storage' was used to set the reserved space for the build cache. | ||
| // TODO(austinvazquez): remove once API v1.47 is no longer supported. See https://github.com/moby/moby/issues/50902 |
There was a problem hiding this comment.
I think for these version-specific constraints we don't have to keep separate tracking tickets; the version-gate itself is an implicit "remove once we drop this version".
Definitely fine for a follow-up, or when we rewrite these to functional args; for the functional args, perhaps we can even use our own struct tags on options for checking the API version 🤔
| if opts.ReservedSpace == 0 && opts.KeepStorage != 0 { | ||
| opts.ReservedSpace = opts.KeepStorage | ||
| } |
There was a problem hiding this comment.
Ah; derp; missed that one. It was late 😂
|
We can cherry-pick the first commit to the 28.x branch in case we do more (patch) releases from that branch |
- What I did
Partial for #50740
This change moves the cache prune options to the client module.
- How I did it
- How to verify it
- Human readable description for the release notes
- A picture of a cute animal (not mandatory but encouraged)