Add docker cleanup steps

main
Micke Nordin 5 months ago
parent 6774b94caf
commit 4f219dab44
Signed by: micke
GPG Key ID: F53C4CC83EDAB3BE

@ -1,4 +1,4 @@
#!/usr/bin/env python3.10
#!/usr/bin/env python3
import argparse
import json
import subprocess
@ -16,6 +16,15 @@ def run_command_in_image(image: str, commands: list[str]) -> tuple:
(_,_) = run_command(["docker", "kill", cid])
return result
def cleanup_image(image: str) -> None:
check_command = ['docker', 'ps', '--filter', f'ancestor={image}', '--quiet']
(stdout, _) = run_command(check_command)
if stdout == b'':
(_,_) = run_command(["docker", "rmi", image, '--force'])
def cleanup_all() -> None:
(_,_) = run_command(["docker", "system", "prune", "-af", "--volumes"])
def get_os_hash(image:str) -> dict:
(stdout, _) = run_command_in_image(image, ["cat", "/etc/os-release"])
hash = dict()
@ -137,5 +146,7 @@ if __name__ == "__main__":
result[image] = { "pkg_list": pkg_list }
result[image]["inspect_data"] = inspect_data
result[image]["os_hash"] = os_hash
cleanup_image(image)
cleanup_all()
print(json.dumps(result))

Loading…
Cancel
Save