Skip to content

Commit f71952c

Browse files
tlrmchlsmthsimon-mo
andcommitted
[Build/CI] Revert back to Ubuntu 20.04, install python 3.12 with uv (#26103)
Signed-off-by: Tyler Michael Smith <[email protected]> Co-authored-by: Simon Mo <[email protected]> Signed-off-by: simon-mo <[email protected]>
1 parent d100776 commit f71952c

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
lines changed

docker/Dockerfile

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ ARG PYTHON_VERSION=3.12
1313
# private registries that use a different repository naming conventions.
1414
#
1515
# Example:
16-
# docker build --build-arg BUILD_BASE_IMAGE=registry.acme.org/mirror/nvidia/cuda:${CUDA_VERSION}-devel-ubuntu22.04
17-
ARG BUILD_BASE_IMAGE=nvidia/cuda:${CUDA_VERSION}-devel-ubuntu22.04
16+
# docker build --build-arg BUILD_BASE_IMAGE=registry.acme.org/mirror/nvidia/cuda:${CUDA_VERSION}-devel-ubuntu20.04
17+
18+
# Important: We build with an old version of Ubuntu to maintain broad
19+
# compatibility with other Linux OSes. The main reason for this is that the
20+
# glibc version is baked into the distro, and binaries built with one glibc
21+
# version are not backwards compatible with OSes that use an earlier version.
22+
ARG BUILD_BASE_IMAGE=nvidia/cuda:${CUDA_VERSION}-devel-ubuntu20.04
1823
# TODO: Restore to base image after FlashInfer AOT wheel fixed
1924
ARG FINAL_BASE_IMAGE=nvidia/cuda:${CUDA_VERSION}-devel-ubuntu22.04
2025

@@ -75,34 +80,19 @@ ARG TARGETPLATFORM
7580
ARG INSTALL_KV_CONNECTORS=false
7681
ENV DEBIAN_FRONTEND=noninteractive
7782

78-
ARG DEADSNAKES_MIRROR_URL
79-
ARG DEADSNAKES_GPGKEY_URL
8083
ARG GET_PIP_URL
8184

82-
# Install Python and other dependencies
85+
# Install system dependencies and uv, then create Python virtual environment
8386
RUN echo 'tzdata tzdata/Areas select America' | debconf-set-selections \
8487
&& echo 'tzdata tzdata/Zones/America select Los_Angeles' | debconf-set-selections \
8588
&& apt-get update -y \
86-
&& apt-get install -y ccache software-properties-common git curl sudo \
87-
&& if [ ! -z ${DEADSNAKES_MIRROR_URL} ] ; then \
88-
if [ ! -z "${DEADSNAKES_GPGKEY_URL}" ] ; then \
89-
mkdir -p -m 0755 /etc/apt/keyrings ; \
90-
curl -L ${DEADSNAKES_GPGKEY_URL} | gpg --dearmor > /etc/apt/keyrings/deadsnakes.gpg ; \
91-
sudo chmod 644 /etc/apt/keyrings/deadsnakes.gpg ; \
92-
echo "deb [signed-by=/etc/apt/keyrings/deadsnakes.gpg] ${DEADSNAKES_MIRROR_URL} $(lsb_release -cs) main" > /etc/apt/sources.list.d/deadsnakes.list ; \
93-
fi ; \
94-
else \
95-
for i in 1 2 3; do \
96-
add-apt-repository -y ppa:deadsnakes/ppa && break || \
97-
{ echo "Attempt $i failed, retrying in 5s..."; sleep 5; }; \
98-
done ; \
99-
fi \
100-
&& apt-get update -y \
101-
&& apt-get install -y python${PYTHON_VERSION} python${PYTHON_VERSION}-dev python${PYTHON_VERSION}-venv \
102-
&& update-alternatives --install /usr/bin/python3 python3 /usr/bin/python${PYTHON_VERSION} 1 \
103-
&& update-alternatives --set python3 /usr/bin/python${PYTHON_VERSION} \
104-
&& ln -sf /usr/bin/python${PYTHON_VERSION}-config /usr/bin/python3-config \
105-
&& curl -sS ${GET_PIP_URL} | python${PYTHON_VERSION} \
89+
&& apt-get install -y ccache software-properties-common git curl sudo python3-pip \
90+
&& 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 \
10696
&& python3 --version && python3 -m pip --version
10797

10898
ARG PIP_INDEX_URL UV_INDEX_URL
@@ -111,9 +101,9 @@ ARG PYTORCH_CUDA_INDEX_BASE_URL
111101
ARG PYTORCH_CUDA_NIGHTLY_INDEX_BASE_URL
112102
ARG PIP_KEYRING_PROVIDER UV_KEYRING_PROVIDER
113103

114-
# Install uv for faster pip installs
115-
RUN --mount=type=cache,target=/root/.cache/uv \
116-
python3 -m pip install uv
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"
117107

118108
# This timeout (in seconds) is necessary when installing some dependencies via uv since it's likely to time out
119109
# Reference: https://github.com/astral-sh/uv/pull/1694
@@ -142,7 +132,7 @@ WORKDIR /workspace
142132
COPY requirements/common.txt requirements/common.txt
143133
COPY requirements/cuda.txt requirements/cuda.txt
144134
RUN --mount=type=cache,target=/root/.cache/uv \
145-
uv pip install --system -r requirements/cuda.txt \
135+
uv pip install --python /opt/venv/bin/python3 -r requirements/cuda.txt \
146136
--extra-index-url ${PYTORCH_CUDA_INDEX_BASE_URL}/cu$(echo $CUDA_VERSION | cut -d. -f1,2 | tr -d '.')
147137

148138
# cuda arch list used by torch
@@ -172,7 +162,7 @@ ENV UV_INDEX_STRATEGY="unsafe-best-match"
172162
ENV UV_LINK_MODE=copy
173163

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

178168
COPY . .
@@ -269,7 +259,7 @@ COPY requirements/lint.txt requirements/lint.txt
269259
COPY requirements/test.txt requirements/test.txt
270260
COPY requirements/dev.txt requirements/dev.txt
271261
RUN --mount=type=cache,target=/root/.cache/uv \
272-
uv pip install --system -r requirements/dev.txt \
262+
uv pip install --python /opt/venv/bin/python3 -r requirements/dev.txt \
273263
--extra-index-url ${PYTORCH_CUDA_INDEX_BASE_URL}/cu$(echo $CUDA_VERSION | cut -d. -f1,2 | tr -d '.')
274264
#################### DEV IMAGE ####################
275265

-8.42 KB
Loading

0 commit comments

Comments
 (0)