diff --git a/rock/admin/proto/request.py b/rock/admin/proto/request.py index b7b45ce95..666d4d0b1 100644 --- a/rock/admin/proto/request.py +++ b/rock/admin/proto/request.py @@ -33,6 +33,8 @@ class SandboxStartRequest(BaseModel): """Password for Docker registry authentication. When both username and password are provided, docker login will be performed before pulling the image.""" use_kata_runtime: bool = False """Whether to use kata container runtime (io.containerd.kata.v2) instead of --privileged mode.""" + auto_delete_seconds: int = 0 + """The time for automatic container deletion, with the unit being seconds.""" class SandboxCommand(Command): diff --git a/rock/deployments/config.py b/rock/deployments/config.py index 7b8b66f9a..d6c2a795d 100644 --- a/rock/deployments/config.py +++ b/rock/deployments/config.py @@ -167,7 +167,11 @@ def auto_clear_time(self) -> int: @classmethod def from_request(cls, request: SandboxStartRequest) -> DeploymentConfig: """Create DockerDeploymentConfig from SandboxStartRequest""" - return cls(**request.model_dump(exclude={"sandbox_id"}), container_name=request.sandbox_id) + return cls( + **request.model_dump(exclude={"sandbox_id", "auto_delete_seconds"}), + container_name=request.sandbox_id, + remove_container=(request.auto_delete_seconds == 0), + ) class RayDeploymentConfig(DockerDeploymentConfig): diff --git a/rock/sdk/sandbox/client.py b/rock/sdk/sandbox/client.py index ed85f7b52..7832ead8a 100644 --- a/rock/sdk/sandbox/client.py +++ b/rock/sdk/sandbox/client.py @@ -174,6 +174,7 @@ async def start(self): "registry_username": self.config.registry_username, "registry_password": self.config.registry_password, "use_kata_runtime": self.config.use_kata_runtime, + "auto_delete_seconds": self.config.auto_delete_seconds, } try: response = await HttpUtils.post(url, headers, data) diff --git a/rock/sdk/sandbox/config.py b/rock/sdk/sandbox/config.py index 46d97dfcc..6dcbdc3e6 100644 --- a/rock/sdk/sandbox/config.py +++ b/rock/sdk/sandbox/config.py @@ -42,6 +42,7 @@ class SandboxConfig(BaseConfig): registry_username: str | None = None registry_password: str | None = None use_kata_runtime: bool = False + auto_delete_seconds: int = 0 class SandboxGroupConfig(SandboxConfig):