From b953727881d1660d5b51af930f47843b0da00da4 Mon Sep 17 00:00:00 2001 From: Tully Foote Date: Fri, 24 Jan 2025 11:58:06 -0800 Subject: [PATCH 1/3] improve robustness of image cleanup --- src/rocker/core.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/rocker/core.py b/src/rocker/core.py index 03af51c3..756176e9 100644 --- a/src/rocker/core.py +++ b/src/rocker/core.py @@ -251,12 +251,24 @@ def docker_build(docker_client = None, output_callback = None, **kwargs): print("no more output and success not detected") return None -def docker_remove_image(image_id, docker_client = None, output_callback = None, **kwargs): +def docker_remove_image( + image_id, + docker_client = None, + output_callback = None, + fail_on_error = False, + force = False, + **kwargs): if not docker_client: docker_client = get_docker_client() - docker_client.remove_image(image_id) + try: + docker_client.remove_image(image_id, force=force) + except docker.errors.APIError as ex: + ## removing the image can fail if there's child images + if fail_on_error: + return False + return True class SIGWINCHPassthrough(object): def __init__ (self, process): @@ -421,7 +433,8 @@ def run(self, command='', **kwargs): def clear_image(self): if self.image_id: - docker_remove_image(self.image_id) + if not docker_remove_image(self.image_id): + print(f'Failed to clear image {self.image_id} it likely has child images.') self.image_id = None self.built = False From 4a6e19171765e417d211ec9a139a66987bca5645 Mon Sep 17 00:00:00 2001 From: Tully Foote Date: Fri, 24 Jan 2025 21:54:42 -0800 Subject: [PATCH 2/3] Don't automatically clean up a named image That makes the name useless --- src/rocker/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rocker/cli.py b/src/rocker/cli.py index e74791b7..70d2cfbc 100644 --- a/src/rocker/cli.py +++ b/src/rocker/cli.py @@ -69,13 +69,13 @@ def main(): exit_code = dig.build(**vars(args)) if exit_code != 0: print("Build failed exiting") - if not args_dict['persist_image']: + if not (args_dict['persist_image'] or args_dict.get('image_name')): dig.clear_image() return exit_code # Convert command into string args.command = ' '.join(args.command) result = dig.run(**args_dict) - if not args_dict['persist_image']: + if not (args_dict['persist_image'] or args_dict.get('image_name')): print(f'Clearing Image: {dig.image_id}s\nTo not clean up use --persist-images') dig.clear_image() return result From df00fb468a4e734f10abb3facd18693c9c8cd655 Mon Sep 17 00:00:00 2001 From: Tully Foote Date: Fri, 31 Jan 2025 17:44:28 -0800 Subject: [PATCH 3/3] Remove unused output_callback As flagged in the review --- src/rocker/core.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rocker/core.py b/src/rocker/core.py index 756176e9..b0a7b54d 100644 --- a/src/rocker/core.py +++ b/src/rocker/core.py @@ -254,7 +254,6 @@ def docker_build(docker_client = None, output_callback = None, **kwargs): def docker_remove_image( image_id, docker_client = None, - output_callback = None, fail_on_error = False, force = False, **kwargs):