mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
ci: helper: Rewrite image listing to Python
The corresponding Bash script is dropped. After this patch's rewrite, the Makefile's original image listing target remains intact only to notify the user to use the Python helper instead. Signed-off-by: Erik Skultety <eskultet@redhat.com> Reviewed-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
parent
5a0e4d79cc
commit
c5f9617b1c
12
ci/Makefile
12
ci/Makefile
@ -211,17 +211,6 @@ ci-build@%:
|
||||
ci-test@%:
|
||||
$(MAKE) -C $(CI_ROOTDIR) ci-build@$* CI_NINJA_ARGS=test
|
||||
|
||||
ci-list-images:
|
||||
@echo
|
||||
@echo "Available x86 container images:"
|
||||
@echo
|
||||
@sh list-images.sh "$(CI_IMAGE_PREFIX)" | grep -v cross
|
||||
@echo
|
||||
@echo "Available cross-compiler container images:"
|
||||
@echo
|
||||
@sh list-images.sh "$(CI_IMAGE_PREFIX)" | grep cross
|
||||
@echo
|
||||
|
||||
ci-help:
|
||||
@echo
|
||||
@echo
|
||||
@ -241,7 +230,6 @@ ci-help:
|
||||
@echo " ci-build@\$$IMAGE - run a default 'ninja' build"
|
||||
@echo " ci-test@\$$IMAGE - run a 'ninja test'"
|
||||
@echo " ci-shell@\$$IMAGE - run an interactive shell"
|
||||
@echo " ci-list-images - list available images"
|
||||
@echo " ci-help - show this help message"
|
||||
@echo
|
||||
@echo "Available make variables:"
|
||||
|
38
ci/helper
38
ci/helper
@ -11,6 +11,8 @@ import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import util
|
||||
|
||||
|
||||
class Parser:
|
||||
def __init__(self):
|
||||
@ -66,6 +68,20 @@ class Parser:
|
||||
help="path to lcitool binary",
|
||||
)
|
||||
|
||||
# Options that are common to actions communicating with a GitLab
|
||||
# instance
|
||||
gitlabparser = argparse.ArgumentParser(add_help=False)
|
||||
gitlabparser.add_argument(
|
||||
"--namespace",
|
||||
default="libvirt/libvirt",
|
||||
help="GitLab project namespace"
|
||||
)
|
||||
gitlabparser.add_argument(
|
||||
"--gitlab-uri",
|
||||
default="https://gitlab.com",
|
||||
help="base GitLab URI"
|
||||
)
|
||||
|
||||
# Main parser
|
||||
self.parser = argparse.ArgumentParser()
|
||||
subparsers = self.parser.add_subparsers(
|
||||
@ -105,6 +121,7 @@ class Parser:
|
||||
listimagesparser = subparsers.add_parser(
|
||||
"list-images",
|
||||
help="list known container images",
|
||||
parents=[gitlabparser],
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
)
|
||||
listimagesparser.set_defaults(func=Application.action_list_images)
|
||||
@ -249,7 +266,26 @@ class Application:
|
||||
self.make_run(f"ci-shell@{self.args.target}")
|
||||
|
||||
def action_list_images(self):
|
||||
self.make_run(f"ci-list-images")
|
||||
registry_uri = util.get_registry_uri(self.args.namespace,
|
||||
self.args.gitlab_uri)
|
||||
images = util.get_registry_images(registry_uri)
|
||||
|
||||
# skip the "ci-" prefix each of our container images' name has
|
||||
name_prefix = "ci-"
|
||||
names = [i["name"][len(name_prefix):] for i in images]
|
||||
names.sort()
|
||||
|
||||
native = [name for name in names if "-cross-" not in name]
|
||||
cross = [name for name in names if "-cross-" in name]
|
||||
|
||||
spacing = 4 * " "
|
||||
print("Available x86 container images:\n")
|
||||
print(spacing + ("\n" + spacing).join(native))
|
||||
|
||||
if cross:
|
||||
print()
|
||||
print("Available cross-compiler container images:\n")
|
||||
print(spacing + ("\n" + spacing).join(cross))
|
||||
|
||||
def action_refresh(self):
|
||||
self.refresh_containers()
|
||||
|
@ -1,14 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
prefix="${1##registry.gitlab.com/}"
|
||||
|
||||
PROJECT_ID=192693
|
||||
|
||||
all_repos() {
|
||||
curl -s "https://gitlab.com/api/v4/projects/$PROJECT_ID/registry/repositories?per_page=100" \
|
||||
| tr , '\n' | grep '"path":' | sed 's,"path":",,g;s,"$,,g'
|
||||
}
|
||||
|
||||
all_repos | grep "^$prefix" | sed "s,^$prefix,,g" | while read repo; do
|
||||
echo " $repo"
|
||||
done | sort -u
|
Loading…
x
Reference in New Issue
Block a user