
...
+def get_registry_stale_images(registry_uri: str, + supported_distros: List[str]) -> Dict[str, int]: + """ + Check the GitLab image registry for images that we no longer support and + which should be deleted. + + :param uri: URI pointing to a GitLab instance's image registry + :param supported_distros: list of hosts supported by lcitool + :return: dictionary formatted as: {<gitlab_image_name>: <gitlab_image_id>} + """ + + images = get_registry_images(registry_uri) + + # extract distro names from the list of registry images + registry_distros = [get_image_distro(i["name"]) for i in images] + + # - compare the distros powering the images in GitLab registry with + # the list of host available from lcitool + # - @unsupported is a set containing the distro names which we no longer + # support; we need to map these back to registry image names + unsupported = set(registry_distros) - set(supported_distros) + if unsupported: + stale_images = {} + for distro in unsupported: + for img in images: + # gitlab images are named like "ci-<distro>-<cross_arch>?" + if distro in img["name"]: + stale_images[img["name"]] = img["id"] + + return stale_images
As far as I can tell, this can be achieved in a much more straightforward way with
def get_registry_stale_images(registry_uri, supported_distros):
images = get_registry_images(registry_uri) stale_images = {}
for img in images: if get_image_distro(img["name"]) not in supported_distros: stale_images[img["name"]] = img["id"]
return stale_images
At least from a quick test, the results appear to be the same. Am I missing something?
No, it works. I'll respin. Erik