Skip to content

Commit

Permalink
Rebase and remove docker runtime
Browse files Browse the repository at this point in the history
Add volume for .venv for dev build
  • Loading branch information
qiangli committed Nov 20, 2024
1 parent b7c304e commit 1a82bb2
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 528 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ SHELL=/bin/bash

# Variables
BACKEND_HOST ?= "127.0.0.1"
BACKEND_PORT = 3000
BACKEND_PORT ?= 3000
BACKEND_HOST_PORT = "$(BACKEND_HOST):$(BACKEND_PORT)"
FRONTEND_PORT = 3001
FRONTEND_PORT ?= 3001
DEFAULT_WORKSPACE_DIR = "./workspace"
DEFAULT_MODEL = "gpt-4o"
CONFIG_FILE = config.toml
Expand Down
8 changes: 7 additions & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ services:
- SANDBOX_RUNTIME_CONTAINER_IMAGE=${SANDBOX_RUNTIME_CONTAINER_IMAGE:-ghcr.io/all-hands-ai/runtime:0.14-nikolaik}
- SANDBOX_USER_ID=${SANDBOX_USER_ID:-1234}
- WORKSPACE_MOUNT_PATH=${WORKSPACE_BASE:-$PWD/workspace}
#
- LOG_ALL_EVENTS=true
# See containers/custom-sandbox/README.md
- SANDBOX_REMOTE_RUNTIME_API_URL=http://host.docker.internal:8000/
- SANDBOX_CONTAINER_NAME=${SANDBOX_CONTAINER_NAME:-}
- SANDBOX_DOCKER_ENDPOINT=${SANDBOX_DOCKER_ENDPOINT:-}
ports:
- "3000:3000"
- "${FRONTEND_PORT:-3000}:3000"
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
Expand Down
39 changes: 32 additions & 7 deletions containers/custom-sandbox/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
# How to build custom Docker sandbox for OpenHands

[Docker](https://docs.docker.com/get-started/docker-overview/) is an open platform for developing, shipping, and running applications.
If you are looking for instructions for building custom sandboxes managed by OpenHands. Please follow [here](https://docs.all-hands.dev/modules/usage/how-to/custom-sandbox-guide)

This folder contains working examples to get you started.
This folder contains working examples for building a custom sandbox that you can run in the same Docker context or a different one. See Docker [context](https://docs.docker.com/engine/manage-resources/contexts/) for more info.

## Build the sandbox

Before attempting to build the sandbox, make sure you can [build OpenHands](https://github.com/All-Hands-AI/OpenHands/blob/main/Development.md).

You may try and build inside docker container.

```bash
make docker-dev
```

```bash
# rename the files and make changes as you please
cp build.example.sh build.sh
cp compose.example.yml compose.yml

./build.sh <my base image>
# ./build.sh <my base image> <my tag>
./build.sh
```

## Start up sandbox
Expand All @@ -20,14 +29,30 @@ cp compose.example.yml compose.yml
docker compose up -d
```

## Update config.toml and restart OpenHands
## Start OpenHands

Update config.toml

```toml
[core]
runtime="docker"

[sandbox]
container_name="<sandbox container_name>"
remote_runtime_api_url="http://<host>:<published sandbox port>/"
# http://<host>:<published sandbox port>/
remote_runtime_api_url = "http://host.docker.internal:8000/"
# <sandbox container_name>
container_name = "custom-sandbox"
# docker context endpoint
docker_endpoint = "unix:///var/run/docker.sock"
```

or use env.

```bash
export SANDBOX_REMOTE_RUNTIME_API_URL=http://host.docker.internal:8000/
export SANDBOX_CONTAINER_NAME=custom-sandbox
export SANDBOX_DOCKER_ENDPOINT=unix:///var/run/docker.sock
```

```bash
make docker-run
```
1 change: 1 addition & 0 deletions containers/custom-sandbox/build.example.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# args: <custom_base_image> <custom_image_tag>

set -euo pipefail

Expand Down
2 changes: 1 addition & 1 deletion containers/custom-sandbox/compose.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
poetry run
python -u -m openhands.runtime.action_execution_server 3000
--working-dir /workspace
--plugins agent_skills jupyter
--plugins agent_skills jupyter vscode
--username openhands
# the publicly exposed port 8000 must match the port in remote_runtime_api_url defined in the config.toml
ports:
Expand Down
11 changes: 6 additions & 5 deletions containers/custom-sandbox/config.example.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[core]
runtime="docker"

[sandbox]
container_name="custom-sandbox"
remote_runtime_api_url="http://host.docker.internal:8000/"

docker_url="unix:///var/run/docker.sock"
# http://<host>:<published sandbox port>/
remote_runtime_api_url = "http://host.docker.internal:8000/"
# <sandbox container_name>
container_name = "custom-sandbox"
# docker context endpoint
docker_endpoint = "unix:///var/run/docker.sock"

###
9 changes: 2 additions & 7 deletions containers/dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,13 @@ RUN apt-get update && apt-get install -y \

WORKDIR /app

# cache build dependencies
#
RUN \
--mount=type=bind,source=./,target=/app/ \
--mount=type=bind,rw,source=./,target=/app/ \
<<EOF
#!/bin/bash
make -s clean
make -s check-dependencies
make -s install-python-dependencies

# NOTE
# node_modules are .dockerignore-d therefore not mountable
# make -s install-frontend-dependencies
EOF

#
Expand Down
4 changes: 3 additions & 1 deletion containers/dev/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
- SANDBOX_USER_ID=${SANDBOX_USER_ID:-1234}
- WORKSPACE_MOUNT_PATH=${WORKSPACE_BASE:-$PWD/workspace}
ports:
- "3000:3000"
- "${FRONTEND_PORT:-3000}:3000"
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
Expand All @@ -29,10 +29,12 @@ services:
- $HOME/.npmrc:/root/.npmrc:ro
# cache
- cache-data:/root/.cache
- venv-data:/app/.venv
pull_policy: never
stdin_open: true
tty: true

##
volumes:
cache-data:
venv-data:
6 changes: 3 additions & 3 deletions openhands/core/config/sandbox_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class SandboxConfig:
browsergym_eval_env: The BrowserGym environment to use for evaluation.
Default is None for general purpose browsing. Check evaluation/miniwob and evaluation/webarena for examples.
platform: The platform on which the image should be built. Default is None.
container_name: The name of the container. Default is None.
docker_url: The URL for the Docker daemon. Default is unix:///var/run/docker.sock.
container_name: The name of the container.
docker_endpoint: The context endpoint for the sandbox Docker daemon.
"""

remote_runtime_api_url: str = 'http://localhost:8000'
Expand All @@ -56,7 +56,7 @@ class SandboxConfig:
browsergym_eval_env: str | None = None
platform: str | None = None
container_name: str | None = None
docker_url: str | None = None
docker_endpoint: str | None = None

def defaults_to_dict(self) -> dict:
"""Serialize fields to a dict for the frontend, including type hints, defaults, and whether it's optional."""
Expand Down
5 changes: 0 additions & 5 deletions openhands/runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ def get_runtime_cls(name: str):
return ModalRuntime
elif name == 'runloop':
return RunloopRuntime
elif name == 'docker':
logger.info('Using custom DockerRuntime')
from openhands.runtime.impl.docker.docker_runtime import DockerRuntime

return DockerRuntime
else:
raise ValueError(f'Runtime {name} not supported')

Expand Down
Loading

0 comments on commit 1a82bb2

Please sign in to comment.