Spaces:
Running
Running
File size: 1,978 Bytes
bc0ac20 4ed2871 a64c042 bc0ac20 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | from pathlib import Path
from multi_agent_sdlc.deployment.contract import COMPOSE_FILE_NAMES
from multi_agent_sdlc.deployment.models import ValidatedProject
from multi_agent_sdlc.system.process import execute_process
def validate_project(
project_directory: Path,
) -> ValidatedProject:
project_directory = project_directory.resolve()
if not project_directory.exists():
raise ValueError(f"Project directory does not exist: {project_directory}")
if not project_directory.is_dir():
raise ValueError(f"Project path is not a directory: {project_directory}")
dockerfile = project_directory / "Dockerfile"
if not dockerfile.is_file():
raise ValueError(f"Dockerfile was not found in {project_directory}")
compose_file = _find_compose_file(project_directory)
result = execute_process(
[
"docker",
"compose",
"-f",
compose_file.name,
"config",
"--quiet",
],
project_directory=project_directory,
timeout_seconds=30,
)
if result["timed_out"]:
raise RuntimeError("Docker Compose configuration validation timed out.")
if result["exit_code"] != 0:
error = result["stderr"] or result["stdout"]
raise ValueError(
"Docker Compose configuration validation failed"
+ (f": {error}" if error else ".")
)
return ValidatedProject(
project_directory=project_directory,
dockerfile=dockerfile,
compose_file=compose_file,
)
def _find_compose_file(
project_directory: Path,
) -> Path:
for filename in COMPOSE_FILE_NAMES:
compose_file = project_directory / filename
if compose_file.is_file():
return compose_file
expected_files = ", ".join(COMPOSE_FILE_NAMES)
raise ValueError(
"Docker Compose configuration was not found. "
f"Expected one of: {expected_files}."
)
|