File size: 1,248 Bytes
59b4e16 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #!/usr/bin/env python3
"""Materialize Harbor task and SIF-cache views from this release."""
import argparse
import json
import os
import subprocess
import tempfile
from pathlib import Path
parser = argparse.ArgumentParser()
parser.add_argument("--release", type=Path, default=Path(__file__).resolve().parents[1])
parser.add_argument("--runtime-root", type=Path, required=True)
args = parser.parse_args()
release = args.release.resolve()
runtime = args.runtime_root.resolve()
if runtime.exists():
raise SystemExit(f"refusing to overwrite {runtime}")
runtime.parent.mkdir(parents=True, exist_ok=True)
with tempfile.TemporaryDirectory(prefix="harbor-runtime-", dir=runtime.parent) as temporary:
stage = Path(temporary) / "runtime"
stage.mkdir()
subprocess.run(
["tar", "--use-compress-program=zstd", "-xf", str(release / "tasks.tar.zst"), "-C", str(stage)],
check=True,
)
sif_cache = stage / "sif-cache"
sif_cache.mkdir()
for line in (release / "manifests" / "task-sif-routing.jsonl").read_text().splitlines():
row = json.loads(line)
(sif_cache / f"{row['task_id']}.sif").symlink_to(release / row["sif_image"])
os.replace(stage, runtime)
print(f"materialized runtime at {runtime}")
|