Skip to content

Commit 3d0a3f1

Browse files
authored
feat: accept all / filters / keep_storage in prune_builds (#3192)
Added in API v1.39. --------- Signed-off-by: Emran Batmanghelich <[email protected]>
1 parent a9b5494 commit 3d0a3f1

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

docker/api/build.py

+29-2
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,24 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
279279
return self._stream_helper(response, decode=decode)
280280

281281
@utils.minimum_version('1.31')
282-
def prune_builds(self):
282+
def prune_builds(self, filters=None, keep_storage=None, all=None):
283283
"""
284284
Delete the builder cache
285285
286+
Args:
287+
filters (dict): Filters to process on the prune list.
288+
Needs Docker API v1.39+
289+
Available filters:
290+
- dangling (bool): When set to true (or 1), prune only
291+
unused and untagged images.
292+
- until (str): Can be Unix timestamps, date formatted
293+
timestamps, or Go duration strings (e.g. 10m, 1h30m) computed
294+
relative to the daemon's local time.
295+
keep_storage (int): Amount of disk space in bytes to keep for cache.
296+
Needs Docker API v1.39+
297+
all (bool): Remove all types of build cache.
298+
Needs Docker API v1.39+
299+
286300
Returns:
287301
(dict): A dictionary containing information about the operation's
288302
result. The ``SpaceReclaimed`` key indicates the amount of
@@ -293,7 +307,20 @@ def prune_builds(self):
293307
If the server returns an error.
294308
"""
295309
url = self._url("/build/prune")
296-
return self._result(self._post(url), True)
310+
if (filters, keep_storage, all) != (None, None, None) \
311+
and utils.version_lt(self._version, '1.39'):
312+
raise errors.InvalidVersion(
313+
'`filters`, `keep_storage`, and `all` args are only available '
314+
'for API version > 1.38'
315+
)
316+
params = {}
317+
if filters is not None:
318+
params['filters'] = utils.convert_filters(filters)
319+
if keep_storage is not None:
320+
params['keep-storage'] = keep_storage
321+
if all is not None:
322+
params['all'] = all
323+
return self._result(self._post(url, params=params), True)
297324

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

0 commit comments

Comments
 (0)