Phase 19: compose validate (docker compose config) + diff vs deployed in editor (0.25.0)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
34c5fffa85
commit
9c4d319f8f
@@ -9,6 +9,7 @@ import asyncio
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import tempfile
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
@@ -313,6 +314,37 @@ async def run_compose(
|
||||
}
|
||||
|
||||
|
||||
async def validate_yaml(content: str, env_content: str = "") -> dict:
|
||||
"""Validate compose YAML by running ``docker compose config -q`` against it
|
||||
in a throwaway directory. Returns ``{"ok": bool, "errors": str}`` — the
|
||||
errors string carries compose's own diagnostics (parse errors, unknown
|
||||
keys, bad interpolation) so the editor can surface them before saving."""
|
||||
with tempfile.TemporaryDirectory(prefix="sp-validate-") as tmp:
|
||||
compose_file = os.path.join(tmp, DEFAULT_COMPOSE_NAME)
|
||||
with open(compose_file, "w", encoding="utf-8") as fh:
|
||||
fh.write(content)
|
||||
if env_content:
|
||||
with open(os.path.join(tmp, ".env"), "w", encoding="utf-8") as fh:
|
||||
fh.write(env_content)
|
||||
cmd = [
|
||||
"docker", "compose",
|
||||
"--project-directory", tmp,
|
||||
"-f", compose_file,
|
||||
"config", "-q",
|
||||
]
|
||||
try:
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
*cmd,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
_out, err = await asyncio.wait_for(proc.communicate(), timeout=30.0)
|
||||
except asyncio.TimeoutError as exc:
|
||||
raise StackFileError("compose config validation timed out") from exc
|
||||
ok = proc.returncode == 0
|
||||
return {"ok": ok, "errors": "" if ok else err.decode("utf-8", "replace").strip()}
|
||||
|
||||
|
||||
async def stream_compose(
|
||||
stack_id: str, args: list[str], override: Optional[str] = None
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user