fix(scripts): give a repository not pushed yet no tags
The registry answers tags/list for a repository that does not exist yet with 404 NAME_UNKNOWN (OCI distribution spec), which failed the Images version step for the first build of a new image such as molecule-controller. A 404 on the first tags/list page now reads as no tags, so the image gets <base>.0; a 404 on a manifest stays an error. Refs #477 Assisted-by: Claude Code
This commit is contained in:
1 parent
0fb4fd70ee
commit
c3a7cef195
2 files changed
+25
-2
No files matched your search
@@ -135,7 +135,13 @@ class Registry:
|
|||||||
def tags(self):
|
def tags(self):
|
||||||
tags, path = [], "tags/list"
|
tags, path = [], "tags/list"
|
||||||
while path:
|
while path:
|
||||||
body, headers = self._get(path)
|
try:
|
||||||
|
body, headers = self._get(path)
|
||||||
|
except RegistryError as exc:
|
||||||
|
# A repository not pushed yet is 404 NAME_UNKNOWN (OCI distribution spec): no tags.
|
||||||
|
if exc.status == 404 and not tags:
|
||||||
|
return []
|
||||||
|
raise
|
||||||
tags += body.get("tags") or []
|
tags += body.get("tags") or []
|
||||||
link = re.search(r"<[^>]*/tags/list(\?[^>]*)>", headers.get("Link", ""))
|
link = re.search(r"<[^>]*/tags/list(\?[^>]*)>", headers.get("Link", ""))
|
||||||
path = f"tags/list{link[1]}" if link else None
|
path = f"tags/list{link[1]}" if link else None
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ class FakeRegistry(http.server.BaseHTTPRequestHandler):
|
|||||||
refuse_token = False
|
refuse_token = False
|
||||||
no_realm = False
|
no_realm = False
|
||||||
empty_token = False
|
empty_token = False
|
||||||
|
unknown = False # the repository does not exist yet
|
||||||
agents = None # a fresh list per test, set in setUp
|
agents = None # a fresh list per test, set in setUp
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
@@ -127,6 +128,9 @@ class FakeRegistry(http.server.BaseHTTPRequestHandler):
|
|||||||
b"{}",
|
b"{}",
|
||||||
extra={"WWW-Authenticate": f'Bearer realm="{realm}",service="reg"'},
|
extra={"WWW-Authenticate": f'Bearer realm="{realm}",service="reg"'},
|
||||||
)
|
)
|
||||||
|
elif self.unknown:
|
||||||
|
body = {"errors": [{"code": "NAME_UNKNOWN", "message": "unknown"}]}
|
||||||
|
self.reply(404, json.dumps(body).encode())
|
||||||
else:
|
else:
|
||||||
self.reply(200, json.dumps({"tags": ["0.1.0"]}).encode())
|
self.reply(200, json.dumps({"tags": ["0.1.0"]}).encode())
|
||||||
|
|
||||||
@@ -150,7 +154,7 @@ class QuietServer(http.server.HTTPServer):
|
|||||||
class RegistryClient(unittest.TestCase):
|
class RegistryClient(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
FakeRegistry.refuse = FakeRegistry.refuse_token = FakeRegistry.no_realm = False
|
FakeRegistry.refuse = FakeRegistry.refuse_token = FakeRegistry.no_realm = False
|
||||||
FakeRegistry.empty_token = False
|
FakeRegistry.empty_token = FakeRegistry.unknown = False
|
||||||
FakeRegistry.agents = []
|
FakeRegistry.agents = []
|
||||||
server = QuietServer(("127.0.0.1", 0), FakeRegistry)
|
server = QuietServer(("127.0.0.1", 0), FakeRegistry)
|
||||||
threading.Thread(target=server.serve_forever, daemon=True).start()
|
threading.Thread(target=server.serve_forever, daemon=True).start()
|
||||||
@@ -165,6 +169,19 @@ class RegistryClient(unittest.TestCase):
|
|||||||
for agent in FakeRegistry.agents:
|
for agent in FakeRegistry.agents:
|
||||||
self.assertTrue(agent.startswith("kamino-"), agent)
|
self.assertTrue(agent.startswith("kamino-"), agent)
|
||||||
|
|
||||||
|
def test_a_repository_not_yet_pushed_has_no_tags(self):
|
||||||
|
FakeRegistry.unknown = True
|
||||||
|
self.assertEqual(self.registry.tags(), [])
|
||||||
|
self.assertEqual(
|
||||||
|
niv.next_version("0.1", self.registry.tags(), "c", no_label), "0.1.0"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_a_missing_manifest_is_still_a_registry_error(self):
|
||||||
|
FakeRegistry.unknown = True
|
||||||
|
with self.assertRaises(niv.RegistryError) as caught:
|
||||||
|
self.registry.label("0.1.0")
|
||||||
|
self.assertIn("404", str(caught.exception))
|
||||||
|
|
||||||
def test_a_refused_request_names_its_status_and_body(self):
|
def test_a_refused_request_names_its_status_and_body(self):
|
||||||
FakeRegistry.refuse = True
|
FakeRegistry.refuse = True
|
||||||
with self.assertRaises(niv.RegistryError) as caught:
|
with self.assertRaises(niv.RegistryError) as caught:
|
||||||
|
|||||||
Reference in new issue
Block a user