Dockerfile.j2 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. {% if skip_init %}
  2. FROM {{ base_image }}
  3. {% else %}
  4. # ================================================================
  5. # START: Build Runtime Image from Scratch
  6. # ================================================================
  7. FROM {{ base_image }}
  8. {% if 'ubuntu' in base_image and (base_image.endswith(':latest') or base_image.endswith(':24.04')) %}
  9. {% set LIBGL_MESA = 'libgl1' %}
  10. {% else %}
  11. {% set LIBGL_MESA = 'libgl1-mesa-glx' %}
  12. {% endif %}
  13. # Install necessary packages and clean up in one layer
  14. RUN apt-get update && \
  15. apt-get install -y wget sudo apt-utils {{ LIBGL_MESA }} libasound2-plugins git && \
  16. apt-get clean && \
  17. rm -rf /var/lib/apt/lists/*
  18. # Create necessary directories
  19. RUN mkdir -p /openhands && \
  20. mkdir -p /openhands/logs && \
  21. mkdir -p /openhands/poetry
  22. ENV POETRY_VIRTUALENVS_PATH=/openhands/poetry
  23. RUN if [ ! -d /openhands/miniforge3 ]; then \
  24. wget --progress=bar:force -O Miniforge3.sh "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" && \
  25. bash Miniforge3.sh -b -p /openhands/miniforge3 && \
  26. rm Miniforge3.sh && \
  27. chmod -R g+w /openhands/miniforge3 && \
  28. bash -c ". /openhands/miniforge3/etc/profile.d/conda.sh && conda config --set changeps1 False && conda config --append channels conda-forge"; \
  29. fi
  30. # Install Python and Poetry
  31. RUN /openhands/miniforge3/bin/mamba install conda-forge::poetry python=3.11 -y
  32. # ================================================================
  33. # END: Build Runtime Image from Scratch
  34. # ================================================================
  35. {% endif %}
  36. # ================================================================
  37. # START: Copy Project and Install/Update Dependencies
  38. # ================================================================
  39. RUN if [ -d /openhands/code ]; then rm -rf /openhands/code; fi
  40. COPY ./code /openhands/code
  41. # Install/Update Dependencies
  42. # 1. Install pyproject.toml via poetry
  43. # 2. Install playwright and chromium
  44. # 3. Clear poetry, apt, mamba caches
  45. RUN cd /openhands/code && \
  46. /openhands/miniforge3/bin/mamba run -n base poetry env use python3.11 && \
  47. /openhands/miniforge3/bin/mamba run -n base poetry install --only main,runtime --no-interaction --no-root && \
  48. apt-get update && \
  49. /openhands/miniforge3/bin/mamba run -n base poetry run pip install playwright && \
  50. /openhands/miniforge3/bin/mamba run -n base poetry run playwright install --with-deps chromium && \
  51. export OD_INTERPRETER_PATH=$(/openhands/miniforge3/bin/mamba run -n base poetry run python -c "import sys; print(sys.executable)") && \
  52. {{ extra_deps }} {% if extra_deps %} && {% endif %} \
  53. /openhands/miniforge3/bin/mamba run -n base poetry cache clear --all . && \
  54. {% if not skip_init %}chmod -R g+rws /openhands/poetry && {% endif %} \
  55. apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
  56. /openhands/miniforge3/bin/mamba clean --all
  57. # ================================================================
  58. # END: Copy Project and Install/Update Dependencies
  59. # ================================================================