File size: 1,597 Bytes
4cf7fc5
 
 
a64c042
4cf7fc5
a64c042
4cf7fc5
 
 
 
 
 
 
 
 
 
 
 
 
bbf2468
4cf7fc5
 
 
 
 
 
 
 
 
 
 
 
b066699
4cf7fc5
 
 
 
 
 
 
 
 
bbf2468
 
 
4cf7fc5
 
 
 
bbf2468
4cf7fc5
 
 
 
 
 
 
 
 
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
from langchain.tools import ToolRuntime, tool

from multi_agent_sdlc.system.process import execute_process
from multi_agent_sdlc.tools.shared.description import RUN_DOCKER_COMPOSE_DESCRIPTION
from multi_agent_sdlc.tools.shared.models import (
    DockerComposeOperation,
    ExecutionTimeout,
    ProcessResult,
)
from multi_agent_sdlc.workflow.state import DevState


@tool(
    "run_docker_compose",
    description=RUN_DOCKER_COMPOSE_DESCRIPTION,
)
def run_docker_compose(
    operation: DockerComposeOperation,
    runtime: ToolRuntime[DevState],
    remove_volumes: bool = False,
    timeout_seconds: ExecutionTimeout = 120,
) -> ProcessResult:
    project_directory = runtime.state["project_directory"]

    command = ["docker", "compose"]

    match operation:
        case DockerComposeOperation.UP:
            command.extend(
                [
                    "up",
                    "-d",
                    "--build",
                    "--wait",
                    "--wait-timeout",
                    "60",
                ]
            )

        case DockerComposeOperation.DOWN:
            command.append("down")

            if remove_volumes:
                command.append("-v")

        case DockerComposeOperation.BUILD:
            command.append("build")

        case DockerComposeOperation.CONFIG:
            command.extend(["config", "--quiet"])

        case DockerComposeOperation.PS:
            command.append("ps")

    return execute_process(
        command,
        project_directory=project_directory,
        timeout_seconds=timeout_seconds,
    )