Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ansible/ansible-runner
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.3.5
Choose a base ref
...
head repository: ansible/ansible-runner
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2.3.6
Choose a head ref
  • 1 commit
  • 1 file changed
  • 2 contributors

Commits on Mar 12, 2024

  1. Untag instead of force remove image for podman (#1342) (#1344)

    now cleanup_images will behave the same for podman and docker
    
    (cherry picked from commit d51a2f3)
    
    Co-authored-by: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com>
    Shrews and TheRealHaoLiu authored Mar 12, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    709cdfc View commit details
Showing with 17 additions and 3 deletions.
  1. +17 −3 ansible_runner/cleanup.py
20 changes: 17 additions & 3 deletions ansible_runner/cleanup.py
Original file line number Diff line number Diff line change
@@ -144,15 +144,29 @@ def cleanup_dirs(pattern, exclude_strings=(), grace_period=GRACE_PERIOD_DEFAULT)


def cleanup_images(images, runtime='podman'):
"""Note: docker will just untag while podman will remove layers with same command"""
"""
`docker rmi` will just untag while
`podman rmi` will untag and remove layers and cause runing container to be killed
for podman we use `untag` to achieve the same behavior
NOTE: this only untag the image and does not delete the image prune_images need to be call to delete
"""
rm_ct = 0
for image_tag in images:
stdout = run_command([runtime, 'images', '--format="{{.Repository}}:{{.Tag}}"', image_tag])
if not stdout:
continue
for discovered_tag in stdout.split('\n'):
stdout = run_command([runtime, 'rmi', discovered_tag.strip().strip('"'), '-f'])
rm_ct += stdout.count('Untagged:')
if runtime == 'podman':
try:
stdout = run_command([runtime, 'untag', image_tag])
if not stdout:
rm_ct += 1
except Exception:
pass # best effort untag
else:
stdout = run_command([runtime, 'rmi', discovered_tag.strip().strip('"'), '-f'])
rm_ct += stdout.count('Untagged:')
return rm_ct