]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ci: Implement 'shell' helper action
authorAndrea Bolognani <abologna@redhat.com>
Fri, 12 Mar 2021 16:55:08 +0000 (17:55 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Mon, 15 Mar 2021 17:49:03 +0000 (18:49 +0100)
This simply calls the underlying Makefile target, but allows
additional arguments to be specified in a more convenient and
discoverable way.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
ci/helper

index 578920c380a86a85c17e6da8c224afae4f4c9942..1d20afd4a2a6c6e682173608130771cd303467c0 100755 (executable)
--- a/ci/helper
+++ b/ci/helper
@@ -4,6 +4,7 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
 import argparse
+import os
 import pathlib
 import pty
 import shutil
@@ -13,6 +14,34 @@ import sys
 
 class Parser:
     def __init__(self):
+        # Options that are common to all actions that use containers
+        containerparser = argparse.ArgumentParser(add_help=False)
+        containerparser.add_argument(
+            "target",
+            help="perform action on target OS",
+        )
+        containerparser.add_argument(
+            "--engine",
+            choices=["auto", "podman", "docker"],
+            default="auto",
+            help="container engine to use",
+        )
+        containerparser.add_argument(
+            "--login",
+            default=os.getlogin(),  # exempt from syntax-check
+            help="login to use inside the container",
+        )
+        containerparser.add_argument(
+            "--image-prefix",
+            default="registry.gitlab.com/libvirt/libvirt/ci-",
+            help="use container images from non-default location",
+        )
+        containerparser.add_argument(
+            "--image-tag",
+            default=":latest",
+            help="use container images with non-default tags",
+        )
+
         # Options that are common to all actions that use lcitool
         lcitoolparser = argparse.ArgumentParser(add_help=False)
         lcitoolparser.add_argument(
@@ -30,6 +59,14 @@ class Parser:
         )
         subparsers.required = True
 
+        # shell action
+        shellparser = subparsers.add_parser(
+            "shell",
+            help="start a shell in a container",
+            parents=[containerparser],
+        )
+        shellparser.set_defaults(func=Application.action_shell)
+
         # list-images action
         listimagesparser = subparsers.add_parser(
             "list-images",
@@ -65,6 +102,14 @@ class Application:
             target,
         ]
 
+        if self.args.action == "shell":
+            args.extend([
+                f"CI_ENGINE={self.args.engine}",
+                f"CI_USER_LOGIN={self.args.login}",
+                f"CI_IMAGE_PREFIX={self.args.image_prefix}",
+                f"CI_IMAGE_TAG={self.args.image_tag}",
+            ])
+
         if pty.spawn(["make"] + args) != 0:
             sys.exit("error: 'make' failed")
 
@@ -144,6 +189,9 @@ class Application:
 
             self.generate_vars(host)
 
+    def action_shell(self):
+        self.make_run(f"ci-shell@{self.args.target}")
+
     def action_list_images(self):
         self.make_run(f"ci-list-images")