Much cleaner build script

This commit is contained in:
Greg Hellings
2023-08-10 23:17:15 -05:00
parent f2c43c3cae
commit dc583c41eb
12 changed files with 171 additions and 8 deletions
+4
View File
@@ -12,3 +12,7 @@ distros/fedora-rawhide-*.hcl
distros/centos-8stream-*.hcl
distros/centos-9stream-*.hcl
cellar/centos-9stream-*.hcl
__pycache__
*.pyc
*.pyo
Executable
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env xonsh
from argparse import ArgumentParser
from pathlib import Path
import sys
sys.path.append(str(Path(__file__).parent / "lib"))
from support import Support, BASE
support = Support()
parser = ArgumentParser("Build a box")
parser.add_argument("--distro", "-d", help="Name of the distro/ folder")
parser.add_argument("--version", "-v", help="Version of the distro to build")
parser.add_argument("--build", "-b", help="Name of the target build, e.g. qemu.x86_64, virtualbox-iso.x86_64")
parser.add_argument("--list", "-l", help="List all build targets")
parser.add_argument("--all", "-a", help="Build all applicable targets", action="store_true")
parser.add_argument("--upload", "-u", help="Force doing uploads", action="store_true")
parser.add_argument("--headless", help="Run builds headless", action="store_true")
args = parser.parse_args()
# Now provide menus if we don't have defaults
def process_all():
if args.distro:
process_distro(support.distros[args.distro])
else:
for name, distro in support.distros.items():
process_distro(distro)
def process_distro(distro):
if args.version:
process_builds(distro.builds_for_version(args.version))
else:
process_builds(distro.builds)
def process_builds(builds):
for build in builds:
if args.build:
name, arch = args.build.split(".")
if build.provider.name == name and build.provider.arch == arch:
do_build(build)
else:
do_build(build)
def do_build(build):
if args.upload:
upload = ""
else:
upload = "-except=upload"
if args.headless:
headless = "headless=true"
else:
headless = "headless=false"
echo packer build -var @(headless) @(build.var_file) @(build.only) @(upload) @(BASE / "sources")
if args.all or (args.distro and args.version and args.build):
process_all()
else:
print("Doing menu stuff")
Executable
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
virsh -q vol-list default | awk '{print $1}' | xargs -r -L 1 virsh vol-delete --pool default
sudo virsh -q vol-list default | awk '{print $1}' | xargs -r -L 1 virsh vol-delete --pool default
vagrant box list | awk '{print $1}' | xargs -r -L 1 vagrant box remove
+10
View File
@@ -0,0 +1,10 @@
8:
- arch: x86_64
provider: qemu
- arch: x86_64
provider: virtualbox-iso
9:
- arch: x86_64
provider: qemu
- arch: x86_64
provider: virtualbox-iso
+5
View File
@@ -0,0 +1,5 @@
7:
- arch: x86_64
provider: qemu
- arch: x86_64
provider: virtualbox-iso
+12
View File
@@ -0,0 +1,12 @@
9:
- arch: x86_64
provider: qemu
10:
- arch: x86_64
provider: qemu
11:
- arch: x86_64
provider: qemu
12:
- arch: x86_64
provider: qemu
View File
+22
View File
@@ -0,0 +1,22 @@
from provider import Provider
class Build:
def __init__(self, distro, version, provider: Provider):
self.distro: str = distro
self.version: str = str(version)
self.provider: str = provider
@property
def var_file(self):
return f"-var-file=distros/{self.distro}/{self.version}/{self.provider.arch}.pkrvars.hcl"
@property
def only(self):
return f"-only={self.provider}"
def __str__(self) -> str:
return f"{self.distro} {self.version}: {self.provider}"
def __repr__(self) -> str:
return str(self)
+26
View File
@@ -0,0 +1,26 @@
from provider import Provider
from build import Build
class Distro:
def __init__(self, name: str, support: map):
self.name = name
self.builds = []
for version, matrix in support.items():
for support in matrix:
provider = Provider(support["provider"], support["arch"])
build = Build(self.name, version, provider)
self.builds.append(build)
def __str__(self) -> str:
return f"{self.name}"
def __repr__(self) -> str:
return f"{self.name}: {' '.join(self.versions)}"
@property
def versions(self) -> set[str]:
return set([b.version for b in self.builds])
def builds_for_version(self, version: str) -> set[Build]:
return set(filter(lambda x: x.version == version, self.builds))
+7
View File
@@ -0,0 +1,7 @@
class Provider:
def __init__(self, name, arch):
self.name = name
self.arch = arch
def __str__(self) -> str:
return f"{self.name}.{self.arch}"
+23
View File
@@ -0,0 +1,23 @@
from distro import Distro
from provider import Provider
from pathlib import Path
from yaml import load, Loader
BASE = Path(__file__).parent.parent
class Support:
def __init__(self):
self.base = BASE
self.distros = self.__get_distros()
def __get_distros(self) -> map:
distros = {}
distros_dir = self.base / "distros"
for f in distros_dir.glob("**/supports.yml"):
name = f.parent.name
with open(f, "r") as fp:
support_yml = load(fp, Loader=Loader)
distros[name] = Distro(name, support_yml)
return distros
-8
View File
@@ -24,14 +24,6 @@ def get_providers():
return providers
def get_builds():
"List of builds as supported in distros/"
base = pathlib.Path(__file__)
distros = base.parent / "distros"
builds = [str(p.stem).rsplit(".", 1)[0] for p in distros.glob("**/*.pkrvars.hcl")]
return builds
def get_parser(args, unsupported=set()):
parser = argparse.ArgumentParser("Builder")
parser.add_argument("--headless", action="store_true")