[libvirt PATCH 7/7] ci: remove obsolete logic for refreshing containers/cirrus

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We now use lcitool's manifest feature to generate files. The logic
for checking for stale containers in the registry, however, is still
relevant so that is propagated to a standalone command.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 ci/helper  | 121 ++++-------------------------------------------------
 ci/util.py |  32 +++++++-------
 2 files changed, 23 insertions(+), 130 deletions(-)

diff --git a/ci/helper b/ci/helper
index 441258f511..8b8d0f68cb 100755
--- a/ci/helper
+++ b/ci/helper
@@ -7,7 +7,6 @@ import argparse
 import os
 import pathlib
 import pty
-import shutil
 import subprocess
 import sys
 import textwrap
@@ -60,15 +59,6 @@ class Parser:
             help="additional arguments passed to ninja",
         )
 
-        # Options that are common to all actions that use lcitool
-        lcitoolparser = argparse.ArgumentParser(add_help=False)
-        lcitoolparser.add_argument(
-            "--lcitool",
-            metavar="PATH",
-            default="lcitool",
-            help="path to lcitool binary",
-        )
-
         # Options that are common to actions communicating with a GitLab
         # instance
         gitlabparser = argparse.ArgumentParser(add_help=False)
@@ -127,27 +117,14 @@ class Parser:
         )
         listimagesparser.set_defaults(func=Application._action_list_images)
 
-        # refresh action
-        refreshparser = subparsers.add_parser(
-            "refresh",
-            help="refresh data generated with lcitool",
-            parents=[lcitoolparser, gitlabparser],
+        # check_stale action
+        check_staleparser = subparsers.add_parser(
+            "check-stale",
+            help="check for existence of stale images on the GitLab instance",
+            parents=[gitlabparser],
             formatter_class=argparse.ArgumentDefaultsHelpFormatter,
         )
-        refreshparser.add_argument(
-            "--quiet",
-            action="store_true",
-            default=False,
-            help="refresh data silently"
-        )
-        refreshparser.add_argument(
-            "--check-stale",
-            action="store",
-            choices=["yes", "no"],
-            default="yes",
-            help="check for existence of stale images on the GitLab instance"
-        )
-        refreshparser.set_defaults(func=Application._action_refresh)
+        check_staleparser.set_defaults(func=Application._action_check_stale)
 
     def parse(self):
         return self._parser.parse_args()
@@ -158,10 +135,6 @@ class Application:
         self._basedir = pathlib.Path(__file__).resolve().parent
         self._args = Parser().parse()
 
-        if self._args.action == "refresh":
-            if not shutil.which(self._args.lcitool):
-                sys.exit("error: 'lcitool' not installed")
-
     def _make_run(self, target):
         args = [
             "-C",
@@ -194,84 +167,12 @@ class Application:
         output = self._lcitool_run(["targets"])
         return output.splitlines()
 
-    def _generate_dockerfile(self, target, cross=None):
-        args = ["dockerfile", target, "libvirt"]
-        outdir = self._basedir.joinpath("containers")
-        outfile = f"{target}.Dockerfile"
-
-        if cross:
-            args.extend(["--cross", cross])
-            outfile = f"{target}-cross-{cross}.Dockerfile"
-
-        outpath = outdir.joinpath(outfile)
-        if not self._args.quiet:
-            print(outpath)
-
-        output = self._lcitool_run(args)
-        with open(outpath, "w") as f:
-            f.write(output)
-
-    def _generate_vars(self, target):
-        args = ["variables", target, "libvirt"]
-        outdir = self._basedir.joinpath("cirrus")
-        outfile = f"{target}.vars"
-
-        outpath = outdir.joinpath(outfile)
-        if not self._args.quiet:
-            print(outpath)
-
-        output = self._lcitool_run(args)
-        with open(outpath, "w") as f:
-            f.write(output)
-
-    def _refresh_containers(self):
-        debian_cross = [
-            "aarch64",
-            "armv6l",
-            "armv7l",
-            "i686",
-            "mips",
-            "mips64el",
-            "mipsel",
-            "ppc64le",
-            "s390x",
-        ]
-        fedora_cross = [
-            "mingw32",
-            "mingw64",
-        ]
-
-        for target in self._lcitool_get_targets():
-            if target.startswith("freebsd-") or target.startswith("macos-"):
-                continue
-
-            self._generate_dockerfile(target)
-
-            if target == "fedora-rawhide":
-                for cross in fedora_cross:
-                    self._generate_dockerfile(target, cross)
-
-            if target.startswith("debian-"):
-                for cross in debian_cross:
-                    if target == "debian-sid" and cross == "mips":
-                        continue
-                    self._generate_dockerfile(target, cross)
-
-    def _refresh_cirrus(self):
-        for target in self._lcitool_get_targets():
-            if not (target.startswith("freebsd-") or target.startswith("macos-")):
-                continue
-
-            self._generate_vars(target)
-
     def _check_stale_images(self):
         namespace = self._args.namespace
         gitlab_uri = self._args.gitlab_uri
         registry_uri = util.get_registry_uri(namespace, gitlab_uri)
-        lcitool_targets = self._lcitool_get_targets()
 
-        stale_images = util.get_registry_stale_images(registry_uri,
-                                                      lcitool_targets)
+        stale_images = util.get_registry_stale_images(registry_uri, self._basedir)
         if stale_images:
             spacing = "\n" + 4 * " "
             stale_fmt = [f"{k} (ID: {v})" for k, v in stale_images.items()]
@@ -328,12 +229,8 @@ class Application:
             print("Available cross-compiler container images:\n")
             print(spacing + ("\n" + spacing).join(cross))
 
-    def _action_refresh(self):
-        self._refresh_containers()
-        self._refresh_cirrus()
-
-        if self._args.check_stale == "yes" and not self._args.quiet:
-            self._check_stale_images()
+    def _action_check_stale(self):
+        self._check_stale_images()
 
     def run(self):
         self._args.func(self)
diff --git a/ci/util.py b/ci/util.py
index 90d58454be..d8be6631eb 100644
--- a/ci/util.py
+++ b/ci/util.py
@@ -1,4 +1,5 @@
 import json
+import pathlib
 import urllib.request
 import urllib.parse
 
@@ -40,42 +41,37 @@ def get_registry_images(uri: str) -> List[Dict]:
     return json.loads(r.read().decode())
 
 
-def get_image_distro(image_name: str) -> str:
+def get_dockerfiles(base_dir) -> List:
     """
-    Extract the name of the distro in the GitLab image registry name, e.g.
-        ci-debian-9-cross-mipsel --> debian-9
+    List all container dockerfiles in the local directory.
 
-    :param image_name: name of the GitLab registry image
-    :return: distro name as a string
+    :return: list of dockerfile names
     """
-    name_prefix = "ci-"
-    name_suffix = "-cross-"
 
-    distro = image_name[len(name_prefix):]
+    dkrs = []
+    d = pathlib.Path(base_dir, "containers")
+    for f in d.iterdir():
+        if f.suffix == ".Dockerfile":
+            dkrs.append(f.stem)
+    return dkrs
 
-    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]:
+def get_registry_stale_images(registry_uri: str, base_dir: 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
+    :param base_dir: local repository base directory
     :return: dictionary formatted as: {<gitlab_image_name>: <gitlab_image_id>}
     """
 
+    dockerfiles = get_dockerfiles(base_dir)
     images = get_registry_images(registry_uri)
 
     stale_images = {}
     for img in images:
-        if get_image_distro(img["name"]) not in supported_distros:
+        if img["name"][3:] not in dockerfiles:
             stale_images[img["name"]] = img["id"]
 
     return stale_images
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux