Skip to content

Fix Docker image deletion when using remove_images: true#361

Closed
rshad wants to merge 3 commits intotest-kitchen:masterfrom
rshad:fix-docker-image-deletion
Closed

Fix Docker image deletion when using remove_images: true#361
rshad wants to merge 3 commits intotest-kitchen:masterfrom
rshad:fix-docker-image-deletion

Conversation

@rshad
Copy link
Copy Markdown

@rshad rshad commented Feb 5, 2020

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

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}")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jeffreycoe
Copy link
Copy Markdown
Contributor

jeffreycoe commented Jun 23, 2020

Hi @rshad - Do you have any update to this PR based on the previous feedback? Do we still need these updates or can this PR be closed?

Also, another PR was merged to fix #356, so this change would have to be removed from this PR. Thanks.

@rshad
Copy link
Copy Markdown
Author

rshad commented Jun 23, 2020

Hi @rshad - Do you have any update to this PR based on the previous feedback? Do we still need these updates or can this PR be closed?

Also, another PR was merged to fix #356, so this change would have to be removed from this PR. Thanks.

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,

@jeffreycoe
Copy link
Copy Markdown
Contributor

@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?

@rshad
Copy link
Copy Markdown
Author

rshad commented Jul 1, 2020

@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

@jeffreycoe
Copy link
Copy Markdown
Contributor

@rshad Ok - I'll close this PR for now, and we can revisit this at a later time. Thanks!

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.36%. Comparing base (9b66340) to head (c204b4f).

Files with missing lines Patch % Lines
lib/kitchen/docker/container/linux.rb 0.00% 1 Missing ⚠️
lib/kitchen/docker/helpers/image_helper.rb 0.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docker images deletions fails when instances share the same image ID

4 participants