Skip to content

Commit 01e4e55

Browse files
committed
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 ```
1 parent 5b8517c commit 01e4e55

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/cosalib/container_manifest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ def create_local_container_manifest(repo, tag, images) -> dict:
2020
return json.loads(manifest_info)
2121

2222

23+
def local_container_manifest_exists(repo, tag):
24+
'''
25+
Delete local manifest list
26+
@param repo str registry repository
27+
@param tag str manifest tag
28+
'''
29+
cmd = ["podman", "manifest", "exists", f"{repo}:{tag}"]
30+
cp = runcmd(cmd, check=False)
31+
# The commands returns 0 (exists), 1 (doesn't exist), 125 (other error)
32+
if cp.returncode == 125:
33+
if cp.stdout:
34+
print(f" STDOUT: {cp.stdout.decode()}")
35+
if cp.stderr:
36+
print(f" STDERR: {cp.stderr.decode()}")
37+
raise Exception("Error encountered when checking if manifest exists")
38+
return cp.returncode == 0
39+
40+
2341
def delete_local_container_manifest(repo, tag):
2442
'''
2543
Delete local manifest list
@@ -56,6 +74,9 @@ def create_and_push_container_manifest(repo, tags, images, v2s2) -> dict:
5674
@param images list of image specifications (including transport)
5775
@param v2s2 boolean use to force v2s2 format
5876
'''
77+
if local_container_manifest_exists(repo, tags[0]):
78+
# perhaps left over from a previous failed run -> delete
79+
delete_local_container_manifest(repo, tags[0])
5980
manifest_info = create_local_container_manifest(repo, tags[0], images)
6081
push_container_manifest(repo, tags, v2s2)
6182
delete_local_container_manifest(repo, tags[0])

0 commit comments

Comments
 (0)