ci: Implement 'shell' helper action

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>
This commit is contained in:
Andrea Bolognani 2021-03-12 17:55:08 +01:00
parent 2481ad1125
commit 897974c0b3

View File

@ -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")