diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-07-02 19:45:53 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-07-02 19:45:53 +0300 |
commit | 81486b3d6f7e1ed35dbf669bd20b1f46afc30163 (patch) | |
tree | 259f18f20bdfeba821b1db8b678ce8c73034e2c3 | |
parent | 22150a8ad50f53b5818bc3656d477ae5f95f3032 (diff) | |
download | ambient-ci-81486b3d6f7e1ed35dbf669bd20b1f46afc30163.tar.gz |
fix: make cache drive have a maximum size
It's currently hardcoded but we can live with that for now.
Sponsored-by: author
-rwxr-xr-x | ambient-run | 29 | ||||
-rwxr-xr-x | test-project/.ambient-script | 1 |
2 files changed, 24 insertions, 6 deletions
diff --git a/ambient-run b/ambient-run index a691b49..1cbc1c2 100755 --- a/ambient-run +++ b/ambient-run @@ -10,6 +10,7 @@ import tarfile import tempfile +MAX_CACHE_SIZE = 1024**3 OVMF_FD = "/usr/share/ovmf/OVMF.fd" OVMF_VARS = "/usr/share/OVMF/OVMF_VARS.fd" @@ -94,16 +95,25 @@ def main(): ["qemu-img", "create", "-q", "-f", "raw", output_drive, "1G"], check=True ) + 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: - cache_drive = os.path.join(tmp, "cache.tar") + tar.close() else: - cache_drive = args.cache - logging.info(f"using {cache_drive} as cache drive") - if not os.path.exists(cache_drive): - logging.info(f"creating empty tar archive as {cache_drive}") - tar = tarfile.open(name=cache_drive, mode="w:") + # Tar up the cache directory. + tar.add(args.cache, arcname=".") tar.close() + # Make the tar the max size. + length = os.path.getsize(cache_drive) + if length < MAX_CACHE_SIZE: + os.truncate(cache_drive, MAX_CACHE_SIZE) + else: + logging.info( + "cache drive {cache_drive} is larger than max allowed, oh well" + ) + if args.dependencies is None: deps_drive = os.path.join(tmp, "deps.tar") tar = tarfile.open(name=deps_drive, mode="w:") @@ -150,6 +160,13 @@ def main(): logging.info("extract artifacts, if any") extract_tar_from_tar(output_drive, args.artifact) + if args.cache is not None: + logging.info(f"extract potentially updated cache from {cache_drive}") + subprocess.run( + ["tar", "-xf", cache_drive, "-C", args.cache], + check=True, + ) + logging.info("Build finished") except Exception as e: sys.stderr.write(f"{e}\n") diff --git a/test-project/.ambient-script b/test-project/.ambient-script index d80fa2a..d226b2f 100755 --- a/test-project/.ambient-script +++ b/test-project/.ambient-script @@ -11,6 +11,7 @@ ls -l /workspace output="$1" echo this is an output file >output.txt +date >>../cache/cache.data echo "produce output tar" tar -cf "$output" . |