From ffa94d963f8c5c9c3b18fd66d584e639991659a5 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 1 Oct 2024 20:57:39 +0000 Subject: [PATCH 01/30] use micromamba instead of mamba for effeciency --- openhands/runtime/client/runtime.py | 2 +- openhands/runtime/plugins/jupyter/__init__.py | 3 +- openhands/runtime/remote/runtime.py | 2 +- .../utils/runtime_templates/Dockerfile.j2 | 33 +++++++++---------- tests/runtime/test_browsing.py | 2 +- tests/unit/test_runtime_build.py | 4 +-- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/openhands/runtime/client/runtime.py b/openhands/runtime/client/runtime.py index dde4df680b3f..97413eefe7b1 100644 --- a/openhands/runtime/client/runtime.py +++ b/openhands/runtime/client/runtime.py @@ -272,7 +272,7 @@ def _init_container( container = self.docker_client.containers.run( self.runtime_container_image, command=( - f'/openhands/miniforge3/bin/mamba run --no-capture-output -n base ' + f'/openhands/micromamba/bin/micromamba run -n openhands ' f'poetry run ' f'python -u -m openhands.runtime.client.client {self._container_port} ' f'--working-dir "{sandbox_workspace_dir}" ' diff --git a/openhands/runtime/plugins/jupyter/__init__.py b/openhands/runtime/plugins/jupyter/__init__.py index b46714c2422e..48ee21dbbba5 100644 --- a/openhands/runtime/plugins/jupyter/__init__.py +++ b/openhands/runtime/plugins/jupyter/__init__.py @@ -28,7 +28,8 @@ async def initialize(self, username: str, kernel_id: str = 'openhands-default'): 'cd /openhands/code\n' 'export POETRY_VIRTUALENVS_PATH=/openhands/poetry;\n' 'export PYTHONPATH=/openhands/code:$PYTHONPATH;\n' - '/openhands/miniforge3/bin/mamba run -n base ' + 'export MAMBA_ROOT_PREFIX=/openhands/micromamba;\n' + '/openhands/micromamba/bin/micromamba run -n openhands ' 'poetry run jupyter kernelgateway ' '--KernelGatewayApp.ip=0.0.0.0 ' f'--KernelGatewayApp.port={self.kernel_gateway_port}\n' diff --git a/openhands/runtime/remote/runtime.py b/openhands/runtime/remote/runtime.py index 30e8f5b646c2..79c5b563d978 100644 --- a/openhands/runtime/remote/runtime.py +++ b/openhands/runtime/remote/runtime.py @@ -143,7 +143,7 @@ def __init__( start_request = { 'image': self.container_image, 'command': ( - f'/openhands/miniforge3/bin/mamba run --no-capture-output -n base ' + f'/openhands/micromamba/bin/micromamba run -n openhands ' 'PYTHONUNBUFFERED=1 poetry run ' f'python -u -m openhands.runtime.client.client {self.port} ' f'--working-dir {self.config.workspace_mount_path_in_sandbox} ' diff --git a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 index 57ea62dba24a..d2c2222e3f95 100644 --- a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 +++ b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 @@ -29,16 +29,15 @@ RUN mkdir -p /openhands && \ # Directory containing subdirectories for virtual environment. ENV POETRY_VIRTUALENVS_PATH=/openhands/poetry -RUN if [ ! -d /openhands/miniforge3 ]; then \ - wget --progress=bar:force -O Miniforge3.sh "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" && \ - bash Miniforge3.sh -b -p /openhands/miniforge3 && \ - rm Miniforge3.sh && \ - chmod -R g+w /openhands/miniforge3 && \ - bash -c ". /openhands/miniforge3/etc/profile.d/conda.sh && conda config --set changeps1 False && conda config --append channels conda-forge"; \ - fi +# Install micromamba +RUN mkdir -p /openhands/micromamba && \ + curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj -C /openhands/micromamba + +# Set up micromamba +ENV MAMBA_ROOT_PREFIX=/openhands/micromamba +RUN /openhands/micromamba/bin/micromamba create -n openhands python=3.11 -y && \ + /openhands/micromamba/bin/micromamba install -n openhands conda-forge::poetry -y -# Install Python and Poetry -RUN /openhands/miniforge3/bin/mamba install conda-forge::poetry python=3.11 -y # ================================================================ # END: Build Runtime Image from Scratch # ================================================================ @@ -60,26 +59,26 @@ COPY ./code /openhands/code WORKDIR /openhands/code RUN \ # Configure Poetry and create virtual environment - /openhands/miniforge3/bin/mamba run -n base poetry config virtualenvs.path /openhands/poetry && \ - /openhands/miniforge3/bin/mamba run -n base poetry env use python3.11 && \ + /openhands/micromamba/bin/micromamba run -n openhands poetry config virtualenvs.path /openhands/poetry && \ + /openhands/micromamba/bin/micromamba run -n openhands poetry env use python3.11 && \ # Install project dependencies - /openhands/miniforge3/bin/mamba run -n base poetry install --only main,runtime --no-interaction --no-root && \ + /openhands/micromamba/bin/micromamba run -n openhands poetry install --only main,runtime --no-interaction --no-root && \ # Update and install additional tools apt-get update && \ - /openhands/miniforge3/bin/mamba run -n base poetry run pip install playwright && \ - /openhands/miniforge3/bin/mamba run -n base poetry run playwright install --with-deps chromium && \ + /openhands/micromamba/bin/micromamba run -n openhands poetry run pip install playwright && \ + /openhands/micromamba/bin/micromamba run -n openhands poetry run playwright install --with-deps chromium && \ # Set environment variables - echo "OH_INTERPRETER_PATH=$(/openhands/miniforge3/bin/mamba run -n base poetry run python -c "import sys; print(sys.executable)")" >> /etc/environment && \ + echo "OH_INTERPRETER_PATH=$(/openhands/micromamba/bin/micromamba run -n openhands poetry run python -c "import sys; print(sys.executable)")" >> /etc/environment && \ # Install extra dependencies if specified {{ extra_deps }} {% if extra_deps %} && {% endif %} \ # Clear caches - /openhands/miniforge3/bin/mamba run -n base poetry cache clear --all . && \ + /openhands/micromamba/bin/micromamba run -n openhands poetry cache clear --all . && \ # Set permissions {% if not skip_init %}chmod -R g+rws /openhands/poetry && {% endif %} \ mkdir -p /openhands/workspace && chmod -R g+rws,o+rw /openhands/workspace && \ # Clean up apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \ - /openhands/miniforge3/bin/mamba clean --all + /openhands/micromamba/bin/micromamba clean --all # ================================================================ # END: Copy Project and Install/Update Dependencies # ================================================================ diff --git a/tests/runtime/test_browsing.py b/tests/runtime/test_browsing.py index c0ea3e1810dc..2f1f6f520a7c 100644 --- a/tests/runtime/test_browsing.py +++ b/tests/runtime/test_browsing.py @@ -19,7 +19,7 @@ # Browsing tests # ============================================================================================================================ -PY3_FOR_TESTING = '/openhands/miniforge3/bin/mamba run -n base python3' +PY3_FOR_TESTING = '/openhands/micromamba/bin/micromamba run -n openhands python3' def test_simple_browse(temp_dir, box_class, run_as_openhands): diff --git a/tests/unit/test_runtime_build.py b/tests/unit/test_runtime_build.py index 0b448f2b5403..bbe26520598b 100644 --- a/tests/unit/test_runtime_build.py +++ b/tests/unit/test_runtime_build.py @@ -157,14 +157,14 @@ def test_generate_dockerfile_scratch(): assert 'apt-get update' in dockerfile_content assert 'apt-get install -y wget sudo apt-utils' in dockerfile_content assert ( - 'RUN /openhands/miniforge3/bin/mamba install conda-forge::poetry python=3.11 -y' + 'RUN /openhands/micromamba/bin/micromamba install conda-forge::poetry python=3.11 -y' in dockerfile_content ) # Check the update command assert 'COPY ./code /openhands/code' in dockerfile_content assert ( - '/openhands/miniforge3/bin/mamba run -n base poetry install' + '/openhands/micromamba/bin/micromamba run -n openhands poetry install' in dockerfile_content ) From dfbc06274382d81abfd3297cb6b90ed8511837f0 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 1 Oct 2024 21:17:19 +0000 Subject: [PATCH 02/30] (debug) ls --- openhands/runtime/utils/runtime_templates/Dockerfile.j2 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 index d2c2222e3f95..79af2b3a975d 100644 --- a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 +++ b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 @@ -31,7 +31,8 @@ ENV POETRY_VIRTUALENVS_PATH=/openhands/poetry # Install micromamba RUN mkdir -p /openhands/micromamba && \ - curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj -C /openhands/micromamba + curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj -C /openhands/ && \ + ls -alh /openhands/micromamba # Set up micromamba ENV MAMBA_ROOT_PREFIX=/openhands/micromamba From 33c54942c287f39e395fd111c276c592dd4a5b0e Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 1 Oct 2024 21:31:35 +0000 Subject: [PATCH 03/30] (debug) try directly using install script (likely more robust long term) --- openhands/runtime/utils/runtime_templates/Dockerfile.j2 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 index 79af2b3a975d..cb33bbbcb027 100644 --- a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 +++ b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 @@ -30,9 +30,8 @@ RUN mkdir -p /openhands && \ ENV POETRY_VIRTUALENVS_PATH=/openhands/poetry # Install micromamba -RUN mkdir -p /openhands/micromamba && \ - curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj -C /openhands/ && \ - ls -alh /openhands/micromamba +RUN mkdir -p /openhands/micromamba/bin && \ + /bin/bash -c "PREFIX_LOCATION=/openhands/micromamba BIN_FOLDER=/openhands/micromamba/bin INIT_YES=no CONDA_FORGE_YES=no $(curl -L https://micro.mamba.pm/install.sh)" # Set up micromamba ENV MAMBA_ROOT_PREFIX=/openhands/micromamba From 374e1acdcbb73ffd63dcee9bb50322a1aa44aab9 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 1 Oct 2024 21:43:14 +0000 Subject: [PATCH 04/30] fix test runtime --- tests/unit/test_runtime_build.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/unit/test_runtime_build.py b/tests/unit/test_runtime_build.py index bbe26520598b..a30eb4184841 100644 --- a/tests/unit/test_runtime_build.py +++ b/tests/unit/test_runtime_build.py @@ -156,10 +156,8 @@ def test_generate_dockerfile_scratch(): assert base_image in dockerfile_content assert 'apt-get update' in dockerfile_content assert 'apt-get install -y wget sudo apt-utils' in dockerfile_content - assert ( - 'RUN /openhands/micromamba/bin/micromamba install conda-forge::poetry python=3.11 -y' - in dockerfile_content - ) + assert 'conda-forge::poetry' in dockerfile_content + assert 'python=3.11' in dockerfile_content # Check the update command assert 'COPY ./code /openhands/code' in dockerfile_content @@ -178,17 +176,12 @@ def test_generate_dockerfile_skip_init(): # These commands SHOULD NOT include in the dockerfile if skip_init is True assert 'RUN apt update && apt install -y wget sudo' not in dockerfile_content - assert ( - 'RUN /openhands/miniforge3/bin/mamba install conda-forge::poetry python=3.11 -y' - not in dockerfile_content - ) + assert 'conda-forge::poetry' not in dockerfile_content + assert 'python=3.11' not in dockerfile_content # These update commands SHOULD still in the dockerfile assert 'COPY ./code /openhands/code' in dockerfile_content - assert ( - '/openhands/miniforge3/bin/mamba run -n base poetry install' - in dockerfile_content - ) + assert 'https://micro.mamba.pm/install.sh' in dockerfile_content def test_get_runtime_image_repo_and_tag_eventstream(): From cf13e56d5f92dd9c5bfed63535c99a3c885c173a Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 1 Oct 2024 21:55:53 +0000 Subject: [PATCH 05/30] fix test runtime build --- tests/unit/test_runtime_build.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_runtime_build.py b/tests/unit/test_runtime_build.py index a30eb4184841..84e5501f0ce9 100644 --- a/tests/unit/test_runtime_build.py +++ b/tests/unit/test_runtime_build.py @@ -178,10 +178,11 @@ def test_generate_dockerfile_skip_init(): assert 'RUN apt update && apt install -y wget sudo' not in dockerfile_content assert 'conda-forge::poetry' not in dockerfile_content assert 'python=3.11' not in dockerfile_content + assert 'https://micro.mamba.pm/install.sh' not in dockerfile_content # These update commands SHOULD still in the dockerfile assert 'COPY ./code /openhands/code' in dockerfile_content - assert 'https://micro.mamba.pm/install.sh' in dockerfile_content + assert 'poetry install' in dockerfile_content def test_get_runtime_image_repo_and_tag_eventstream(): From 156a679f62a94e491efdd9dd88a0da79d018c56e Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 1 Oct 2024 22:03:39 +0000 Subject: [PATCH 06/30] conda forge yes --- openhands/runtime/utils/runtime_templates/Dockerfile.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 index cb33bbbcb027..dda600204dae 100644 --- a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 +++ b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 @@ -31,7 +31,7 @@ ENV POETRY_VIRTUALENVS_PATH=/openhands/poetry # Install micromamba RUN mkdir -p /openhands/micromamba/bin && \ - /bin/bash -c "PREFIX_LOCATION=/openhands/micromamba BIN_FOLDER=/openhands/micromamba/bin INIT_YES=no CONDA_FORGE_YES=no $(curl -L https://micro.mamba.pm/install.sh)" + /bin/bash -c "PREFIX_LOCATION=/openhands/micromamba BIN_FOLDER=/openhands/micromamba/bin INIT_YES=no CONDA_FORGE_YES=yes $(curl -L https://micro.mamba.pm/install.sh)" # Set up micromamba ENV MAMBA_ROOT_PREFIX=/openhands/micromamba From a95245c321d67305a2ee0bec038d4044ecc6d532 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 1 Oct 2024 22:26:34 +0000 Subject: [PATCH 07/30] tweak conda forge to no --- openhands/runtime/utils/runtime_templates/Dockerfile.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 index dda600204dae..cb33bbbcb027 100644 --- a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 +++ b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 @@ -31,7 +31,7 @@ ENV POETRY_VIRTUALENVS_PATH=/openhands/poetry # Install micromamba RUN mkdir -p /openhands/micromamba/bin && \ - /bin/bash -c "PREFIX_LOCATION=/openhands/micromamba BIN_FOLDER=/openhands/micromamba/bin INIT_YES=no CONDA_FORGE_YES=yes $(curl -L https://micro.mamba.pm/install.sh)" + /bin/bash -c "PREFIX_LOCATION=/openhands/micromamba BIN_FOLDER=/openhands/micromamba/bin INIT_YES=no CONDA_FORGE_YES=no $(curl -L https://micro.mamba.pm/install.sh)" # Set up micromamba ENV MAMBA_ROOT_PREFIX=/openhands/micromamba From ef76b1e4d9ab9e79152f1c9597275d72ad3c4727 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 1 Oct 2024 22:46:45 +0000 Subject: [PATCH 08/30] tweak to install py together with poetry & set forge_yes to true again --- openhands/runtime/utils/runtime_templates/Dockerfile.j2 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 index cb33bbbcb027..e888dd15f084 100644 --- a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 +++ b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 @@ -31,12 +31,12 @@ ENV POETRY_VIRTUALENVS_PATH=/openhands/poetry # Install micromamba RUN mkdir -p /openhands/micromamba/bin && \ - /bin/bash -c "PREFIX_LOCATION=/openhands/micromamba BIN_FOLDER=/openhands/micromamba/bin INIT_YES=no CONDA_FORGE_YES=no $(curl -L https://micro.mamba.pm/install.sh)" + /bin/bash -c "PREFIX_LOCATION=/openhands/micromamba BIN_FOLDER=/openhands/micromamba/bin INIT_YES=no CONDA_FORGE_YES=yes $(curl -L https://micro.mamba.pm/install.sh)" # Set up micromamba ENV MAMBA_ROOT_PREFIX=/openhands/micromamba -RUN /openhands/micromamba/bin/micromamba create -n openhands python=3.11 -y && \ - /openhands/micromamba/bin/micromamba install -n openhands conda-forge::poetry -y +RUN /openhands/micromamba/bin/micromamba create -n openhands -y && \ + /openhands/micromamba/bin/micromamba install -n openhands conda-forge::poetry python=3.11 -y # ================================================================ # END: Build Runtime Image from Scratch From d8836799a31f229b04dff36b39a553fdc5a0eed5 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 1 Oct 2024 23:15:31 +0000 Subject: [PATCH 09/30] re-order env var --- .../utils/runtime_templates/Dockerfile.j2 | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 index e888dd15f084..38d85d548676 100644 --- a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 +++ b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 @@ -1,11 +1,13 @@ -{% if skip_init %} FROM {{ base_image }} -{% else %} + +# Shared environment variables (regardless of init or not) +ENV POETRY_VIRTUALENVS_PATH=/openhands/poetry +ENV MAMBA_ROOT_PREFIX=/openhands/micromamba + +{% if not skip_init %} # ================================================================ # START: Build Runtime Image from Scratch # ================================================================ -FROM {{ base_image }} - {% if 'ubuntu' in base_image and (base_image.endswith(':latest') or base_image.endswith(':24.04')) %} {% set LIBGL_MESA = 'libgl1' %} {% else %} @@ -26,17 +28,13 @@ RUN mkdir -p /openhands && \ mkdir -p /openhands/logs && \ mkdir -p /openhands/poetry -# Directory containing subdirectories for virtual environment. -ENV POETRY_VIRTUALENVS_PATH=/openhands/poetry - # Install micromamba RUN mkdir -p /openhands/micromamba/bin && \ /bin/bash -c "PREFIX_LOCATION=/openhands/micromamba BIN_FOLDER=/openhands/micromamba/bin INIT_YES=no CONDA_FORGE_YES=yes $(curl -L https://micro.mamba.pm/install.sh)" -# Set up micromamba -ENV MAMBA_ROOT_PREFIX=/openhands/micromamba +# Create the openhands virtual environment and install poetry and python RUN /openhands/micromamba/bin/micromamba create -n openhands -y && \ - /openhands/micromamba/bin/micromamba install -n openhands conda-forge::poetry python=3.11 -y + /openhands/micromamba/bin/micromamba install -n openhands -c conda-forge poetry python=3.11 -y # ================================================================ # END: Build Runtime Image from Scratch From 23d755d4edf2905ee0ed6e3d5893c3176c0b9b18 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 2 Oct 2024 01:27:46 +0000 Subject: [PATCH 10/30] always remove commercial channel 'defaults' --- openhands/runtime/utils/runtime_templates/Dockerfile.j2 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 index 38d85d548676..93caa75c76dd 100644 --- a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 +++ b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 @@ -30,7 +30,9 @@ RUN mkdir -p /openhands && \ # Install micromamba RUN mkdir -p /openhands/micromamba/bin && \ - /bin/bash -c "PREFIX_LOCATION=/openhands/micromamba BIN_FOLDER=/openhands/micromamba/bin INIT_YES=no CONDA_FORGE_YES=yes $(curl -L https://micro.mamba.pm/install.sh)" + /bin/bash -c "PREFIX_LOCATION=/openhands/micromamba BIN_FOLDER=/openhands/micromamba/bin INIT_YES=no CONDA_FORGE_YES=yes $(curl -L https://micro.mamba.pm/install.sh)" && \ + /openhands/micromamba/bin/micromamba config remove channels defaults && \ + /openhands/micromamba/bin/micromamba config list # Create the openhands virtual environment and install poetry and python RUN /openhands/micromamba/bin/micromamba create -n openhands -y && \ From dc8db3fb717f17445e0851a2e89f6f4a308fd661 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 2 Oct 2024 01:38:13 +0000 Subject: [PATCH 11/30] try log stderrr --- openhands/runtime/builder/docker.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/openhands/runtime/builder/docker.py b/openhands/runtime/builder/docker.py index e0fc5785dd8d..e4627fb7024a 100644 --- a/openhands/runtime/builder/docker.py +++ b/openhands/runtime/builder/docker.py @@ -110,6 +110,10 @@ def build( return_code = process.wait() if return_code != 0: + logger.error( + f'Buildx command failed: {buildx_cmd}.\nStatus code: {return_code}\nSTDERR: {process.stderr}' + ) + raise subprocess.CalledProcessError( return_code, process.args, @@ -186,9 +190,7 @@ def image_exists(self, image_name: str, pull_from_repo: bool = True) -> bool: return True except docker.errors.ImageNotFound: if not pull_from_repo: - logger.debug( - f'Image {image_name} not found locally' - ) + logger.debug(f'Image {image_name} not found locally') return False try: logger.debug( From c68efe364c4b8acccb29e0b52c29161661326f8d Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 1 Oct 2024 21:48:04 -0400 Subject: [PATCH 12/30] remove python unbufferred to fix remote runtime --- openhands/runtime/remote/runtime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openhands/runtime/remote/runtime.py b/openhands/runtime/remote/runtime.py index 79c5b563d978..ac007626b568 100644 --- a/openhands/runtime/remote/runtime.py +++ b/openhands/runtime/remote/runtime.py @@ -144,7 +144,7 @@ def __init__( 'image': self.container_image, 'command': ( f'/openhands/micromamba/bin/micromamba run -n openhands ' - 'PYTHONUNBUFFERED=1 poetry run ' + 'poetry run ' f'python -u -m openhands.runtime.client.client {self.port} ' f'--working-dir {self.config.workspace_mount_path_in_sandbox} ' f'{plugin_arg}' From f10f98ae16b7e9574b5f5d027b2109a52b1c819a Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 1 Oct 2024 21:49:36 -0400 Subject: [PATCH 13/30] add more printing --- openhands/runtime/builder/docker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openhands/runtime/builder/docker.py b/openhands/runtime/builder/docker.py index e4627fb7024a..1a142145253c 100644 --- a/openhands/runtime/builder/docker.py +++ b/openhands/runtime/builder/docker.py @@ -111,7 +111,7 @@ def build( if return_code != 0: logger.error( - f'Buildx command failed: {buildx_cmd}.\nStatus code: {return_code}\nSTDERR: {process.stderr}' + f'Buildx command failed: {buildx_cmd}.\nStatus code: {return_code}\nSTDOUT:\n{process.stdout}\nSTDERR:\n{process.stderr}' ) raise subprocess.CalledProcessError( From 7d0fa1d14a090fec3d1de559591a983a6c40a95d Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 1 Oct 2024 21:56:47 -0400 Subject: [PATCH 14/30] fix print --- openhands/runtime/builder/docker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openhands/runtime/builder/docker.py b/openhands/runtime/builder/docker.py index 1a142145253c..8cf3a33f159c 100644 --- a/openhands/runtime/builder/docker.py +++ b/openhands/runtime/builder/docker.py @@ -111,7 +111,7 @@ def build( if return_code != 0: logger.error( - f'Buildx command failed: {buildx_cmd}.\nStatus code: {return_code}\nSTDOUT:\n{process.stdout}\nSTDERR:\n{process.stderr}' + f'Buildx command failed: {buildx_cmd}.\nStatus code: {return_code}\nSTDOUT:\n{process.stdout.read() if process.stdout else ""}\nSTDERR:\n{process.stderr.read() if process.stderr else ""}' ) raise subprocess.CalledProcessError( From 08b042ef7c14358492022dedf3821d5aaf588db7 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 1 Oct 2024 22:05:35 -0400 Subject: [PATCH 15/30] fix runtime build tests --- tests/unit/test_runtime_build.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_runtime_build.py b/tests/unit/test_runtime_build.py index 84e5501f0ce9..e58be6557871 100644 --- a/tests/unit/test_runtime_build.py +++ b/tests/unit/test_runtime_build.py @@ -156,7 +156,7 @@ def test_generate_dockerfile_scratch(): assert base_image in dockerfile_content assert 'apt-get update' in dockerfile_content assert 'apt-get install -y wget sudo apt-utils' in dockerfile_content - assert 'conda-forge::poetry' in dockerfile_content + assert 'poetry' in dockerfile_content and '-c conda-forge' in dockerfile_content assert 'python=3.11' in dockerfile_content # Check the update command @@ -176,7 +176,10 @@ def test_generate_dockerfile_skip_init(): # These commands SHOULD NOT include in the dockerfile if skip_init is True assert 'RUN apt update && apt install -y wget sudo' not in dockerfile_content - assert 'conda-forge::poetry' not in dockerfile_content + assert ( + 'poetry' not in dockerfile_content + and '-c conda-forge' not in dockerfile_content + ) assert 'python=3.11' not in dockerfile_content assert 'https://micro.mamba.pm/install.sh' not in dockerfile_content From b778f440d3fbc374af0c3729e5f34acfe7f2addd Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 1 Oct 2024 22:23:25 -0400 Subject: [PATCH 16/30] fix test --- tests/unit/test_runtime_build.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/unit/test_runtime_build.py b/tests/unit/test_runtime_build.py index e58be6557871..fc85e409ef2d 100644 --- a/tests/unit/test_runtime_build.py +++ b/tests/unit/test_runtime_build.py @@ -176,10 +176,7 @@ def test_generate_dockerfile_skip_init(): # These commands SHOULD NOT include in the dockerfile if skip_init is True assert 'RUN apt update && apt install -y wget sudo' not in dockerfile_content - assert ( - 'poetry' not in dockerfile_content - and '-c conda-forge' not in dockerfile_content - ) + assert '-c conda-forge' not in dockerfile_content assert 'python=3.11' not in dockerfile_content assert 'https://micro.mamba.pm/install.sh' not in dockerfile_content From 6999e90a6e813447fc4e7e3a55f487d26f06caf7 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 1 Oct 2024 22:40:34 -0400 Subject: [PATCH 17/30] update CalledProcessError --- openhands/runtime/builder/docker.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/openhands/runtime/builder/docker.py b/openhands/runtime/builder/docker.py index 8cf3a33f159c..e77a9b1fd61e 100644 --- a/openhands/runtime/builder/docker.py +++ b/openhands/runtime/builder/docker.py @@ -110,15 +110,11 @@ def build( return_code = process.wait() if return_code != 0: - logger.error( - f'Buildx command failed: {buildx_cmd}.\nStatus code: {return_code}\nSTDOUT:\n{process.stdout.read() if process.stdout else ""}\nSTDERR:\n{process.stderr.read() if process.stderr else ""}' - ) - raise subprocess.CalledProcessError( return_code, process.args, - output=None, - stderr=None, + output=process.stdout.read() if process.stdout else None, + stderr=process.stderr.read() if process.stderr else None, ) except subprocess.CalledProcessError as e: From 334389a9231d54aff0d0c504f17778e6f486a182 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 2 Oct 2024 00:02:30 -0400 Subject: [PATCH 18/30] add test rerun --- .github/workflows/ghcr-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ghcr-build.yml b/.github/workflows/ghcr-build.yml index 348247779067..cc32c7fa2883 100644 --- a/.github/workflows/ghcr-build.yml +++ b/.github/workflows/ghcr-build.yml @@ -293,7 +293,7 @@ jobs: SANDBOX_RUNTIME_CONTAINER_IMAGE=$image_name \ TEST_IN_CI=true \ RUN_AS_OPENHANDS=false \ - poetry run pytest -n 3 -raR --reruns 1 --reruns-delay 3 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime + poetry run pytest -n 3 -raR --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 env: @@ -371,7 +371,7 @@ jobs: SANDBOX_RUNTIME_CONTAINER_IMAGE=$image_name \ TEST_IN_CI=true \ RUN_AS_OPENHANDS=true \ - poetry run pytest -n 3 -raR --reruns 1 --reruns-delay 3 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime + poetry run pytest -n 3 -raR --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 env: From cdabea029a1c0a2e687f7d17456f1f6ed86a0741 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 2 Oct 2024 04:47:18 +0000 Subject: [PATCH 19/30] attempt to fix ci by set n=1 --- .github/workflows/ghcr-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ghcr-build.yml b/.github/workflows/ghcr-build.yml index cc32c7fa2883..8fe72fb70653 100644 --- a/.github/workflows/ghcr-build.yml +++ b/.github/workflows/ghcr-build.yml @@ -293,7 +293,7 @@ jobs: SANDBOX_RUNTIME_CONTAINER_IMAGE=$image_name \ TEST_IN_CI=true \ RUN_AS_OPENHANDS=false \ - poetry run pytest -n 3 -raR --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime + poetry run pytest -n 1 -raR --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 env: @@ -371,7 +371,7 @@ jobs: SANDBOX_RUNTIME_CONTAINER_IMAGE=$image_name \ TEST_IN_CI=true \ RUN_AS_OPENHANDS=true \ - poetry run pytest -n 3 -raR --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime + poetry run pytest -n 1 -raR --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 env: From f959421599ed11834c79ea133fef6e6e80b0cab0 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 2 Oct 2024 14:57:00 +0000 Subject: [PATCH 20/30] Revert "attempt to fix ci by set n=1" This reverts commit cdabea029a1c0a2e687f7d17456f1f6ed86a0741. --- .github/workflows/ghcr-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ghcr-build.yml b/.github/workflows/ghcr-build.yml index 8fe72fb70653..cc32c7fa2883 100644 --- a/.github/workflows/ghcr-build.yml +++ b/.github/workflows/ghcr-build.yml @@ -293,7 +293,7 @@ jobs: SANDBOX_RUNTIME_CONTAINER_IMAGE=$image_name \ TEST_IN_CI=true \ RUN_AS_OPENHANDS=false \ - poetry run pytest -n 1 -raR --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime + poetry run pytest -n 3 -raR --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 env: @@ -371,7 +371,7 @@ jobs: SANDBOX_RUNTIME_CONTAINER_IMAGE=$image_name \ TEST_IN_CI=true \ RUN_AS_OPENHANDS=true \ - poetry run pytest -n 1 -raR --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime + poetry run pytest -n 3 -raR --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 env: From d732d3b1e9e73d38aaafe472452b754b164ab963 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 2 Oct 2024 14:59:08 +0000 Subject: [PATCH 21/30] force rebuild for browsergym test --- openhands/core/config/sandbox_config.py | 2 ++ openhands/runtime/client/runtime.py | 1 + openhands/runtime/remote/runtime.py | 1 + tests/runtime/conftest.py | 3 ++- tests/runtime/test_browsing.py | 1 + 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/openhands/core/config/sandbox_config.py b/openhands/core/config/sandbox_config.py index e6dc72d2cb7b..3f535a5fe81f 100644 --- a/openhands/core/config/sandbox_config.py +++ b/openhands/core/config/sandbox_config.py @@ -18,6 +18,7 @@ class SandboxConfig: enable_auto_lint: Whether to enable auto-lint. use_host_network: Whether to use the host network. initialize_plugins: Whether to initialize plugins. + force_rebuild_runtime: Whether to force rebuild the runtime image. runtime_extra_deps: The extra dependencies to install in the runtime image (typically used for evaluation). This will be rendered into the end of the Dockerfile that builds the runtime image. It can contain any valid shell commands (e.g., pip install numpy). @@ -43,6 +44,7 @@ class SandboxConfig: ) use_host_network: bool = False initialize_plugins: bool = True + force_rebuild_runtime: bool = False runtime_extra_deps: str | None = None runtime_startup_env_vars: dict[str, str] = field(default_factory=dict) browsergym_eval_env: str | None = None diff --git a/openhands/runtime/client/runtime.py b/openhands/runtime/client/runtime.py index 97413eefe7b1..e201f9418540 100644 --- a/openhands/runtime/client/runtime.py +++ b/openhands/runtime/client/runtime.py @@ -166,6 +166,7 @@ def __init__( self.base_container_image, self.runtime_builder, extra_deps=self.config.sandbox.runtime_extra_deps, + force_rebuild=self.config.sandbox.force_rebuild_runtime, ) self.container = self._init_container( sandbox_workspace_dir=self.config.workspace_mount_path_in_sandbox, # e.g. /workspace diff --git a/openhands/runtime/remote/runtime.py b/openhands/runtime/remote/runtime.py index ac007626b568..cf9489ae026b 100644 --- a/openhands/runtime/remote/runtime.py +++ b/openhands/runtime/remote/runtime.py @@ -118,6 +118,7 @@ def __init__( self.config.sandbox.base_container_image, self.runtime_builder, extra_deps=self.config.sandbox.runtime_extra_deps, + force_rebuild=self.config.sandbox.force_rebuild_runtime, ) response = send_request( diff --git a/tests/runtime/conftest.py b/tests/runtime/conftest.py index 2308244fb355..9b5bebab5476 100644 --- a/tests/runtime/conftest.py +++ b/tests/runtime/conftest.py @@ -208,6 +208,7 @@ def _load_runtime( base_container_image: str | None = None, browsergym_eval_env: str | None = None, use_workspace: bool | None = None, + force_rebuild_runtime: bool = False, ) -> Runtime: sid = 'rt_' + str(random.randint(100000, 999999)) @@ -217,7 +218,7 @@ def _load_runtime( config = load_app_config() config.run_as_openhands = run_as_openhands - + config.sandbox.force_rebuild_runtime = force_rebuild_runtime # Folder where all tests create their own folder global test_mount_path if use_workspace: diff --git a/tests/runtime/test_browsing.py b/tests/runtime/test_browsing.py index 2f1f6f520a7c..1d3a42131bbd 100644 --- a/tests/runtime/test_browsing.py +++ b/tests/runtime/test_browsing.py @@ -75,6 +75,7 @@ def test_browsergym_eval_env(box_class, temp_dir): run_as_openhands=False, # need root permission to access file base_container_image='xingyaoww/od-eval-miniwob:v1.0', browsergym_eval_env='browsergym/miniwob.choose-list', + force_rebuild_runtime=True, ) from openhands.runtime.browser.browser_env import ( BROWSER_EVAL_GET_GOAL_ACTION, From e04c84eec20e941e3b77aeae9c42abda5df9f9a4 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 2 Oct 2024 17:29:48 +0000 Subject: [PATCH 22/30] try print stderr --- openhands/runtime/builder/docker.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/openhands/runtime/builder/docker.py b/openhands/runtime/builder/docker.py index e77a9b1fd61e..42afffe700a3 100644 --- a/openhands/runtime/builder/docker.py +++ b/openhands/runtime/builder/docker.py @@ -96,17 +96,28 @@ def build( process = subprocess.Popen( buildx_cmd, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, + stderr=subprocess.PIPE, universal_newlines=True, bufsize=1, ) - if process.stdout: - for line in iter(process.stdout.readline, ''): - line = line.strip() + # Read stdout and stderr concurrently + while True: + stdout_line = process.stdout.readline() if process.stdout else '' + stderr_line = process.stderr.readline() if process.stderr else '' + + if not stdout_line and not stderr_line and process.poll() is not None: + break + + if stdout_line: + line = stdout_line.strip() if line: self._output_logs(line) + if stderr_line: + sys.stderr.write(stderr_line) + sys.stderr.flush() + return_code = process.wait() if return_code != 0: @@ -120,6 +131,9 @@ def build( except subprocess.CalledProcessError as e: logger.error(f'Image build failed:\n{e}') logger.error(f'Command output:\n{e.output}') + if e.stderr: + sys.stderr.write(f'Error output:\n{e.stderr.decode()}\n') + sys.stderr.flush() raise except subprocess.TimeoutExpired: From 3fbff154aff0e98eb3bad3be92fe604cbe655cf4 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 2 Oct 2024 17:51:45 +0000 Subject: [PATCH 23/30] force rebuild for dummy agent --- .github/workflows/dummy-agent-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dummy-agent-test.yml b/.github/workflows/dummy-agent-test.yml index 517af6fea173..795391e5b2a6 100644 --- a/.github/workflows/dummy-agent-test.yml +++ b/.github/workflows/dummy-agent-test.yml @@ -45,7 +45,7 @@ jobs: - name: Run tests run: | set -e - poetry run python3 openhands/core/main.py -t "do a flip" -d ./workspace/ -c DummyAgent + SANDBOX_FORCE_REBUILD_RUNTIME=True poetry run python3 openhands/core/main.py -t "do a flip" -d ./workspace/ -c DummyAgent - name: Check exit code run: | if [ $? -ne 0 ]; then From bc39c1d20d5e1fcff2dbe21c2cdee8d2e81978fa Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 2 Oct 2024 18:34:13 +0000 Subject: [PATCH 24/30] include stdout/stderr for failed test --- .github/workflows/ghcr-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ghcr-build.yml b/.github/workflows/ghcr-build.yml index cc32c7fa2883..82c30d988ee4 100644 --- a/.github/workflows/ghcr-build.yml +++ b/.github/workflows/ghcr-build.yml @@ -293,7 +293,7 @@ jobs: SANDBOX_RUNTIME_CONTAINER_IMAGE=$image_name \ TEST_IN_CI=true \ RUN_AS_OPENHANDS=false \ - poetry run pytest -n 3 -raR --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime + poetry run pytest -n 3 -raRs --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 env: @@ -371,7 +371,7 @@ jobs: SANDBOX_RUNTIME_CONTAINER_IMAGE=$image_name \ TEST_IN_CI=true \ RUN_AS_OPENHANDS=true \ - poetry run pytest -n 3 -raR --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime + poetry run pytest -n 3 -raRs --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 env: From 33c523832a395222865b82b6b49665e05b090a81 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 2 Oct 2024 18:59:29 +0000 Subject: [PATCH 25/30] always disable ps1 --- openhands/runtime/utils/runtime_templates/Dockerfile.j2 | 1 + 1 file changed, 1 insertion(+) diff --git a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 index 93caa75c76dd..e9fb491621c4 100644 --- a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 +++ b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 @@ -58,6 +58,7 @@ COPY ./code /openhands/code # virtual environment are used by default. WORKDIR /openhands/code RUN \ + /openhands/micromamba/bin/micromamba config set changeps1 False && \ # Configure Poetry and create virtual environment /openhands/micromamba/bin/micromamba run -n openhands poetry config virtualenvs.path /openhands/poetry && \ /openhands/micromamba/bin/micromamba run -n openhands poetry env use python3.11 && \ From 6330b52bf45b3aa55ec6bd7cec91f94f241e6495 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 2 Oct 2024 19:00:58 +0000 Subject: [PATCH 26/30] tweak pytests --- .github/workflows/ghcr-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ghcr-build.yml b/.github/workflows/ghcr-build.yml index 82c30d988ee4..2f244f4b78a8 100644 --- a/.github/workflows/ghcr-build.yml +++ b/.github/workflows/ghcr-build.yml @@ -293,7 +293,7 @@ jobs: SANDBOX_RUNTIME_CONTAINER_IMAGE=$image_name \ TEST_IN_CI=true \ RUN_AS_OPENHANDS=false \ - poetry run pytest -n 3 -raRs --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime + poetry run pytest -n 1 -raRvvxss --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 env: @@ -371,7 +371,7 @@ jobs: SANDBOX_RUNTIME_CONTAINER_IMAGE=$image_name \ TEST_IN_CI=true \ RUN_AS_OPENHANDS=true \ - poetry run pytest -n 3 -raRs --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime + poetry run pytest -n 1 -raRvvxss --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 env: From 8a9033d1cf2018836716380b899ed1a609b21f16 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 2 Oct 2024 19:42:39 +0000 Subject: [PATCH 27/30] install curl too --- openhands/runtime/utils/runtime_templates/Dockerfile.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 index e9fb491621c4..339584716158 100644 --- a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 +++ b/openhands/runtime/utils/runtime_templates/Dockerfile.j2 @@ -16,7 +16,7 @@ ENV MAMBA_ROOT_PREFIX=/openhands/micromamba # Install necessary packages and clean up in one layer RUN apt-get update && \ - apt-get install -y wget sudo apt-utils {{ LIBGL_MESA }} libasound2-plugins git && \ + apt-get install -y wget curl sudo apt-utils {{ LIBGL_MESA }} libasound2-plugins git && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* From 811ba8247ee00c635dd8b5851480c51a7f5c98e8 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 2 Oct 2024 19:54:16 +0000 Subject: [PATCH 28/30] fix runtime build tests --- tests/unit/test_runtime_build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_runtime_build.py b/tests/unit/test_runtime_build.py index fc85e409ef2d..0031f081604c 100644 --- a/tests/unit/test_runtime_build.py +++ b/tests/unit/test_runtime_build.py @@ -155,7 +155,7 @@ def test_generate_dockerfile_scratch(): ) assert base_image in dockerfile_content assert 'apt-get update' in dockerfile_content - assert 'apt-get install -y wget sudo apt-utils' in dockerfile_content + assert 'apt-get install -y wget curl sudo apt-utils' in dockerfile_content assert 'poetry' in dockerfile_content and '-c conda-forge' in dockerfile_content assert 'python=3.11' in dockerfile_content @@ -347,7 +347,7 @@ def live_docker_image(): dockerfile_content = f""" # syntax=docker/dockerfile:1.4 FROM {DEFAULT_BASE_IMAGE} AS base - RUN apt-get update && apt-get install -y wget sudo apt-utils + RUN apt-get update && apt-get install -y wget curl sudo apt-utils FROM base AS intermediate RUN mkdir -p /openhands From 61c6ec95e26267f70226ec2a018b2847d7f6451e Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 2 Oct 2024 20:38:39 +0000 Subject: [PATCH 29/30] Revert "try print stderr" This reverts commit e04c84eec20e941e3b77aeae9c42abda5df9f9a4. --- openhands/runtime/builder/docker.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/openhands/runtime/builder/docker.py b/openhands/runtime/builder/docker.py index 42afffe700a3..e77a9b1fd61e 100644 --- a/openhands/runtime/builder/docker.py +++ b/openhands/runtime/builder/docker.py @@ -96,28 +96,17 @@ def build( process = subprocess.Popen( buildx_cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + stderr=subprocess.STDOUT, universal_newlines=True, bufsize=1, ) - # Read stdout and stderr concurrently - while True: - stdout_line = process.stdout.readline() if process.stdout else '' - stderr_line = process.stderr.readline() if process.stderr else '' - - if not stdout_line and not stderr_line and process.poll() is not None: - break - - if stdout_line: - line = stdout_line.strip() + if process.stdout: + for line in iter(process.stdout.readline, ''): + line = line.strip() if line: self._output_logs(line) - if stderr_line: - sys.stderr.write(stderr_line) - sys.stderr.flush() - return_code = process.wait() if return_code != 0: @@ -131,9 +120,6 @@ def build( except subprocess.CalledProcessError as e: logger.error(f'Image build failed:\n{e}') logger.error(f'Command output:\n{e.output}') - if e.stderr: - sys.stderr.write(f'Error output:\n{e.stderr.decode()}\n') - sys.stderr.flush() raise except subprocess.TimeoutExpired: From 42157a9929a9864093a596376a54be3e33fa900f Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 2 Oct 2024 20:39:06 +0000 Subject: [PATCH 30/30] Revert "tweak pytests" This reverts commit 6330b52bf45b3aa55ec6bd7cec91f94f241e6495. --- .github/workflows/ghcr-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ghcr-build.yml b/.github/workflows/ghcr-build.yml index 2f244f4b78a8..82c30d988ee4 100644 --- a/.github/workflows/ghcr-build.yml +++ b/.github/workflows/ghcr-build.yml @@ -293,7 +293,7 @@ jobs: SANDBOX_RUNTIME_CONTAINER_IMAGE=$image_name \ TEST_IN_CI=true \ RUN_AS_OPENHANDS=false \ - poetry run pytest -n 1 -raRvvxss --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime + poetry run pytest -n 3 -raRs --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 env: @@ -371,7 +371,7 @@ jobs: SANDBOX_RUNTIME_CONTAINER_IMAGE=$image_name \ TEST_IN_CI=true \ RUN_AS_OPENHANDS=true \ - poetry run pytest -n 1 -raRvvxss --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime + poetry run pytest -n 3 -raRs --reruns 2 --reruns-delay 5 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 env: