mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
Feat: Divided docker layer to make it easier to cache (#4313)
Co-authored-by: Xingyao Wang <xingyao@all-hands.dev>
This commit is contained in:
@@ -4,10 +4,13 @@ FROM {{ base_image }}
|
||||
ENV POETRY_VIRTUALENVS_PATH=/openhands/poetry
|
||||
ENV MAMBA_ROOT_PREFIX=/openhands/micromamba
|
||||
|
||||
{% if not skip_init %}
|
||||
{% if build_from_scratch %}
|
||||
# ================================================================
|
||||
# START: Build Runtime Image from Scratch
|
||||
# ================================================================
|
||||
# This is used in cases where the base image is something more generic like nikolaik/python-nodejs
|
||||
# rather than the current OpenHands release
|
||||
|
||||
{% if 'ubuntu' in base_image and (base_image.endswith(':latest') or base_image.endswith(':24.04')) %}
|
||||
{% set LIBGL_MESA = 'libgl1' %}
|
||||
{% else %}
|
||||
@@ -38,24 +41,14 @@ RUN mkdir -p /openhands/micromamba/bin && \
|
||||
RUN /openhands/micromamba/bin/micromamba create -n openhands -y && \
|
||||
/openhands/micromamba/bin/micromamba install -n openhands -c conda-forge poetry python=3.12 -y
|
||||
|
||||
# ================================================================
|
||||
# END: Build Runtime Image from Scratch
|
||||
# ================================================================
|
||||
{% endif %}
|
||||
# Create a clean openhands directory including only the pyproject.toml, poetry.lock and openhands/__init__.py
|
||||
RUN \
|
||||
if [ -d /openhands/code ]; then rm -rf /openhands/code; fi && \
|
||||
mkdir -p /openhands/code/openhands && \
|
||||
touch /openhands/code/openhands/__init__.py
|
||||
COPY ./code/pyproject.toml ./code/poetry.lock /openhands/code
|
||||
|
||||
# ================================================================
|
||||
# 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.
|
||||
# Install all dependencies
|
||||
WORKDIR /openhands/code
|
||||
RUN \
|
||||
/openhands/micromamba/bin/micromamba config set changeps1 False && \
|
||||
@@ -70,16 +63,26 @@ RUN \
|
||||
/openhands/micromamba/bin/micromamba run -n openhands poetry run playwright install --with-deps chromium && \
|
||||
# Set environment variables
|
||||
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/micromamba/bin/micromamba run -n openhands poetry cache clear --all . && \
|
||||
# Set permissions
|
||||
{% if not skip_init %}chmod -R g+rws /openhands/poetry && {% endif %} \
|
||||
chmod -R g+rws /openhands/poetry && \
|
||||
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/micromamba/bin/micromamba clean --all
|
||||
|
||||
# ================================================================
|
||||
# END: Copy Project and Install/Update Dependencies
|
||||
# END: Build Runtime Image from Scratch
|
||||
# ================================================================
|
||||
{% endif %}
|
||||
|
||||
# ================================================================
|
||||
# Copy Project source files
|
||||
# ================================================================
|
||||
RUN if [ -d /openhands/code/openhands ]; then rm -rf /openhands/code/openhands; fi
|
||||
COPY ./code/pyproject.toml ./code/poetry.lock /openhands/code
|
||||
COPY ./code/openhands /openhands/code/openhands
|
||||
|
||||
# Install extra dependencies if specified
|
||||
{% if extra_deps %}RUN {{ extra_deps }} {% endif %}
|
||||
|
||||
Reference in New Issue
Block a user