From 8231e06c1d33e56dc74d72f805c7d4f0096019cc Mon Sep 17 00:00:00 2001 From: Khushiyant Date: Tue, 1 Apr 2025 19:58:07 +0530 Subject: [PATCH] feat: add prune_builds method with additional space management parameters Signed-off-by: Khushiyant --- docker/api/build.py | 62 +++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/docker/api/build.py b/docker/api/build.py index 47216a58f..aeb09252d 100644 --- a/docker/api/build.py +++ b/docker/api/build.py @@ -275,32 +275,38 @@ 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, filters=None, keep_storage=None, all=None): + def prune_builds(self, filters=None, keep_storage=None, all=None, max_used_space=None, reserved_space=None, min_free_space=None): """ - Delete the builder cache - - Args: - filters (dict): Filters to process on the prune list. - Needs Docker API v1.39+ - 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. - Needs Docker API v1.39+ - all (bool): Remove all types of build cache. - Needs Docker API v1.39+ - - Returns: - (dict): A dictionary containing information about the operation's - result. The ``SpaceReclaimed`` key indicates the amount of - bytes of disk space reclaimed. - - Raises: - :py:class:`docker.errors.APIError` - If the server returns an error. + Delete the builder cache + + Args: + filters (dict): Filters to process on the prune list. + Needs Docker API v1.39+ + 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. + Needs Docker API v1.39+ + all (bool): Remove all types of build cache. + Needs Docker API v1.39+ + reserved-space (int): The minimum amount of disk space that Docker is allowed to keep for build cache. + Cache below this threshold won't be removed during garbage collection. + max-used-space (int): The maximum amount of disk space that Docker is allowed to use for build cache. + Any usage above this threshold will be reclaimed during garbage collection. Needs Docker API v1.48+ + min-free-space (int): The target amount of free disk space that the garbage collector will attempt to maintain on your system. + Needs Docker API v1.48+ + + Returns: + (dict): A dictionary containing information about the operation's + result. The ``SpaceReclaimed`` key indicates the amount of + bytes of disk space reclaimed. + + Raises: + :py:class:`docker.errors.APIError` + If the server returns an error. """ url = self._url("/build/prune") if (filters, keep_storage, all) != (None, None, None) \ @@ -316,6 +322,12 @@ def prune_builds(self, filters=None, keep_storage=None, all=None): params['keep-storage'] = keep_storage if all is not None: params['all'] = all + if max_used_space is not None: + params['max-used-space'] = max_used_space + if reserved_space is not None: + params['reserved-space'] = reserved_space + if min_free_space is not None: + params['min-free-space'] = min_free_space return self._result(self._post(url, params=params), True) def _set_auth_headers(self, headers):