From 9639525e89bf107c20fe860f50fa01b26f00692c Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Tue, 19 Nov 2024 15:35:54 -0500 Subject: [PATCH] cosalib/container_manifest.py: cleanup manifest before create/push If a manifest previously exists then let's try to clean it up before continuing. We saw this in the pipeline where one run failed in the middle and then a later run failed because the manifest existed: ``` 2024-11-19 14:29:26,184 INFO - Running command: ['podman', 'manifest', 'create', 'quay.io/coreos-assembler/coreos-assembler:main'] Error: creating manifest: image name "quay.io/coreos-assembler/coreos-assembler:main" is already associated with image "ffbb463bfb0e3bb0fb4c42856d2dca0ff985d1dd5d7b34f1b3ae0277287ad83d": that name is already in use ``` --- src/cosalib/container_manifest.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/cosalib/container_manifest.py b/src/cosalib/container_manifest.py index 56538174ca..f7307beaa3 100644 --- a/src/cosalib/container_manifest.py +++ b/src/cosalib/container_manifest.py @@ -20,6 +20,24 @@ def create_local_container_manifest(repo, tag, images) -> dict: return json.loads(manifest_info) +def local_container_manifest_exists(repo, tag): + ''' + Delete local manifest list + @param repo str registry repository + @param tag str manifest tag + ''' + cmd = ["podman", "manifest", "exists", f"{repo}:{tag}"] + cp = runcmd(cmd, check=False) + # The commands returns 0 (exists), 1 (doesn't exist), 125 (other error) + if cp.returncode == 125: + if cp.stdout: + print(f" STDOUT: {cp.stdout.decode()}") + if cp.stderr: + print(f" STDERR: {cp.stderr.decode()}") + raise Exception("Error encountered when checking if manifest exists") + return cp.returncode == 0 + + def delete_local_container_manifest(repo, tag): ''' Delete local manifest list @@ -56,6 +74,9 @@ def create_and_push_container_manifest(repo, tags, images, v2s2) -> dict: @param images list of image specifications (including transport) @param v2s2 boolean use to force v2s2 format ''' + if local_container_manifest_exists(repo, tags[0]): + # perhaps left over from a previous failed run -> delete + delete_local_container_manifest(repo, tags[0]) manifest_info = create_local_container_manifest(repo, tags[0], images) push_container_manifest(repo, tags, v2s2) delete_local_container_manifest(repo, tags[0])