mirror of
https://github.com/acedanger/shell.git
synced 2026-03-24 18:01:49 -07:00
feat: Enhance Diun integration to support image tags and update status reporting
This commit is contained in:
@@ -97,11 +97,15 @@ def get_diun_info():
|
||||
# If no registry (no /), prepend library/
|
||||
if "/" not in norm_name:
|
||||
norm_name = f"library/{norm_name}"
|
||||
|
||||
tag = latest.get("tag", "latest")
|
||||
|
||||
if norm_name not in diun_info:
|
||||
diun_info[norm_name] = {}
|
||||
|
||||
diun_info[norm_name] = {
|
||||
diun_info[norm_name][tag] = {
|
||||
"digest": digest,
|
||||
"labels": labels,
|
||||
"tag": latest.get("tag", ""),
|
||||
"original_name": name
|
||||
}
|
||||
|
||||
@@ -202,28 +206,59 @@ def list_containers(projects):
|
||||
|
||||
# Normalize image name for lookup
|
||||
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/"):
|
||||
norm_image = norm_image[10:]
|
||||
if "/" not in norm_image:
|
||||
norm_image = f"library/{norm_image}"
|
||||
|
||||
# Check Diun info
|
||||
if norm_image in diun_info:
|
||||
info = diun_info[norm_image]
|
||||
# Try to get version from Diun labels first
|
||||
version = get_image_version(info.get("labels", {}))
|
||||
|
||||
# Check for updates
|
||||
inspect_digest_cmd = ["docker", "inspect", c_name, "--format", "{{index .RepoDigests 0}}"]
|
||||
inspect_digest_res = run_command(inspect_digest_cmd, path, capture_output=True)
|
||||
if inspect_digest_res and inspect_digest_res.returncode == 0:
|
||||
running_digest_full = inspect_digest_res.stdout.strip()
|
||||
# running_digest is like name@sha256:hash
|
||||
if "@" in running_digest_full:
|
||||
running_digest = running_digest_full.split("@")[1]
|
||||
latest_digest = info.get("digest", "")
|
||||
if latest_digest and running_digest != latest_digest:
|
||||
update_status = "Update Available"
|
||||
if diun_info:
|
||||
if norm_image in diun_info:
|
||||
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
|
||||
version = get_image_version(info.get("labels", {}))
|
||||
|
||||
# Check for updates
|
||||
# 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)
|
||||
|
||||
if inspect_digest_res and inspect_digest_res.returncode == 0:
|
||||
running_digest_full = inspect_digest_res.stdout.strip()
|
||||
# running_digest is like name@sha256:hash
|
||||
if "@" in running_digest_full:
|
||||
running_digest = running_digest_full.split("@")[1]
|
||||
latest_digest = info.get("digest", "")
|
||||
|
||||
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 == "latest" or version == "unknown":
|
||||
|
||||
Reference in New Issue
Block a user