Skip to content

Commit 8231e06

Browse files
committed
feat: add prune_builds method with additional space management parameters
Signed-off-by: Khushiyant <khushiyant2002@gmail.com>
1 parent db7f8b8 commit 8231e06

File tree

1 file changed

+37
-25
lines changed

1 file changed

+37
-25
lines changed

docker/api/build.py

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -275,32 +275,38 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
275275
return self._stream_helper(response, decode=decode)
276276

277277
@utils.minimum_version('1.31')
278-
def prune_builds(self, filters=None, keep_storage=None, all=None):
278+
def prune_builds(self, filters=None, keep_storage=None, all=None, max_used_space=None, reserved_space=None, min_free_space=None):
279279
"""
280-
Delete the builder cache
281-
282-
Args:
283-
filters (dict): Filters to process on the prune list.
284-
Needs Docker API v1.39+
285-
Available filters:
286-
- dangling (bool): When set to true (or 1), prune only
287-
unused and untagged images.
288-
- until (str): Can be Unix timestamps, date formatted
289-
timestamps, or Go duration strings (e.g. 10m, 1h30m) computed
290-
relative to the daemon's local time.
291-
keep_storage (int): Amount of disk space in bytes to keep for cache.
292-
Needs Docker API v1.39+
293-
all (bool): Remove all types of build cache.
294-
Needs Docker API v1.39+
295-
296-
Returns:
297-
(dict): A dictionary containing information about the operation's
298-
result. The ``SpaceReclaimed`` key indicates the amount of
299-
bytes of disk space reclaimed.
300-
301-
Raises:
302-
:py:class:`docker.errors.APIError`
303-
If the server returns an error.
280+
Delete the builder cache
281+
282+
Args:
283+
filters (dict): Filters to process on the prune list.
284+
Needs Docker API v1.39+
285+
Available filters:
286+
- dangling (bool): When set to true (or 1), prune only
287+
unused and untagged images.
288+
- until (str): Can be Unix timestamps, date formatted
289+
timestamps, or Go duration strings (e.g. 10m, 1h30m) computed
290+
relative to the daemon's local time.
291+
keep_storage (int): Amount of disk space in bytes to keep for cache.
292+
Needs Docker API v1.39+
293+
all (bool): Remove all types of build cache.
294+
Needs Docker API v1.39+
295+
reserved-space (int): The minimum amount of disk space that Docker is allowed to keep for build cache.
296+
Cache below this threshold won't be removed during garbage collection.
297+
max-used-space (int): The maximum amount of disk space that Docker is allowed to use for build cache.
298+
Any usage above this threshold will be reclaimed during garbage collection. Needs Docker API v1.48+
299+
min-free-space (int): The target amount of free disk space that the garbage collector will attempt to maintain on your system.
300+
Needs Docker API v1.48+
301+
302+
Returns:
303+
(dict): A dictionary containing information about the operation's
304+
result. The ``SpaceReclaimed`` key indicates the amount of
305+
bytes of disk space reclaimed.
306+
307+
Raises:
308+
:py:class:`docker.errors.APIError`
309+
If the server returns an error.
304310
"""
305311
url = self._url("/build/prune")
306312
if (filters, keep_storage, all) != (None, None, None) \
@@ -316,6 +322,12 @@ def prune_builds(self, filters=None, keep_storage=None, all=None):
316322
params['keep-storage'] = keep_storage
317323
if all is not None:
318324
params['all'] = all
325+
if max_used_space is not None:
326+
params['max-used-space'] = max_used_space
327+
if reserved_space is not None:
328+
params['reserved-space'] = reserved_space
329+
if min_free_space is not None:
330+
params['min-free-space'] = min_free_space
319331
return self._result(self._post(url, params=params), True)
320332

321333
def _set_auth_headers(self, headers):

0 commit comments

Comments
 (0)