Skip to content

Commit

Permalink
don't fail if manifest unknown is detected (#54)
Browse files Browse the repository at this point in the history
related #53
  • Loading branch information
linuxmaniac authored Jan 11, 2025
1 parent 5057c54 commit c761fae
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions clean_ghcr.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
DOCKER_ENDPOINT = "ghcr.io/"


class NoManifestErr(Exception):
pass


def get_url(path):
if path.startswith(API_ENDPOINT):
return path
Expand Down Expand Up @@ -121,16 +125,21 @@ def get_deps_pkgs(owner, pkgs):


def get_image_deps(image):
manifest_txt = get_manifest(image)
data = json.loads(manifest_txt)
return [manifest['digest'] for manifest in data.get("manifests", [])]
try:
manifest_txt = get_manifest(image)
data = json.loads(manifest_txt)
return [manifest["digest"] for manifest in data.get("manifests", [])]
except NoManifestErr:
return []


def get_manifest(image):
cmd = f"docker manifest inspect {image}"
res = subprocess.run(cmd, shell=True, capture_output=True)
if res.returncode != 0:
print(cmd)
if res.stderr == b"manifest unknown\n":
raise NoManifestErr()
raise Exception(res.stderr)
return res.stdout.decode("utf-8")

Expand Down

0 comments on commit c761fae

Please sign in to comment.