from __future__ import annotations from pathlib import Path from typing import Any, Dict from lab.compose import 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]: compose_path, payload = generate_compose(profile, run_dir) result = { "compose_path": str(compose_path), "service_count": len(payload.get("services", {})), "docker_available": command_available("docker"), "status": "ready", } if dry_run: result["status"] = "planned" return result 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