Fix Docker image deletion when using remove_images: true#361
Fix Docker image deletion when using remove_images: true#361rshad wants to merge 3 commits intotest-kitchen:masterfrom
Conversation
| def remove_image(state) | ||
| image_id = state[:image_id] | ||
| docker_command("rmi #{image_id}") | ||
| run_command("docker ps -a | grep -q #{image_id} && echo 'Can not delete such image; It is being used by running container/s' || docker rmi #{image_id}") |
There was a problem hiding this comment.
Could we implement this using a new method inside this helper instead of in line with bash? I'd rather raise an exception and allow test kitchen to handle the exception instead of writing a message to stdout.
Something more like this?
def image_in_use?
# determine if image is in use with a running container
end
def remove_image(state)
image_id = state[:image_id]
raise "Can not delete image #{state[:image_id]}. It is being used by a running container." if image_in_use?
docker_command("rmi #{image_id}")
end
Hi @jeffreycoe, sorry I didn't have time to add the changes you requested before, but I think this issue is still persisting. Kind regards, |
|
@rshad - Thanks for the response. Will you be updating this PR with these changes, or can this PR be closed out and be addressed at a later time? |
Sorry, I am not working with kitchen since many months ago and I don't think that I'll be adding the related changes soon. Kind regards, Rshad |
|
@rshad Ok - I'll close this PR for now, and we can revisit this at a later time. Thanks! |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #361 +/- ##
==========================================
+ Coverage 35.29% 35.36% +0.06%
==========================================
Files 9 9
Lines 510 509 -1
==========================================
Hits 180 180
+ Misses 330 329 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Hi all!
This PR resolves #360
My fix is based on the idea of deleting the target Docker image only if it's not being used by an existing container, in other cases Kitchen will print an INFO message.
Note: I first merged the fix of #356 from the corresponding fork branch: paulcalabro:fix-ip-address-issue.Kr,
Rshad