summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-07-02 16:46:32 +0000
committerLars Wirzenius <liw@liw.fi>2023-07-02 16:46:32 +0000
commita8d3758b6faa685efc81e3e5446392494a532951 (patch)
tree259f18f20bdfeba821b1db8b678ce8c73034e2c3
parent22150a8ad50f53b5818bc3656d477ae5f95f3032 (diff)
parent81486b3d6f7e1ed35dbf669bd20b1f46afc30163 (diff)
downloadambient-ci-a8d3758b6faa685efc81e3e5446392494a532951.tar.gz
Merge branch 'liw/cache-max' into 'main'
fix: make cache drive have a maximum size See merge request larswirzenius/ambient-ci!20
-rwxr-xr-xambient-run29
-rwxr-xr-xtest-project/.ambient-script1
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" .