summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-07-30 17:23:56 +0300
committerLars Wirzenius <liw@liw.fi>2023-07-30 17:33:59 +0300
commit5f510908cb44197d9208a8cb62d866e3e12ff412 (patch)
tree76475af71639211c8c46a814f12bc7cd0211a94d
parent81f4b5698c919bea00de8969239a9ad2e837e9dd (diff)
downloadambient-ci-5f510908cb44197d9208a8cb62d866e3e12ff412.tar.gz
feat: get build specification from YAML file instead of command line
Sponsored-by: author
-rwxr-xr-xambient-run58
1 files changed, 41 insertions, 17 deletions
diff --git a/ambient-run b/ambient-run
index bd277f9..751fb23 100755
--- a/ambient-run
+++ b/ambient-run
@@ -8,6 +8,7 @@ import subprocess
import sys
import tarfile
import tempfile
+import yaml
MAX_CACHE_SIZE = 1024**3
@@ -15,15 +16,34 @@ OVMF_FD = "/usr/share/ovmf/OVMF.fd"
OVMF_VARS = "/usr/share/OVMF/OVMF_VARS.fd"
+class BuildSpec:
+ def __init__(self, filename):
+ with open(filename) as f:
+ o = yaml.safe_load(f)
+ self.image = os.path.expanduser(o["image"])
+ self.src = os.path.expanduser(o.get("src", "."))
+
+ if "cache" in o:
+ self.cache = os.path.expanduser(o["cache"])
+ else:
+ self.cache = None
+
+ if "dependencies" in o:
+ self.dependencies = os.path.expanduser(o["dependencies"])
+ else:
+ self.dependencies = None
+
+ if "artifact" in o:
+ self.artifact = os.path.expanduser(o["artifact"])
+ else:
+ self.artifact = None
+
+
def parse_args():
p = argparse.ArgumentParser()
p.add_argument("--verbose", action="store_true")
- p.add_argument("--image", required=True)
p.add_argument("--log", required=True)
- p.add_argument("--artifact")
- p.add_argument("--cache")
- p.add_argument("--dependencies")
- p.add_argument("source_tree")
+ p.add_argument("build_spec")
return p.parse_args()
@@ -73,6 +93,10 @@ def main():
logging.debug(f"args: {args}")
try:
+ logging.debug(f"loading build spec from {args.build_spec}")
+ build = BuildSpec(args.build_spec)
+ logging.debug(f"build: {build}")
+
tmp = tempfile.mkdtemp()
logging.debug(f"created {tmp}")
@@ -81,14 +105,14 @@ def main():
src_tar = os.path.join(tmp, "src.tar")
vars = os.path.join(tmp, "vars.fd")
- logging.info(f"copying {args.image} to {image}")
- shutil.copyfile(args.image, image)
+ logging.info(f"copying {build.image} to {image}")
+ shutil.copyfile(build.image, image)
logging.info(f"copying {OVMF_VARS}")
shutil.copyfile(OVMF_FD, vars)
- logging.info(f"create tar of source tree {args.source_tree}")
- subprocess.run(["tar", "-cf", src_tar, "-C", args.source_tree, "."], check=True)
+ logging.info(f"create tar of source tree {build.src}")
+ subprocess.run(["tar", "-cf", src_tar, "-C", build.src, "."], check=True)
logging.info(f"create output drive {output_drive}")
subprocess.run(
@@ -98,11 +122,11 @@ def main():
cache_drive = os.path.join(tmp, "cache.tar")
logging.info(f"using {cache_drive} as cache drive")
tar = tarfile.open(name=cache_drive, mode="w:")
- if args.cache is None:
+ if build.cache is None:
tar.close()
else:
# Tar up the cache directory.
- tar.add(args.cache, arcname=".")
+ tar.add(build.cache, arcname=".")
tar.close()
# Make the tar the max size.
@@ -117,11 +141,11 @@ def main():
deps_drive = os.path.join(tmp, "deps.tar")
logging.info(f"using {deps_drive} as the dependencies drive")
tar = tarfile.open(name=deps_drive, mode="w:")
- if args.dependencies is None:
+ if build.dependencies is None:
tar.close()
else:
# Tar up the dependencies directory.
- tar.add(args.dependencies, arcname=".")
+ tar.add(build.dependencies, arcname=".")
tar.close()
logging.info("run build in VM")
@@ -160,14 +184,14 @@ def main():
sys.stderr.write(p.stderr.decode())
raise Exception("qemu-system failed")
- if args.artifact is not None:
+ if build.artifact is not None:
logging.info("extract artifacts, if any")
- extract_tar_from_tar(output_drive, args.artifact)
+ extract_tar_from_tar(output_drive, build.artifact)
- if args.cache is not None:
+ if build.cache is not None:
logging.info(f"extract potentially updated cache from {cache_drive}")
subprocess.run(
- ["tar", "-xf", cache_drive, "-C", args.cache],
+ ["tar", "-xf", cache_drive, "-C", build.cache],
check=True,
)