|
24 | 24 |
|
25 | 25 |
|
26 | 26 | CACHE_SCHEMA_VERSION = 3 |
27 | | -DEFAULT_PREBUILT_INFO_PATH = "/opt/fastvideo-kernel-build-info.json" |
| 27 | +DEFAULT_PREBUILT_INFO_PATH = "/opt/fastvideo-kernel-prebuilt" |
28 | 28 | KERNEL_RELATIVE_DIR = "fastvideo-kernel" |
| 29 | +DEFAULT_BUILD_INFO_OUTPUT = "/opt/fastvideo-kernel-prebuilt/default/metadata.json" |
29 | 30 | METADATA_FILE = "metadata.json" |
30 | 31 | EXPECTED_DISTRIBUTION = "fastvideo-kernel" |
31 | 32 |
|
@@ -372,26 +373,35 @@ def _cache_entry_wheel(cache_entry: Path, cache_key: str) -> tuple[Path | None, |
372 | 373 | return _validated_payload_wheel(metadata, wheel, cache_key) |
373 | 374 |
|
374 | 375 |
|
| 376 | +def _prebuilt_metadata_paths(prebuilt_info_path: Path) -> list[Path]: |
| 377 | + if prebuilt_info_path.is_dir() and not prebuilt_info_path.is_symlink(): |
| 378 | + return sorted(prebuilt_info_path.glob(f"*/{METADATA_FILE}")) |
| 379 | + if prebuilt_info_path.exists() or prebuilt_info_path.is_symlink(): |
| 380 | + return [prebuilt_info_path] |
| 381 | + return [] |
| 382 | + |
| 383 | + |
375 | 384 | def _try_install_prebuilt(metadata: dict[str, object], prebuilt_info_path: Path) -> bool: |
376 | 385 | cache_key = str(metadata["cache_key"]) |
377 | | - if not prebuilt_info_path.exists(): |
378 | | - return False |
379 | | - prebuilt, reason = _load_metadata(prebuilt_info_path) |
380 | | - if prebuilt is None: |
381 | | - _log(f"Docker-prebuilt kernel metadata is invalid at {prebuilt_info_path}: {reason}") |
382 | | - return False |
383 | | - wheel_path = Path(str(prebuilt.get("wheel_path", ""))) |
384 | | - wheel, reason = _validated_payload_wheel(prebuilt, wheel_path, cache_key) |
385 | | - if wheel is None: |
386 | | - _log(f"Docker-prebuilt kernel artifact rejected at {prebuilt_info_path}: {reason}") |
387 | | - return False |
388 | | - try: |
389 | | - _log(f"using Docker-prebuilt kernel wheel for cache key {cache_key}") |
390 | | - _install_wheel(wheel) |
391 | | - except (FileNotFoundError, OSError, subprocess.CalledProcessError) as error: |
392 | | - _log(f"Docker-prebuilt kernel installation failed: {error}; falling back") |
393 | | - return False |
394 | | - return True |
| 386 | + for metadata_path in _prebuilt_metadata_paths(prebuilt_info_path): |
| 387 | + prebuilt, reason = _load_metadata(metadata_path) |
| 388 | + if prebuilt is None: |
| 389 | + _log(f"Docker-prebuilt kernel metadata is invalid at {metadata_path}: {reason}") |
| 390 | + continue |
| 391 | + wheel_path = Path(str(prebuilt.get("wheel_path", ""))) |
| 392 | + wheel, reason = _validated_payload_wheel(prebuilt, wheel_path, cache_key) |
| 393 | + if wheel is None: |
| 394 | + _log(f"Docker-prebuilt kernel artifact rejected at {metadata_path}: {reason}") |
| 395 | + continue |
| 396 | + try: |
| 397 | + _log(f"Docker-prebuilt cache hit for key {cache_key}: {wheel}") |
| 398 | + _install_wheel(wheel) |
| 399 | + except (FileNotFoundError, OSError, subprocess.CalledProcessError) as error: |
| 400 | + _log(f"Docker-prebuilt kernel installation failed: {error}; falling back") |
| 401 | + return False |
| 402 | + return True |
| 403 | + _log(f"Docker-prebuilt cache miss for key {cache_key}") |
| 404 | + return False |
395 | 405 |
|
396 | 406 |
|
397 | 407 | def _store_cache_entry(cache_root: Path, metadata: dict[str, object], wheel: Path) -> Path: |
@@ -535,7 +545,7 @@ def parse_args() -> argparse.Namespace: |
535 | 545 | parser.add_argument("--prebuilt-info-path", |
536 | 546 | default=os.environ.get("FASTVIDEO_KERNEL_PREBUILT_INFO", DEFAULT_PREBUILT_INFO_PATH)) |
537 | 547 | parser.add_argument("--wheel-dir", default="") |
538 | | - parser.add_argument("--output", default=DEFAULT_PREBUILT_INFO_PATH) |
| 548 | + parser.add_argument("--output", default=DEFAULT_BUILD_INFO_OUTPUT) |
539 | 549 | return parser.parse_args() |
540 | 550 |
|
541 | 551 |
|
|
0 commit comments