-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change: Configure runtimes/deployments from config (#144)
- Loading branch information
Showing
16 changed files
with
351 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,3 @@ | ||
from typing import Literal | ||
from swerex.deployment.config import get_deployment | ||
|
||
from swerex.deployment.abstract import AbstractDeployment | ||
|
||
|
||
def get_deployment( | ||
deployment_type: Literal["local", "docker", "modal", "fargate", "remote"], **kwargs | ||
) -> AbstractDeployment: | ||
if deployment_type == "dummy": | ||
from swerex.deployment.dummy import DummyDeployment | ||
|
||
return DummyDeployment(**kwargs) | ||
if deployment_type == "local": | ||
from swerex.deployment.local import LocalDeployment | ||
|
||
return LocalDeployment(**kwargs) | ||
if deployment_type == "docker": | ||
from swerex.deployment.docker import DockerDeployment | ||
|
||
return DockerDeployment(**kwargs) | ||
if deployment_type == "modal": | ||
from swerex.deployment.modal import ModalDeployment | ||
|
||
return ModalDeployment(**kwargs) | ||
if deployment_type == "fargate": | ||
from swerex.deployment.fargate import FargateDeployment | ||
|
||
return FargateDeployment(**kwargs) | ||
if deployment_type == "remote": | ||
from swerex.deployment.remote import RemoteDeployment | ||
|
||
return RemoteDeployment(**kwargs) | ||
msg = f"Unknown deployment type: {deployment_type}" | ||
raise ValueError(msg) | ||
__all__ = ["get_deployment"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
from pathlib import PurePath | ||
from typing import Any, Literal | ||
|
||
from pydantic import BaseModel | ||
|
||
from swerex.deployment.abstract import AbstractDeployment | ||
|
||
|
||
class ModalDeploymentConfig(BaseModel): | ||
image: str | PurePath | ||
"""Image to use for the deployment. | ||
""" | ||
startup_timeout: float = 0.4 | ||
"""The time to wait for the runtime to start.""" | ||
runtime_timeout: float = 1800.0 | ||
"""The runtime timeout.""" | ||
modal_sandbox_kwargs: dict[str, Any] = {} | ||
"""Additional arguments to pass to `modal.Sandbox.create`""" | ||
|
||
|
||
class DockerDeploymentConfig(BaseModel): | ||
image: str | ||
"""The name of the docker image to use.""" | ||
port: int | None = None | ||
"""The port that the docker container connects to. If None, a free port is found.""" | ||
docker_args: list[str] = [] | ||
"""Additional arguments to pass to the docker run command.""" | ||
startup_timeout: float = 60.0 | ||
"""The time to wait for the runtime to start.""" | ||
pull: Literal["never", "always", "missing"] = "missing" | ||
"""When to pull docker images.""" | ||
remove_images: bool = False | ||
"""Whether to remove the image after it has stopped.""" | ||
|
||
|
||
class DummyDeploymentConfig(BaseModel): | ||
pass | ||
|
||
|
||
class FargateDeploymentConfig(BaseModel): | ||
image: str | ||
port: int = 8880 | ||
cluster_name: str = "swe-rex-cluster" | ||
execution_role_prefix: str = "swe-rex-execution-role" | ||
task_definition_prefix: str = "swe-rex-task" | ||
log_group: str | None = "/ecs/swe-rex-deployment" | ||
security_group_prefix: str = "swe-rex-deployment-sg" | ||
fargate_args: dict[str, str] = {} | ||
container_timeout: float = 60 * 15 | ||
runtime_timeout: float = 30 | ||
|
||
|
||
class LocalDeploymentConfig(BaseModel): | ||
"""The port that the runtime connects to.""" | ||
|
||
|
||
class RemoteDeploymentConfig(BaseModel): | ||
auth_token: str | ||
"""The token to use for authentication.""" | ||
host: str = "http://127.0.0.1" | ||
"""The host to connect to.""" | ||
port: int | None = None | ||
"""The port to connect to.""" | ||
timeout: float = 0.15 | ||
|
||
|
||
DeploymentConfig = ( | ||
LocalDeploymentConfig | ||
| DockerDeploymentConfig | ||
| ModalDeploymentConfig | ||
| FargateDeploymentConfig | ||
| RemoteDeploymentConfig | ||
) | ||
|
||
|
||
def get_deployment( | ||
config: DeploymentConfig, | ||
) -> AbstractDeployment: | ||
# Defer imports to avoid pulling in unnecessary dependencies | ||
if isinstance(config, DummyDeploymentConfig): | ||
from swerex.deployment.dummy import DummyDeployment | ||
|
||
return DummyDeployment.from_config(config) | ||
if isinstance(config, LocalDeploymentConfig): | ||
from swerex.deployment.local import LocalDeployment | ||
|
||
return LocalDeployment.from_config(config) | ||
if isinstance(config, DockerDeploymentConfig): | ||
from swerex.deployment.docker import DockerDeployment | ||
|
||
return DockerDeployment.from_config(config) | ||
if isinstance(config, ModalDeploymentConfig): | ||
from swerex.deployment.modal import ModalDeployment | ||
|
||
return ModalDeployment.from_config(config) | ||
if isinstance(config, FargateDeploymentConfig): | ||
from swerex.deployment.fargate import FargateDeployment | ||
|
||
return FargateDeployment.from_config(config) | ||
if isinstance(config, RemoteDeploymentConfig): | ||
from swerex.deployment.remote import RemoteDeployment | ||
|
||
return RemoteDeployment.from_config(config) | ||
|
||
msg = f"Unknown deployment type: {type(config)}" | ||
raise ValueError(msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.