| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- {% if skip_init %}
- FROM {{ base_image }}
- {% else %}
- # ================================================================
- # 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 %}
- {% set LIBGL_MESA = 'libgl1-mesa-glx' %}
- {% endif %}
- # 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 clean && \
- rm -rf /var/lib/apt/lists/*
- # Remove UID 1000 if it's called pn--this fixes the nikolaik image for ubuntu users
- RUN if getent passwd 1000 | grep -q pn; then userdel pn; fi
- # Create necessary directories
- RUN mkdir -p /openhands && \
- mkdir -p /openhands/logs && \
- mkdir -p /openhands/poetry
- # 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 Python and Poetry
- RUN /openhands/miniforge3/bin/mamba install conda-forge::poetry python=3.11 -y
- # ================================================================
- # END: Build Runtime Image from Scratch
- # ================================================================
- {% endif %}
- # ================================================================
- # START: Copy Project and Install/Update Dependencies
- # ================================================================
- RUN if [ -d /openhands/code ]; then rm -rf /openhands/code; fi
- COPY ./code /openhands/code
- # Below RUN command sets up the Python environment using Poetry,
- # installs project dependencies, and configures the container
- # for OpenHands development.
- # It creates and activates a virtual environment, installs necessary
- # tools like Playwright, sets up environment variables, and configures
- # the bash environment to ensure the correct Python interpreter and
- # virtual environment are used by default.
- 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 && \
- # Install project dependencies
- /openhands/miniforge3/bin/mamba run -n base 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 && \
- # 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 && \
- # Install extra dependencies if specified
- {{ extra_deps }} {% if extra_deps %} && {% endif %} \
- # Clear caches
- /openhands/miniforge3/bin/mamba run -n base 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
- # ================================================================
- # END: Copy Project and Install/Update Dependencies
- # ================================================================
|