mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-09 14:57:59 -05:00
fix: pip not available in runtime (#3306)
* try to fix pip unavailable
* update test case for pip
* force rebuild in CI
* remove extra symlink
* fix newline
* added semi-colon to line 31
* Dockerfile.j2: activate env at the end
* Revert "Dockerfile.j2: activate env at the end"
This reverts commit cf2f565102.
* cleanup Dockerfile
* switch default python image
* remove image agnostic (no longer used)
* fix tests
* switch to nikolaik/python-nodejs:python3.11-nodejs22
* fix test
* fix test
* revert docker
* update template
---------
Co-authored-by: tobitege <tobitege@gmx.de>
Co-authored-by: Graham Neubig <neubig@gmail.com>
This commit is contained in:
@@ -59,7 +59,7 @@ mkdir -p $WORKSPACE_BASE
|
||||
TEST_RUNTIME="${TEST_RUNTIME:-eventstream}" # can be server or eventstream
|
||||
# TODO: set this as default after ServerRuntime is deprecated
|
||||
if [ "$TEST_RUNTIME" == "eventstream" ] && [ -z "$SANDBOX_CONTAINER_IMAGE" ]; then
|
||||
SANDBOX_CONTAINER_IMAGE="ubuntu:22.04"
|
||||
SANDBOX_CONTAINER_IMAGE="nikolaik/python-nodejs:python3.11-nodejs22"
|
||||
fi
|
||||
|
||||
MAX_ITERATIONS=15
|
||||
|
||||
@@ -358,7 +358,7 @@ def test_defaults_dict_after_updates(default_config):
|
||||
assert defaults_after_updates['sandbox']['timeout']['default'] == 120
|
||||
assert (
|
||||
defaults_after_updates['sandbox']['container_image']['default']
|
||||
== 'ubuntu:22.04'
|
||||
== 'nikolaik/python-nodejs:python3.11-nodejs22'
|
||||
)
|
||||
assert defaults_after_updates == initial_defaults
|
||||
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from opendevin.runtime.utils.image_agnostic import (
|
||||
_get_new_image_name,
|
||||
generate_dockerfile,
|
||||
get_od_sandbox_image,
|
||||
)
|
||||
|
||||
|
||||
def test_generate_dockerfile():
|
||||
base_image = 'debian:11'
|
||||
dockerfile_content = generate_dockerfile(base_image)
|
||||
assert base_image in dockerfile_content
|
||||
assert (
|
||||
'RUN apt update && apt install -y openssh-server wget sudo'
|
||||
in dockerfile_content
|
||||
)
|
||||
|
||||
|
||||
def test_get_new_image_name_legacy():
|
||||
# test non-eventstream runtime (sandbox-based)
|
||||
base_image = 'debian:11'
|
||||
new_image_name = _get_new_image_name(base_image)
|
||||
assert new_image_name == 'od_sandbox:debian__11'
|
||||
|
||||
base_image = 'ubuntu:22.04'
|
||||
new_image_name = _get_new_image_name(base_image)
|
||||
assert new_image_name == 'od_sandbox:ubuntu__22.04'
|
||||
|
||||
base_image = 'ubuntu'
|
||||
new_image_name = _get_new_image_name(base_image)
|
||||
assert new_image_name == 'od_sandbox:ubuntu__latest'
|
||||
|
||||
|
||||
@patch('opendevin.runtime.utils.image_agnostic._build_sandbox_image')
|
||||
@patch('opendevin.runtime.utils.image_agnostic.docker.DockerClient')
|
||||
def test_get_od_sandbox_image(mock_docker_client, mock_build_sandbox_image):
|
||||
base_image = 'debian:11'
|
||||
mock_docker_client.images.list.return_value = [
|
||||
MagicMock(tags=['od_sandbox:debian__11'])
|
||||
]
|
||||
|
||||
image_name = get_od_sandbox_image(base_image, mock_docker_client)
|
||||
assert image_name == 'od_sandbox:debian__11'
|
||||
|
||||
mock_docker_client.images.list.return_value = []
|
||||
image_name = get_od_sandbox_image(base_image, mock_docker_client)
|
||||
assert image_name == 'od_sandbox:debian__11'
|
||||
mock_build_sandbox_image.assert_called_once_with(
|
||||
base_image, 'od_sandbox:debian__11', mock_docker_client
|
||||
)
|
||||
@@ -83,7 +83,9 @@ def enable_auto_lint(request):
|
||||
return request.param
|
||||
|
||||
|
||||
@pytest.fixture(scope='module', params=['ubuntu:22.04', 'debian:11'])
|
||||
@pytest.fixture(
|
||||
scope='module', params=['nikolaik/python-nodejs:python3.11-nodejs22', 'debian:11']
|
||||
)
|
||||
def container_image(request):
|
||||
time.sleep(1)
|
||||
return request.param
|
||||
@@ -127,7 +129,7 @@ async def _load_runtime(
|
||||
if 'od_runtime' not in cur_container_image and cur_container_image not in {
|
||||
'xingyaoww/od-eval-miniwob:v1.0'
|
||||
}: # a special exception list
|
||||
cur_container_image = 'ubuntu:22.04'
|
||||
cur_container_image = 'nikolaik/python-nodejs:python3.11-nodejs22'
|
||||
logger.warning(
|
||||
f'`{config.sandbox.container_image}` is not an od_runtime image. Will use `{cur_container_image}` as the container image for testing.'
|
||||
)
|
||||
@@ -1033,6 +1035,13 @@ async def test_bash_python_version(temp_dir, box_class):
|
||||
assert obs.exit_code == 0
|
||||
# Should not error out
|
||||
|
||||
action = CmdRunAction(command='pip --version')
|
||||
logger.info(action, extra={'msg_type': 'ACTION'})
|
||||
obs = await runtime.run_action(action)
|
||||
logger.info(obs, extra={'msg_type': 'OBSERVATION'})
|
||||
assert obs.exit_code == 0
|
||||
# Should not error out
|
||||
|
||||
await runtime.close()
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ def test_put_source_code_to_dir(temp_dir):
|
||||
def test_docker_build_folder(temp_dir):
|
||||
prep_docker_build_folder(
|
||||
temp_dir,
|
||||
base_image='ubuntu:22.04',
|
||||
base_image='nikolaik/python-nodejs:python3.11-nodejs22',
|
||||
skip_init=False,
|
||||
)
|
||||
|
||||
@@ -81,14 +81,14 @@ def test_docker_build_folder(temp_dir):
|
||||
def test_hash_folder_same(temp_dir):
|
||||
dir_hash_1 = prep_docker_build_folder(
|
||||
temp_dir,
|
||||
base_image='ubuntu:22.04',
|
||||
base_image='nikolaik/python-nodejs:python3.11-nodejs22',
|
||||
skip_init=False,
|
||||
)
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir_2:
|
||||
dir_hash_2 = prep_docker_build_folder(
|
||||
temp_dir_2,
|
||||
base_image='ubuntu:22.04',
|
||||
base_image='nikolaik/python-nodejs:python3.11-nodejs22',
|
||||
skip_init=False,
|
||||
)
|
||||
assert dir_hash_1 == dir_hash_2
|
||||
@@ -97,14 +97,14 @@ def test_hash_folder_same(temp_dir):
|
||||
def test_hash_folder_diff_init(temp_dir):
|
||||
dir_hash_1 = prep_docker_build_folder(
|
||||
temp_dir,
|
||||
base_image='ubuntu:22.04',
|
||||
base_image='nikolaik/python-nodejs:python3.11-nodejs22',
|
||||
skip_init=False,
|
||||
)
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir_2:
|
||||
dir_hash_2 = prep_docker_build_folder(
|
||||
temp_dir_2,
|
||||
base_image='ubuntu:22.04',
|
||||
base_image='nikolaik/python-nodejs:python3.11-nodejs22',
|
||||
skip_init=True,
|
||||
)
|
||||
assert dir_hash_1 != dir_hash_2
|
||||
@@ -113,7 +113,7 @@ def test_hash_folder_diff_init(temp_dir):
|
||||
def test_hash_folder_diff_image(temp_dir):
|
||||
dir_hash_1 = prep_docker_build_folder(
|
||||
temp_dir,
|
||||
base_image='ubuntu:22.04',
|
||||
base_image='nikolaik/python-nodejs:python3.11-nodejs22',
|
||||
skip_init=False,
|
||||
)
|
||||
|
||||
@@ -178,11 +178,12 @@ def test_get_runtime_image_repo_and_tag_eventstream():
|
||||
and img_tag == f'{OD_VERSION}_image_debian_tag_11'
|
||||
)
|
||||
|
||||
base_image = 'ubuntu:22.04'
|
||||
base_image = 'nikolaik/python-nodejs:python3.11-nodejs22'
|
||||
img_repo, img_tag = get_runtime_image_repo_and_tag(base_image)
|
||||
assert (
|
||||
img_repo == f'{RUNTIME_IMAGE_REPO}'
|
||||
and img_tag == f'{OD_VERSION}_image_ubuntu_tag_22.04'
|
||||
and img_tag
|
||||
== f'{OD_VERSION}_image_nikolaik___python-nodejs_tag_python3.11-nodejs22'
|
||||
)
|
||||
|
||||
base_image = 'ubuntu'
|
||||
|
||||
Reference in New Issue
Block a user