From dce9c8946bf8f60d40796da39d1da08a2f823da2 Mon Sep 17 00:00:00 2001 From: aliciaaevans Date: Fri, 13 Dec 2024 18:29:09 -0500 Subject: [PATCH] fix: prune stopped containers after build --- bioconda_utils/build.py | 5 ++++- bioconda_utils/docker_utils.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bioconda_utils/build.py b/bioconda_utils/build.py index b4612fafdb..6daddd1733 100644 --- a/bioconda_utils/build.py +++ b/bioconda_utils/build.py @@ -494,6 +494,9 @@ def build_recipes(recipe_folder: str, config_path: str, recipes: List[str], # remove traces of the build if not keep_old_work: conda_build_purge() + # prune stopped containers + if docker_builder is not None: + docker_utils.pruneStoppedContainers() if failed or failed_uploads: logger.error('BUILD SUMMARY: of %s recipes, ' @@ -525,4 +528,4 @@ def report_resources(message, show_docker=True): logger.info("{0} Free disk space: {1:.2f} MB. Free memory: {2:.2f} MB ({3:.2f}%)".format(message, free_space_mb, free_mem_mb, free_mem_percent)) if show_docker: cmd = ['docker', 'system', 'df'] - utils.run(cmd, mask=False, live=True) \ No newline at end of file + utils.run(cmd, mask=False, live=True) diff --git a/bioconda_utils/docker_utils.py b/bioconda_utils/docker_utils.py index 3296cf8841..65c587f3f2 100644 --- a/bioconda_utils/docker_utils.py +++ b/bioconda_utils/docker_utils.py @@ -490,3 +490,8 @@ def purgeImage(mulled_upload_target, img): pkg_container_image = f"quay.io/{mulled_upload_target}/{pkg_name}:{pkg_version}--{pkg_build_string}" cmd = ['docker', 'rmi', pkg_container_image] o = utils.run(cmd, mask=False) + + +def pruneStoppedContainers(): + cmd = ['docker', 'container', 'prune', '-f'] + utils.run(cmd, mask=False)