Allow setting of runtime container image (#3573)

* Add runtime container image setting

* Fix typo in test

* Fix sandbox base container image

* Update variables

* Update to base_container_image

* Update tests/unit/test_config.py

Co-authored-by: Xingyao Wang <xingyao6@illinois.edu>

* Fixed eval

* Fixed container_image

* Fix typo

---------

Co-authored-by: Xingyao Wang <xingyao6@illinois.edu>
This commit is contained in:
Graham Neubig
2024-08-25 19:05:41 -04:00
committed by GitHub
parent 356d9b34be
commit f9088766e8
33 changed files with 92 additions and 82 deletions

View File

@@ -179,7 +179,8 @@ class SandboxConfig(metaclass=Singleton):
Attributes:
api_hostname: The hostname for the EventStream Runtime API.
container_image: The container image to use for the sandbox.
base_container_image: The base container image from which to build the runtime image.
runtime_container_image: The runtime container image to use.
user_id: The user ID for the sandbox.
timeout: The timeout for the sandbox.
enable_auto_lint: Whether to enable auto-lint.
@@ -199,7 +200,10 @@ class SandboxConfig(metaclass=Singleton):
"""
api_hostname: str = 'localhost'
container_image: str = 'nikolaik/python-nodejs:python3.11-nodejs22' # default to nikolaik/python-nodejs:python3.11-nodejs22 for eventstream runtime
base_container_image: str | None = (
'nikolaik/python-nodejs:python3.11-nodejs22' # default to nikolaik/python-nodejs:python3.11-nodejs22 for eventstream runtime
)
runtime_container_image: str | None = None
user_id: int = os.getuid() if hasattr(os, 'getuid') else 1000
timeout: int = 120
enable_auto_lint: bool = (

View File

@@ -22,7 +22,7 @@ class ConfigType(str, Enum):
CACHE_DIR = 'CACHE_DIR'
LLM_MODEL = 'LLM_MODEL'
CONFIRMATION_MODE = 'CONFIRMATION_MODE'
SANDBOX_CONTAINER_IMAGE = 'SANDBOX_CONTAINER_IMAGE'
BASE_CONTAINER_IMAGE = 'BASE_CONTAINER_IMAGE'
RUN_AS_OPENHANDS = 'RUN_AS_OPENHANDS'
LLM_EMBEDDING_MODEL = 'LLM_EMBEDDING_MODEL'
LLM_EMBEDDING_BASE_URL = 'LLM_EMBEDDING_BASE_URL'

View File

@@ -104,7 +104,6 @@ class EventStreamRuntime(Runtime):
event_stream: EventStream,
sid: str = 'default',
plugins: list[PluginRequirement] | None = None,
container_image: str | None = None,
):
super().__init__(
config, event_stream, sid, plugins
@@ -118,11 +117,8 @@ class EventStreamRuntime(Runtime):
)
# TODO: We can switch to aiodocker when `get_od_sandbox_image` is updated to use aiodocker
self.docker_client: docker.DockerClient = self._init_docker_client()
self.container_image = (
self.config.sandbox.container_image
if container_image is None
else container_image
)
self.base_container_image = self.config.sandbox.base_container_image
self.runtime_container_image = self.config.sandbox.runtime_container_image
self.container_name = self.container_name_prefix + self.instance_id
self.container = None
@@ -140,11 +136,16 @@ class EventStreamRuntime(Runtime):
f'Installing extra user-provided dependencies in the runtime image: {self.config.sandbox.runtime_extra_deps}'
)
self.container_image = build_runtime_image(
self.container_image,
self.runtime_builder,
extra_deps=self.config.sandbox.runtime_extra_deps,
)
if self.runtime_container_image is None:
if self.base_container_image is None:
raise ValueError(
'Neither runtime container image nor base container image is set'
)
self.runtime_container_image = build_runtime_image(
self.base_container_image,
self.runtime_builder,
extra_deps=self.config.sandbox.runtime_extra_deps,
)
self.container = await self._init_container(
self.sandbox_workspace_dir,
mount_dir=self.config.workspace_mount_path,
@@ -181,7 +182,7 @@ class EventStreamRuntime(Runtime):
):
try:
logger.info(
f'Starting container with image: {self.container_image} and name: {self.container_name}'
f'Starting container with image: {self.runtime_container_image} and name: {self.container_name}'
)
plugin_arg = ''
if plugins is not None and len(plugins) > 0:
@@ -215,7 +216,7 @@ class EventStreamRuntime(Runtime):
else:
browsergym_arg = ''
container = self.docker_client.containers.run(
self.container_image,
self.runtime_container_image,
command=(
f'/openhands/miniforge3/bin/mamba run --no-capture-output -n base '
'PYTHONUNBUFFERED=1 poetry run '