-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the robustness of image cleanup #313
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -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 | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems a little weird not to print or log a message when catching this error. The end-user has no way of knowing whether the image was cleaned up or not, especially with the default behavior of not failing on error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will return a True/False and then it warns the user based on the results: Line 437 in 4a6e191
And the default is False so it's only suppressed if the developer asks for it to be suppressed. |
||||
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 | ||||
|
||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of drive-by but
output_callback
appears completely unused. Is it deprecated?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this doesn't have the streaming interface so removing it makes sense.