Skip to content

Commit

Permalink
feat: use uv as a pip alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
MoisesGSalas committed Oct 15, 2024
1 parent f7e223c commit 0fca25f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
11 changes: 11 additions & 0 deletions changelog.d/20241015_113438_moises.gonzalez_uv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- [Improvement] Use [`uv`](https://github.com/astral-sh/uv) as a replacement for
pip for installing and resolving packages. uv provides a faster package
resolution and installation steps, reducing the python-requirements layer
build time by about ~2-5x.

For the most part uv is a drop-in replacement for main pip functionality with
the exception of VCS editable requirements. The main use of VCS editable
requirements is to copy all the files in the VCS repository when installing
the package. This can be avoided by making proper use of a `MANIFEST.in` file.
It's possible to also use the `PIP_COMMAND=pip` build argument to keep using
pip.
28 changes: 18 additions & 10 deletions tutor/templates/build/openedx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
apt update && \
apt install -y build-essential curl git language-pack-en
ENV LC_ALL=en_US.UTF-8

COPY --from=ghcr.io/astral-sh/uv:0.4.21 /uv /usr/local/bin/uv
ARG PIP_COMMAND="uv pip"

{{ patch("openedx-dockerfile-minimal") }}

###### Install python with pyenv in /opt/pyenv and create virtualenv in /openedx/venv
Expand Down Expand Up @@ -53,6 +57,8 @@ RUN git config --global user.email "[email protected]" \
# Patches in nightly node
{%- else %}
# Patches in non-nightly mode
RUN curl -fsSL https://github.com/eduNEXT/edx-platform/commit/5bc067474ce557fe57aed29174d7f81873be5cf8.patch | git am

{%- endif %}

{# Example: RUN curl -fsSL https://github.com/openedx/edx-platform/commit/<GITSHA1>.patch | git am #}
Expand All @@ -74,6 +80,7 @@ FROM python AS python-requirements
ENV PATH=/openedx/venv/bin:${PATH}
ENV VIRTUAL_ENV=/openedx/venv/
ENV XDG_CACHE_HOME=/openedx/.cache
ENV UV_CACHE_DIR=$XDG_CACHE_HOME/pip

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
Expand All @@ -91,11 +98,11 @@ RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
# Install base requirements
RUN --mount=type=bind,from=edx-platform,source=/requirements/edx/base.txt,target=/openedx/edx-platform/requirements/edx/base.txt \
--mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install -r /openedx/edx-platform/requirements/edx/base.txt
$PIP_COMMAND install -r /openedx/edx-platform/requirements/edx/base.txt

# Install extra requirements
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install \
$PIP_COMMAND install \
# Use redis as a django cache https://pypi.org/project/django-redis/
django-redis==5.4.0 \
# uwsgi server https://pypi.org/project/uWSGI/
Expand All @@ -104,20 +111,21 @@ RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
{{ patch("openedx-dockerfile-post-python-requirements") }}

# Install scorm xblock
RUN pip install "openedx-scorm-xblock>=18.0.0,<19.0.0"
RUN $PIP_COMMAND install "openedx-scorm-xblock>=18.0.0,<19.0.0"

{% for extra_requirements in OPENEDX_EXTRA_PIP_REQUIREMENTS %}
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install '{{ extra_requirements }}'
$PIP_COMMAND install '{{ extra_requirements }}'
{% endfor %}

###### Install nodejs with nodeenv in /openedx/nodeenv
FROM python AS nodejs-requirements
ENV VIRTUAL_ENV=/openedx/venv/
ENV PATH=/openedx/nodeenv/bin:/openedx/venv/bin:${PATH}

# Install nodeenv with the version provided by edx-platform
# https://github.com/openedx/edx-platform/blob/master/requirements/edx/base.txt
RUN pip install nodeenv==1.8.0
RUN $PIP_COMMAND install nodeenv==1.8.0
RUN nodeenv /openedx/nodeenv --node=18.20.1 --prebuilt

# Install nodejs requirements
Expand Down Expand Up @@ -174,12 +182,12 @@ WORKDIR /openedx/edx-platform
{# Install auto-mounted directories as Python packages. #}
{% for name in iter_mounted_directories(MOUNTS, "openedx") %}
COPY --link --chown=$APP_USER_ID:$APP_USER_ID --from=mnt-{{ name }} / /mnt/{{ name }}
RUN pip install -e "/mnt/{{ name }}"
RUN $PIP_COMMAND install -e "/mnt/{{ name }}"
{% endfor %}

# We install edx-platform here because it creates an egg-info folder in the current
# repo. We need both the source code and the virtualenv to run this command.
RUN pip install -e .
RUN $PIP_COMMAND install -e .

# Create folder that will store lms/cms.env.yml files, as well as
# the tutor-specific settings files.
Expand Down Expand Up @@ -260,16 +268,16 @@ USER app

# Install dev python requirements
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install -r requirements/edx/development.txt
$PIP_COMMAND install -r requirements/edx/development.txt
# https://pypi.org/project/ipdb/
# https://pypi.org/project/ipython (>=Python 3.10 started with 8.20)
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install ipdb==0.13.13 ipython==8.24.0
$PIP_COMMAND install ipdb==0.13.13 ipython==8.24.0

{# Re-install mounted requirements, otherwise they will be superseded by upstream reqs #}
{% for name in iter_mounted_directories(MOUNTS, "openedx") %}
COPY --link --chown=$APP_USER_ID:$APP_USER_ID --from=mnt-{{ name }} / /mnt/{{ name }}
RUN pip install -e "/mnt/{{ name }}"
RUN $PIP_COMMAND install -e "/mnt/{{ name }}"
{% endfor %}

# Add ipdb as default PYTHONBREAKPOINT
Expand Down

0 comments on commit 0fca25f

Please sign in to comment.