mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
ci: util: Add a registry checker for stale images
This function checks whether there are any stale Docker images in the registry that can be purged. Since we're pulling available container images from our GitLab registry with the 'list-images' action, it could happen that we'd list old (already unsupported) images and make them available for the user to consume and run a build in them. Naturally, the build will most likely fail leaving the user confused. Signed-off-by: Erik Skultety <eskultet@redhat.com> Reviewed-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
41
ci/util.py
41
ci/util.py
@@ -38,3 +38,44 @@ def get_registry_images(uri: str) -> List[Dict]:
|
||||
|
||||
# read the HTTP response and load the JSON part of it
|
||||
return json.loads(r.read().decode())
|
||||
|
||||
|
||||
def get_image_distro(image_name: str) -> str:
|
||||
"""
|
||||
Extract the name of the distro in the GitLab image registry name, e.g.
|
||||
ci-debian-9-cross-mipsel --> debian-9
|
||||
|
||||
:param image_name: name of the GitLab registry image
|
||||
:return: distro name as a string
|
||||
"""
|
||||
name_prefix = "ci-"
|
||||
name_suffix = "-cross-"
|
||||
|
||||
distro = image_name[len(name_prefix):]
|
||||
|
||||
index = distro.find(name_suffix)
|
||||
if index > 0:
|
||||
distro = distro[:index]
|
||||
|
||||
return distro
|
||||
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user