mirror of
https://github.com/acedanger/shell.git
synced 2026-03-24 20:11:49 -07:00
feat: Enhance Diun integration to support image tags and update status reporting
This commit is contained in:
@@ -98,10 +98,14 @@ def get_diun_info():
|
|||||||
if "/" not in norm_name:
|
if "/" not in norm_name:
|
||||||
norm_name = f"library/{norm_name}"
|
norm_name = f"library/{norm_name}"
|
||||||
|
|
||||||
diun_info[norm_name] = {
|
tag = latest.get("tag", "latest")
|
||||||
|
|
||||||
|
if norm_name not in diun_info:
|
||||||
|
diun_info[norm_name] = {}
|
||||||
|
|
||||||
|
diun_info[norm_name][tag] = {
|
||||||
"digest": digest,
|
"digest": digest,
|
||||||
"labels": labels,
|
"labels": labels,
|
||||||
"tag": latest.get("tag", ""),
|
|
||||||
"original_name": name
|
"original_name": name
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,28 +206,59 @@ def list_containers(projects):
|
|||||||
|
|
||||||
# Normalize image name for lookup
|
# Normalize image name for lookup
|
||||||
norm_image = image
|
norm_image = image
|
||||||
|
tag = "latest"
|
||||||
|
|
||||||
|
# Remove tag if present (heuristic: split on last colon, if right side has no slashes)
|
||||||
|
if ":" in norm_image:
|
||||||
|
base, sep, t = norm_image.rpartition(":")
|
||||||
|
if sep and "/" not in t:
|
||||||
|
norm_image = base
|
||||||
|
tag = t
|
||||||
|
|
||||||
if norm_image.startswith("docker.io/"):
|
if norm_image.startswith("docker.io/"):
|
||||||
norm_image = norm_image[10:]
|
norm_image = norm_image[10:]
|
||||||
if "/" not in norm_image:
|
if "/" not in norm_image:
|
||||||
norm_image = f"library/{norm_image}"
|
norm_image = f"library/{norm_image}"
|
||||||
|
|
||||||
# Check Diun info
|
# Check Diun info
|
||||||
|
if diun_info:
|
||||||
if norm_image in diun_info:
|
if norm_image in diun_info:
|
||||||
info = diun_info[norm_image]
|
image_tags = diun_info[norm_image]
|
||||||
|
|
||||||
|
# Only proceed if we have info for this specific tag
|
||||||
|
if tag in image_tags:
|
||||||
|
info = image_tags[tag]
|
||||||
# Try to get version from Diun labels first
|
# Try to get version from Diun labels first
|
||||||
version = get_image_version(info.get("labels", {}))
|
version = get_image_version(info.get("labels", {}))
|
||||||
|
|
||||||
# Check for updates
|
# Check for updates
|
||||||
inspect_digest_cmd = ["docker", "inspect", c_name, "--format", "{{index .RepoDigests 0}}"]
|
# First get the Image ID of the running container
|
||||||
|
inspect_id_cmd = ["docker", "inspect", c_name, "--format", "{{.Image}}"]
|
||||||
|
inspect_id_res = run_command(inspect_id_cmd, path, capture_output=True)
|
||||||
|
|
||||||
|
if inspect_id_res and inspect_id_res.returncode == 0:
|
||||||
|
image_id = inspect_id_res.stdout.strip()
|
||||||
|
|
||||||
|
# Now inspect the Image ID to get RepoDigests
|
||||||
|
inspect_digest_cmd = ["docker", "inspect", image_id, "--format", "{{if .RepoDigests}}{{index .RepoDigests 0}}{{end}}"]
|
||||||
inspect_digest_res = run_command(inspect_digest_cmd, path, capture_output=True)
|
inspect_digest_res = run_command(inspect_digest_cmd, path, capture_output=True)
|
||||||
|
|
||||||
if inspect_digest_res and inspect_digest_res.returncode == 0:
|
if inspect_digest_res and inspect_digest_res.returncode == 0:
|
||||||
running_digest_full = inspect_digest_res.stdout.strip()
|
running_digest_full = inspect_digest_res.stdout.strip()
|
||||||
# running_digest is like name@sha256:hash
|
# running_digest is like name@sha256:hash
|
||||||
if "@" in running_digest_full:
|
if "@" in running_digest_full:
|
||||||
running_digest = running_digest_full.split("@")[1]
|
running_digest = running_digest_full.split("@")[1]
|
||||||
latest_digest = info.get("digest", "")
|
latest_digest = info.get("digest", "")
|
||||||
if latest_digest and running_digest != latest_digest:
|
|
||||||
update_status = "Update Available"
|
if latest_digest:
|
||||||
|
if running_digest != latest_digest:
|
||||||
|
update_status = "[bold red]Update Available[/bold red]"
|
||||||
|
else:
|
||||||
|
update_status = "[green]Up to Date[/green]"
|
||||||
|
else:
|
||||||
|
update_status = "[dim]Tag Not Monitored[/dim]"
|
||||||
|
else:
|
||||||
|
update_status = "[dim]Not Monitored[/dim]"
|
||||||
|
|
||||||
# If version is still unknown, try to get from running container labels
|
# If version is still unknown, try to get from running container labels
|
||||||
if version == "latest" or version == "unknown":
|
if version == "latest" or version == "unknown":
|
||||||
|
|||||||
Reference in New Issue
Block a user