Skip to content

Commit 44901a6

Browse files
committed
cosalib/container_manifest.py: account for images that are repo:tag
enhance the garbage collection for the repo:tag we are trying to create a container image manifest for. In this case we were getting an error because someone had pulled the quay.io/coreos-assembler/coreos-assembler:main image down from quay. It wasn't a manifest listed repo:tag so `podman manifest exists` wasn't returning true, but the create would fail. The updated code here should handle this case. This enhances the previous effort in 01e4e55.
1 parent 7dd4b4d commit 44901a6

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/cosalib/container_manifest.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,36 @@ 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):
23+
def local_container_manifest_or_image_exists(repo, tag):
2424
'''
25-
Delete local manifest list
25+
Delete local manifest list or image associated with repo:tag
2626
@param repo str registry repository
27-
@param tag str manifest tag
27+
@param tag str tag
2828
'''
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
29+
cmds = [["podman", "manifest", "exists", f"{repo}:{tag}"],
30+
["podman", "image", "exists", f"{repo}:{tag}"]]
31+
for cmd in cmds:
32+
cp = runcmd(cmd, check=False)
33+
# The commands returns 0 (exists), 1 (doesn't exist), 125 (other error)
34+
if cp.returncode == 125:
35+
if cp.stdout:
36+
print(f" STDOUT: {cp.stdout.decode()}")
37+
if cp.stderr:
38+
print(f" STDERR: {cp.stderr.decode()}")
39+
raise Exception("Error encountered when checking if manifest exists")
40+
if cp.returncode == 0:
41+
return True
42+
return False
3943

4044

41-
def delete_local_container_manifest(repo, tag):
45+
def delete_local_container_imgref(repo, tag):
4246
'''
43-
Delete local manifest list
47+
Delete local manifest list or image associated with repo:tag
4448
@param repo str registry repository
4549
@param tag str manifest tag
4650
'''
47-
cmd = ["podman", "manifest", "rm", f"{repo}:{tag}"]
51+
# Note `podman image rm` will delete a manifest or plain image
52+
cmd = ["podman", "image", "rm", f"{repo}:{tag}"]
4853
runcmd(cmd)
4954

5055

@@ -74,10 +79,10 @@ def create_and_push_container_manifest(repo, tags, images, v2s2) -> dict:
7479
@param images list of image specifications (including transport)
7580
@param v2s2 boolean use to force v2s2 format
7681
'''
77-
if local_container_manifest_exists(repo, tags[0]):
82+
if local_container_manifest_or_image_exists(repo, tags[0]):
7883
# perhaps left over from a previous failed run -> delete
79-
delete_local_container_manifest(repo, tags[0])
84+
delete_local_container_imgref(repo, tags[0])
8085
manifest_info = create_local_container_manifest(repo, tags[0], images)
8186
push_container_manifest(repo, tags, v2s2)
82-
delete_local_container_manifest(repo, tags[0])
87+
delete_local_container_imgref(repo, tags[0])
8388
return manifest_info

0 commit comments

Comments
 (0)