|
|
@ -16,14 +16,16 @@ def run_command_in_image(image: str, commands: list[str]) -> tuple:
|
|
|
|
(_,_) = run_command(["docker", "kill", cid])
|
|
|
|
(_,_) = run_command(["docker", "kill", cid])
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_os_hash(image:str) -> dict:
|
|
|
|
|
|
|
|
|
|
|
|
def get_os_for_image(image: str) -> str:
|
|
|
|
|
|
|
|
(stdout, _) = run_command_in_image(image, ["cat", "/etc/os-release"])
|
|
|
|
(stdout, _) = run_command_in_image(image, ["cat", "/etc/os-release"])
|
|
|
|
hash = dict()
|
|
|
|
hash = dict()
|
|
|
|
for line in stdout.decode().split('\n'):
|
|
|
|
for line in stdout.decode().split('\n'):
|
|
|
|
(name, var) = line.partition("=")[::2]
|
|
|
|
if len(line) != 0:
|
|
|
|
hash[name.strip().strip('"')] = var.strip().strip('"')
|
|
|
|
(name, var) = line.partition("=")[::2]
|
|
|
|
|
|
|
|
hash[name.strip().strip('"')] = var.strip().strip('"')
|
|
|
|
|
|
|
|
return hash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_os_for_image(image: str, hash: dict) -> str:
|
|
|
|
if "PRETTY_NAME" in hash:
|
|
|
|
if "PRETTY_NAME" in hash:
|
|
|
|
if hash["PRETTY_NAME"] == "Distroless":
|
|
|
|
if hash["PRETTY_NAME"] == "Distroless":
|
|
|
|
return "distroless"
|
|
|
|
return "distroless"
|
|
|
@ -79,8 +81,8 @@ def get_inspect_data(image: str) -> list[dict]:
|
|
|
|
(output, _) = run_command(["docker", "image", "inspect", image])
|
|
|
|
(output, _) = run_command(["docker", "image", "inspect", image])
|
|
|
|
return json.loads(output.decode())
|
|
|
|
return json.loads(output.decode())
|
|
|
|
|
|
|
|
|
|
|
|
def get_packages(image: str) -> list[dict]:
|
|
|
|
def get_packages(image: str, hash: dict) -> list[dict]:
|
|
|
|
os = get_os_for_image(image)
|
|
|
|
os = get_os_for_image(image, hash)
|
|
|
|
command = list()
|
|
|
|
command = list()
|
|
|
|
result = list()
|
|
|
|
result = list()
|
|
|
|
match os:
|
|
|
|
match os:
|
|
|
@ -119,9 +121,11 @@ if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
result = dict()
|
|
|
|
result = dict()
|
|
|
|
for image in args.images:
|
|
|
|
for image in args.images:
|
|
|
|
pkg_list = get_packages(image)
|
|
|
|
os_hash = get_os_hash(image)
|
|
|
|
|
|
|
|
pkg_list = get_packages(image, os_hash)
|
|
|
|
inspect_data = get_inspect_data(image)
|
|
|
|
inspect_data = get_inspect_data(image)
|
|
|
|
result[image] = { "pkg_list": pkg_list }
|
|
|
|
result[image] = { "pkg_list": pkg_list }
|
|
|
|
result[image]["inspect_data"] = inspect_data
|
|
|
|
result[image]["inspect_data"] = inspect_data
|
|
|
|
|
|
|
|
result[image]["os_hash"] = os_hash
|
|
|
|
|
|
|
|
|
|
|
|
print(json.dumps(result))
|
|
|
|
print(json.dumps(result))
|
|
|
|