Files
vms/build.xsh
T

94 lines
3.3 KiB
Plaintext
Raw Normal View History

2023-08-10 23:17:15 -05:00
#!/usr/bin/env xonsh
from pathlib import Path
import sys
2023-12-29 23:49:26 -06:00
sys.path.insert(0, str(Path(__file__).parent / "lib"))
2023-08-10 23:17:15 -05:00
from support import Support, BASE
2023-08-12 17:28:31 -05:00
import time
2023-12-06 08:21:32 -08:00
import json
2023-08-10 23:17:15 -05:00
2023-12-18 02:04:17 +00:00
from argparse import ArgumentParser
from functools import reduce
from yaml import dump, Dumper, load, Loader
2023-08-23 16:26:13 -05:00
source test.xsh
2023-08-10 23:17:15 -05:00
2023-08-15 11:23:29 -05:00
year, month, day, hour, minute, second, wday, jday, dst = time.localtime()
STAMP = f"build={year}.{month}.{day}.{hour}"
2023-08-10 23:17:15 -05:00
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")
2023-11-27 21:00:35 -06:00
parser.add_argument("--build", "-b", help="Name of the target build, e.g. qemu.amd64, virtualbox-iso.amd64")
2023-11-27 10:03:21 -06:00
parser.add_argument("--list", "-l", help="List all build targets", action="store_true")
2023-08-10 23:17:15 -05:00
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")
2023-08-15 11:23:29 -05:00
parser.add_argument("--stamp", "-s", help="Time stamp for builds", default=STAMP)
2023-08-10 23:17:15 -05:00
args = parser.parse_args()
2023-08-12 17:28:31 -05:00
2023-12-06 08:21:32 -08:00
my_list = []
2023-08-10 23:17:15 -05:00
# 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):
2024-04-04 13:33:31 -05:00
for build in builds:
if args.build:
name, arch = args.build.split(".")
if build.provider.name == name and build.provider.arch == arch:
2023-08-10 23:17:15 -05:00
do_build(build)
2024-04-04 13:33:31 -05:00
else:
do_build(build)
2023-08-10 23:17:15 -05:00
def do_build(build):
if args.headless:
headless = "headless=true"
else:
headless = "headless=false"
2023-08-12 17:28:31 -05:00
2023-11-27 10:03:21 -06:00
if args.list:
2023-12-06 08:21:32 -08:00
my_list.append(build)
2023-08-12 17:28:31 -05:00
else:
2023-11-27 10:03:21 -06:00
if args.upload:
if "VAGRANT_CLOUD_TOKEN" not in ${...}:
print("You need to set your cloud token")
sys.exit(1)
packer build -var @(headless) -var @(args.stamp) @(build.var_file) @(build.only) @(BASE / "sources")
2023-08-23 16:26:13 -05:00
else:
2023-11-27 10:03:21 -06:00
upload = "-except=upload"
# Skip building file if we already have built it
output = Path(__file__).parent / "output" / get_vagrant_provider(build.provider.name) / f"{build.distro}-{build.version}-{build.provider.arch}.box"
if output.exists():
print(f"Skipping {build} as box already exists")
else:
packer build -var @(headless) -var @(args.stamp) @(build.var_file) @(build.only) -except=upload @(BASE / "sources")
2023-08-10 23:17:15 -05:00
2023-11-27 10:03:21 -06:00
if args.all or args.list or (args.distro and args.version and args.build):
2023-08-10 23:17:15 -05:00
process_all()
2023-12-06 08:21:32 -08:00
if args.list:
2023-12-18 02:04:17 +00:00
with open(".gitlab-ci-build.yml.in", "r") as fp:
y = load(fp, Loader=Loader)
for item in my_list:
2024-04-11 13:32:56 -05:00
print(item)
2023-12-18 02:04:17 +00:00
if item.is_github:
y[ item.only[6:] ]["parallel"]["matrix"].append({"distro": item.var_path})
with open(".gitlab-ci-build.yml", "w") as fp:
dump(y, fp, Dumper=Dumper)
2023-08-10 23:17:15 -05:00
else:
print("Doing menu stuff")