文件
websafe-kb/scripts/lab/provision.py

44 行
1.6 KiB
Python

from __future__ import annotations
from pathlib import Path
from typing import Any, Dict
from lab.compose import compose_payload, generate_compose
from lab.utils import command_available, run
def prepare(profile: Dict[str, Any], run_dir: Path, dry_run: bool = False) -> Dict[str, Any]:
payload = compose_payload(profile)
compose_path = run_dir / "compose" / "compose.yaml"
result = {
"compose_path": str(compose_path),
"service_count": len(payload.get("services", {})),
"compose_preview": payload,
"docker_available": command_available("docker"),
"status": "ready",
}
if dry_run:
result["status"] = "planned"
return result
compose_path, payload = generate_compose(profile, run_dir)
if not result["docker_available"]:
result["status"] = "blocked-artifact"
result["blocked_reason"] = "docker unavailable on this machine"
return result
config = run(["docker", "compose", "-f", str(compose_path), "config"], cwd=run_dir)
result["compose_config_rc"] = config.returncode
if config.returncode != 0:
result["status"] = "blocked-artifact"
result["blocked_reason"] = config.stderr.strip() or "docker compose config failed"
return result
up = run(["docker", "compose", "-f", str(compose_path), "up", "-d"], cwd=run_dir)
result["compose_up_rc"] = up.returncode
if up.returncode != 0:
result["status"] = "blocked-artifact"
result["blocked_reason"] = up.stderr.strip() or "docker compose up failed"
return result
return result