33 行
1.0 KiB
Python
33 行
1.0 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import Any, Dict, Tuple
|
|
|
|
from lab.utils import write_yaml
|
|
|
|
|
|
def compose_payload(profile: Dict[str, Any]) -> Dict[str, Any]:
|
|
services = {}
|
|
for service_name, service in profile.get("services", {}).items():
|
|
payload = {
|
|
"image": service["image"],
|
|
}
|
|
if service.get("ports"):
|
|
payload["ports"] = service["ports"]
|
|
if service.get("environment"):
|
|
payload["environment"] = service["environment"]
|
|
if service.get("depends_on"):
|
|
payload["depends_on"] = service["depends_on"]
|
|
services[service_name] = payload
|
|
return {
|
|
"services": services,
|
|
"networks": {"labnet": {"driver": "bridge"}},
|
|
}
|
|
|
|
|
|
def generate_compose(profile: Dict[str, Any], run_dir: Path) -> Tuple[Path, Dict[str, Any]]:
|
|
payload = compose_payload(profile)
|
|
compose_path = run_dir / "compose" / "compose.yaml"
|
|
write_yaml(compose_path, payload)
|
|
return compose_path, payload
|