Skip to content

Commit a0fd1a5

Browse files
committed
update
Signed-off-by: Tyler Michael Smith <[email protected]>
1 parent 159b581 commit a0fd1a5

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

docker/Dockerfile

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,19 @@ ENV DEBIAN_FRONTEND=noninteractive
8282

8383
ARG GET_PIP_URL
8484

85-
# Install system dependencies and uv, then create Python virtual environment
85+
# Install system dependencies and uv, then install Python via uv
8686
RUN echo 'tzdata tzdata/Areas select America' | debconf-set-selections \
8787
&& echo 'tzdata tzdata/Zones/America select Los_Angeles' | debconf-set-selections \
8888
&& apt-get update -y \
89-
&& apt-get install -y ccache software-properties-common git curl sudo python3-pip \
89+
&& apt-get install -y ccache software-properties-common git curl sudo \
9090
&& curl -LsSf https://astral.sh/uv/install.sh | sh \
91-
&& $HOME/.local/bin/uv venv /opt/venv --python ${PYTHON_VERSION} \
92-
&& rm -f /usr/bin/python3 /usr/bin/python3-config /usr/bin/pip \
93-
&& ln -s /opt/venv/bin/python3 /usr/bin/python3 \
94-
&& ln -s /opt/venv/bin/python3-config /usr/bin/python3-config \
95-
&& ln -s /opt/venv/bin/pip /usr/bin/pip \
91+
&& $HOME/.local/bin/uv python install ${PYTHON_VERSION} \
92+
&& PYTHON_PATH=$(ls -d $HOME/.local/share/uv/python/cpython-${PYTHON_VERSION}*/bin | head -1) \
93+
&& update-alternatives --install /usr/bin/python3 python3 ${PYTHON_PATH}/python3 1 \
94+
&& update-alternatives --set python3 ${PYTHON_PATH}/python3 \
95+
&& update-alternatives --install /usr/bin/pip pip ${PYTHON_PATH}/pip 1 \
96+
&& update-alternatives --set pip ${PYTHON_PATH}/pip \
97+
&& ln -sf ${PYTHON_PATH}/python3-config /usr/bin/python3-config \
9698
&& python3 --version && python3 -m pip --version
9799

98100
ARG PIP_INDEX_URL UV_INDEX_URL
@@ -101,16 +103,20 @@ ARG PYTORCH_CUDA_INDEX_BASE_URL
101103
ARG PYTORCH_CUDA_NIGHTLY_INDEX_BASE_URL
102104
ARG PIP_KEYRING_PROVIDER UV_KEYRING_PROVIDER
103105

104-
# Activate virtual environment and add uv to PATH
105-
ENV PATH="/opt/venv/bin:/root/.local/bin:$PATH"
106-
ENV VIRTUAL_ENV="/opt/venv"
106+
# Add uv to PATH
107+
ENV PATH="/root/.local/bin:$PATH"
107108

108109
# This timeout (in seconds) is necessary when installing some dependencies via uv since it's likely to time out
109110
# Reference: https://github.com/astral-sh/uv/pull/1694
110111
ENV UV_HTTP_TIMEOUT=500
111112
ENV UV_INDEX_STRATEGY="unsafe-best-match"
112113
# Use copy mode to avoid hardlink failures with Docker cache mounts
113114
ENV UV_LINK_MODE=copy
115+
# Ensure uv uses python3 (which we set up with update-alternatives)
116+
ENV UV_PYTHON=python3
117+
# Allow installing into uv-managed Python
118+
ENV UV_PYTHON_PREFERENCE=only-system
119+
ENV UV_SYSTEM_PYTHON=1
114120

115121
# Upgrade to GCC 10 to avoid https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92519
116122
# as it was causing spam when compiling the CUTLASS kernels
@@ -132,7 +138,7 @@ WORKDIR /workspace
132138
COPY requirements/common.txt requirements/common.txt
133139
COPY requirements/cuda.txt requirements/cuda.txt
134140
RUN --mount=type=cache,target=/root/.cache/uv \
135-
uv pip install --python /opt/venv/bin/python3 -r requirements/cuda.txt \
141+
uv pip install --system -r requirements/cuda.txt \
136142
--extra-index-url ${PYTORCH_CUDA_INDEX_BASE_URL}/cu$(echo $CUDA_VERSION | cut -d. -f1,2 | tr -d '.')
137143

138144
# cuda arch list used by torch
@@ -162,7 +168,7 @@ ENV UV_INDEX_STRATEGY="unsafe-best-match"
162168
ENV UV_LINK_MODE=copy
163169

164170
RUN --mount=type=cache,target=/root/.cache/uv \
165-
uv pip install --python /opt/venv/bin/python3 -r requirements/build.txt \
171+
uv pip install --system -r requirements/build.txt \
166172
--extra-index-url ${PYTORCH_CUDA_INDEX_BASE_URL}/cu$(echo $CUDA_VERSION | cut -d. -f1,2 | tr -d '.')
167173

168174
COPY . .
@@ -259,7 +265,7 @@ COPY requirements/lint.txt requirements/lint.txt
259265
COPY requirements/test.txt requirements/test.txt
260266
COPY requirements/dev.txt requirements/dev.txt
261267
RUN --mount=type=cache,target=/root/.cache/uv \
262-
uv pip install --python /opt/venv/bin/python3 -r requirements/dev.txt \
268+
uv pip install --system -r requirements/dev.txt \
263269
--extra-index-url ${PYTORCH_CUDA_INDEX_BASE_URL}/cu$(echo $CUDA_VERSION | cut -d. -f1,2 | tr -d '.')
264270
#################### DEV IMAGE ####################
265271

0 commit comments

Comments
 (0)