Skip to content

Commit 0fca25f

Browse files
committed
feat: use uv as a pip alternative
1 parent f7e223c commit 0fca25f

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- [Improvement] Use [`uv`](https://github.com/astral-sh/uv) as a replacement for
2+
pip for installing and resolving packages. uv provides a faster package
3+
resolution and installation steps, reducing the python-requirements layer
4+
build time by about ~2-5x.
5+
6+
For the most part uv is a drop-in replacement for main pip functionality with
7+
the exception of VCS editable requirements. The main use of VCS editable
8+
requirements is to copy all the files in the VCS repository when installing
9+
the package. This can be avoided by making proper use of a `MANIFEST.in` file.
10+
It's possible to also use the `PIP_COMMAND=pip` build argument to keep using
11+
pip.

tutor/templates/build/openedx/Dockerfile

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
99
apt update && \
1010
apt install -y build-essential curl git language-pack-en
1111
ENV LC_ALL=en_US.UTF-8
12+
13+
COPY --from=ghcr.io/astral-sh/uv:0.4.21 /uv /usr/local/bin/uv
14+
ARG PIP_COMMAND="uv pip"
15+
1216
{{ patch("openedx-dockerfile-minimal") }}
1317

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

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

7885
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
7986
--mount=type=cache,target=/var/lib/apt,sharing=locked \
@@ -91,11 +98,11 @@ RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
9198
# Install base requirements
9299
RUN --mount=type=bind,from=edx-platform,source=/requirements/edx/base.txt,target=/openedx/edx-platform/requirements/edx/base.txt \
93100
--mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
94-
pip install -r /openedx/edx-platform/requirements/edx/base.txt
101+
$PIP_COMMAND install -r /openedx/edx-platform/requirements/edx/base.txt
95102

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

106113
# Install scorm xblock
107-
RUN pip install "openedx-scorm-xblock>=18.0.0,<19.0.0"
114+
RUN $PIP_COMMAND install "openedx-scorm-xblock>=18.0.0,<19.0.0"
108115

109116
{% for extra_requirements in OPENEDX_EXTRA_PIP_REQUIREMENTS %}
110117
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
111-
pip install '{{ extra_requirements }}'
118+
$PIP_COMMAND install '{{ extra_requirements }}'
112119
{% endfor %}
113120

114121
###### Install nodejs with nodeenv in /openedx/nodeenv
115122
FROM python AS nodejs-requirements
123+
ENV VIRTUAL_ENV=/openedx/venv/
116124
ENV PATH=/openedx/nodeenv/bin:/openedx/venv/bin:${PATH}
117125

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

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

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

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

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

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

275283
# Add ipdb as default PYTHONBREAKPOINT

0 commit comments

Comments
 (0)