From nobody Mon Feb 9 00:07:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612977917; cv=none; d=zohomail.com; s=zohoarc; b=KTr0UK2wMfH/0taJbCfPuwREWCQgnwcItctZ3MmBcxDfWM+UG4p8+7fl0FIiGcA6YkEMlE0gvmjq/1qHxI+HR1krZoNQ58lysIGRdjxmBbC6Wglpy9yZWaId3Jlidnm1uRRTVycuhMXBBVHSDpdtGZkQFc/l6JoAuVgMJRqNVLg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612977917; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fhsnn3ympFRVUvn/QBS9R2O/T2cGyOBk/WJx5EVngA8=; b=aL969BPwGXeHX7Y0wFSoGj/OYHWYnFqMlA6FEthrr1br1kdzD/yma867xcdCfqoiQwWcN69tT35Z27EOQunn3O6xDrP5hcam0KOvMIarSM9fU9na6F8OBf4koxXZwQ2ASUva1Pvn80tPcJqfJzKLyX0lmwUW3C3lFOsq6FB/nKI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612977917312578.8883342651766; Wed, 10 Feb 2021 09:25:17 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-102-iSGxobtoMl2dtNzFJDybkg-1; Wed, 10 Feb 2021 12:25:13 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6A3C3C7401; Wed, 10 Feb 2021 17:25:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E94B4C; Wed, 10 Feb 2021 17:25:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 00BABC841; Wed, 10 Feb 2021 17:25:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11AHOkq9019456 for ; Wed, 10 Feb 2021 12:24:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 422505D9E3; Wed, 10 Feb 2021 17:24:46 +0000 (UTC) Received: from nautilus.redhat.com (unknown [10.40.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E0F05D9DC; Wed, 10 Feb 2021 17:24:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612977916; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=fhsnn3ympFRVUvn/QBS9R2O/T2cGyOBk/WJx5EVngA8=; b=DFlQLs8u0slbTBzsdFYrArbHmenzW+ElKYUaa7JnLsre7l36u5PtJkMt06WnfZbEMwD/Du uClGhr60xQiR1BAR6qad4GLAzEv2TKIXANMie93d+hj8d345/J1x68MyqJWvXhnKMxdtHI YMeARmazsW6h6wh1SGkcqDI7G2G6Hf4= X-MC-Unique: iSGxobtoMl2dtNzFJDybkg-1 From: Erik Skultety To: libvir-list@redhat.com Subject: [libvirt PATCH 4/4] ci: Introduce a new checker script 'check-registry.py' Date: Wed, 10 Feb 2021 18:24:36 +0100 Message-Id: <765ef45d8b45eb6adb54beed9e92273d651b7f9c.1612977855.git.eskultet@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: eskultet@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When removing the dependency on sudo in our CI Makefile, I realized that the list of images that we pull contains some old images that we no longer support in lcitool, but can be still pulled from the registry. This is a simple checker which runs in context of the refresh script which informs the developer/maintainer that there are some old redundant images that should be purged from the registry, so that people don't try to run local builds in those (which will most likely fail anyway). Signed-off-by: Erik Skultety --- ci/containers/check-registry.py | 96 +++++++++++++++++++++++++++++++++ ci/containers/refresh | 5 ++ 2 files changed, 101 insertions(+) create mode 100644 ci/containers/check-registry.py diff --git a/ci/containers/check-registry.py b/ci/containers/check-registry= .py new file mode 100644 index 0000000000..f0159da54d --- /dev/null +++ b/ci/containers/check-registry.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 + +import argparse +import subprocess +import shutil +import sys + +import util + + +def get_image_distro(image_name: str): + name_prefix =3D "ci-" + name_suffix =3D "-cross-" + + distro =3D image_name[len(name_prefix):] + + index =3D distro.find(name_suffix) + if index > 0: + distro =3D distro[:index] + + return distro + + +def get_undesirables(registry_distros_d, hosts_l): + """ Returns a dictionary of 'id':'name' pairs of images that can be pu= rged""" + + undesirables_d =3D {} + for distro in registry_distros_d: + if distro not in hosts_l: + for image in registry_distros_d[distro]: + undesirables_d[str(image["id"])] =3D image["path"] + + return undesirables_d if undesirables_d else None + + +def get_lcitool_hosts(lcitool_path): + """ Returns a list of supported hosts by lcitool + @param lcitool_path: absolute path to local copy of lcitool, if om= itted it is + assumed lcitool is installed in the current environment""" + + if not lcitool_path: + lcitool_path =3D "lcitool" + if not shutil.which(lcitool_path): + sys.exit("error: 'lcitool' not installed") + + lcitool_out =3D subprocess.check_output([lcitool_path, "hosts"]) + return lcitool_out.decode("utf-8").splitlines() + + +def main(): + parser =3D argparse.ArgumentParser() + parser.add_argument("project_id", + help=3D"GitLab project ID") + parser.add_argument("--lcitool_path", + dest=3D"lcitool", + metavar=3D"PATH", + help=3D"absolute path to lcitool, CWD is used if o= mitted") + + args =3D parser.parse_args() + + uri =3D util.get_registry_uri(util.PROJECT_ID) + images_json =3D util.list_images(uri + "?per_page=3D100") + + registry_distros_d =3D {} + for image in images_json: + distro_name =3D get_image_distro(image["name"]) + + try: + registry_distros_d[distro_name].append(image) + except KeyError: + registry_distros_d[distro_name] =3D [image] + + hosts_l =3D get_lcitool_hosts(args.lcitool) + + # print the list of images that we can safely purge from the registry + undesirables_d =3D get_undesirables(registry_distros_d, hosts_l) + if undesirables_d: + undesirable_image_names =3D "\t" + "\n\t".join(undesirables_d.valu= es()) + undesirable_image_ids =3D " ".join(undesirables_d.keys()) + + sys.exit(f""" +The following images can be purged from the registry: + +{undesirable_image_names} + +You can remove the above images over the API with the following code snipp= et: + +\t$ for image_id in {undesirable_image_ids} \\ +\t;do \\ +\t\tcurl --request DELETE --header "PRIVATE-TOKEN: " \\ +\t\t{util.get_registry_uri(util.PROJECT_ID)}/$image_id \\ +\t;done""") + + +if __name__ =3D=3D "__main__": + main() diff --git a/ci/containers/refresh b/ci/containers/refresh index a39d0b0996..9dfaf75300 100755 --- a/ci/containers/refresh +++ b/ci/containers/refresh @@ -40,3 +40,8 @@ do =20 $LCITOOL dockerfile $host libvirt > ci-$host.Dockerfile done + +# Check whether there are some old images in the container registry that c= ould +# be purged - mainly because the list-images script would list them as +# available +/usr/bin/env python3 check-registry.py --lcitool_path "$LCITOOL" 192693 --=20 2.29.2