Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jsternberg
Copy link
Collaborator

@jsternberg jsternberg commented Oct 21, 2024

- What I did

This wires up the new gc types that buildkit exposes in version 0.17. The previous flag, KeepBytes, was renamed to ReservedBytes and two new options, MaxUsed and MinFree were added.

MaxUsed corresponds to the maximum amount of space that buildkit will
use for the build cache and MinFree amount of free disk space for the
system to prevent the cache from using that space. This allows greater
configuration of the cache storage usage when used in situations where
docker is not the only service on the system using disk space.

Fixes #48639.

- How I did it

Modified the areas marked by @thaJeztah in #48639.

- How to verify it

Added some test cases to check that the old and new config options work.

- Description for the changelog

`docker buildx prune` now supports `reserved-space`, `max-used-space` and `min-free-space`, `keep-bytes` filters.
API: `POST /build/prune` renames `keep-bytes` to `reserved-space` and now supports additional prune parameters `max-used-space` and `min-free-space`.

- A picture of a cute animal (not mandatory but encouraged)

const defaultCap int64 = 2e9 // 2GB
const (
defaultReservedSpaceBytes int64 = 2e9 // 2GB
defaultMaxUsedSpaceBytes int64 = 10e9 // 10GB
Copy link
Member

Choose a reason for hiding this comment

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

If for some reason the disk size can not be detected then maxused and minfree should be left empty.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

return defaultCap
import "github.com/containerd/errdefs"

func detectDiskSize(_ string) (int64, error) {
Copy link
Member

Choose a reason for hiding this comment

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

In buildkit we do have windows implementation and it seems to be in a reusable function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Switched to using this implementation. It also means I can just delete both of these files.

@jsternberg jsternberg force-pushed the buildkit-gc-options branch 3 times, most recently from 8423932 to 78356dd Compare October 22, 2024 16:21
@jsternberg
Copy link
Collaborator Author

Updated the swagger API and found a few additional places I missed by grepping for keep-storage.

@jsternberg jsternberg force-pushed the buildkit-gc-options branch 3 times, most recently from acd6af2 to 4e3c41c Compare October 22, 2024 18:07
@jsternberg jsternberg marked this pull request as ready for review October 22, 2024 18:34
@thaJeztah thaJeztah added this to the 28.0.0 milestone Oct 23, 2024
@jsternberg
Copy link
Collaborator Author

Updated the default gc policy code after some offline feedback from @tonistiigi.

@jsternberg jsternberg requested a review from tonistiigi October 24, 2024 14:58
bs, err := strconv.Atoi(fv)
if err != nil {
return invalidParam{errors.Wrapf(err, "keep-storage is in bytes and expects an integer, got %v", fv)}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

As this is a new API-level feature - we should either:

  1. Not backport this to 27.x
  2. Ship API v1.48 in 27.4 and move the current 1.48 API features to 1.49

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Looks like this one dropped of my radar 🙈

Yes, I'm considering to skip this one for 27.4; IIUC, without this patch, things continue to work "as before", just the new options not being exposed (?).

For these changes above though, possibly we need some API-version gates? (need to look closer)

@thompson-shaun
Copy link
Contributor

thompson-shaun commented Jan 16, 2025

Since we're only targeting v28 are we ok to merge this?

@jsternberg can we get this to a green/merge state?

@jsternberg
Copy link
Collaborator Author

This is rebased now. The failing test doesn't seem to be related.

@jsternberg jsternberg force-pushed the buildkit-gc-options branch 2 times, most recently from 54b8050 to 998dca6 Compare January 16, 2025 22:03
@thompson-shaun
Copy link
Contributor

@vvoland @thaJeztah - API version check?

Copy link
Contributor

@vvoland vvoland left a comment

Choose a reason for hiding this comment

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

New options should be API version gated.

docs/api/version-history.md also needs an entry for the newly supported options

@jsternberg
Copy link
Collaborator Author

@vvoland done. I've never done it before so please double check that I did it correctly.

If this is API version-gated, do we need the fallback code for keep-bytes to keep functioning?

Copy link
Contributor

@vvoland vvoland left a comment

Choose a reason for hiding this comment

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

Thanks, looks good but spotted some minor issues.

Could you also update the description for the release notes to be more human-facing?
Mostly thinking about showing the user how to use it. Something along the lines of "docker buildx prune now supports X, Y and Y",

@jsternberg
Copy link
Collaborator Author

Done.

@jsternberg jsternberg requested a review from vvoland January 24, 2025 21:22
Filters filters.Args

// FIXME(thaJeztah): add new options; see https://github.com/moby/moby/issues/48639
KeepStorage int64 // Deprecated: deprecated in API 1.48.
Copy link
Contributor

Choose a reason for hiding this comment

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

if opts.All {
query.Set("all", "1")
}
query.Set("keep-storage", strconv.Itoa(int(opts.KeepStorage)))
Copy link
Contributor

Choose a reason for hiding this comment

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

We're still keeping KeepStorage as deprecated, so we should still set it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Restored this code.

@thaJeztah thaJeztah added the release-blocker PRs we want to block a release on label Jan 30, 2025
This wires up the new gc types that buildkit exposes in version 0.17.
The previous flag, `KeepBytes`, was renamed to `ReservedBytes` and two
new options, `MaxUsed` and `MinFree` were added.

`MaxUsed` corresponds to the maximum amount of space that buildkit will
use for the build cache and `MinFree` amount of free disk space for the
system to prevent the cache from using that space. This allows greater
configuration of the cache storage usage when used in situations where
docker is not the only service on the system using disk space.

Signed-off-by: Jonathan A. Sternberg <[email protected]>
Copy link
Contributor

@vvoland vvoland left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@vvoland vvoland merged commit 72b8351 into moby:master Feb 3, 2025
153 checks passed
@jsternberg jsternberg deleted the buildkit-gc-options branch February 3, 2025 23:25
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.

Adjust BuildKit v0.17 GC configuration, and deprecate KeepBytes field

5 participants