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

feat: accept filters and keep_storage in prune_builds #3192

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: accept filters and keep_storage in prune_builds
Signed-off-by: Emran Batmanghelich <emran.bm@gmail.com>
  • Loading branch information
emranbm committed Dec 3, 2023
commit aeaac4c9fca444989eca320f38b78cf53ab1f900
19 changes: 17 additions & 2 deletions docker/api/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,20 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
return self._stream_helper(response, decode=decode)

@utils.minimum_version('1.31')
def prune_builds(self):
def prune_builds(self, filters=None, keep_storage=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

There's also all, which is a boolean and was added at the same time as filters and keep-storage - let's add that as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

"""
Delete the builder cache

Args:
filters (dict): Filters to process on the prune list.
Available filters:
- dangling (bool): When set to true (or 1), prune only
unused and untagged images.
- until (str): Can be Unix timestamps, date formatted
timestamps, or Go duration strings (e.g. 10m, 1h30m) computed
relative to the daemon's local time.
keep_storage (int): Amount of disk space in bytes to keep for cache.

Returns:
(dict): A dictionary containing information about the operation's
result. The ``SpaceReclaimed`` key indicates the amount of
Expand All @@ -290,7 +300,12 @@ def prune_builds(self):
If the server returns an error.
"""
url = self._url("/build/prune")
return self._result(self._post(url), True)
params = {}
if filters is not None:
params['filters'] = utils.convert_filters(filters)
if keep_storage is not None:
params['keep-storage'] = keep_storage
return self._result(self._post(url, params=params), True)
Copy link
Contributor

Choose a reason for hiding this comment

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

These args were added in API v1.39 - typically, we add a check for them, e.g.

if utils.version_lt(self._version, '1.39'):
    raise errors.InvalidVersion(
        '`keep-storage` arg only available for API version > 1.38'
    )

(if you look for utils.version_lt or utils.version_gte you'll see a bunch of examples - they're not 100% consistent so do whatever makes sense here, e.g. I'm fine if there's a single check if ANY of filters / keep_storage / any are not None since they were all added together in the same API version)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!


def _set_auth_headers(self, headers):
log.debug('Looking for auth config')
Expand Down