Skip to content

Commit 559304c

Browse files
committed
[Build/CI] Revert back to Ubuntu 20.04, install python 3.12 with uv
Signed-off-by: Tyler Michael Smith <[email protected]>
1 parent be8921f commit 559304c

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

docker/Dockerfile

Lines changed: 22 additions & 29 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

@@ -79,30 +84,18 @@ ARG DEADSNAKES_MIRROR_URL
7984
ARG DEADSNAKES_GPGKEY_URL
8085
ARG GET_PIP_URL
8186

82-
# Install Python and other dependencies
87+
# Install system dependencies and uv, then create Python virtual environment
8388
RUN echo 'tzdata tzdata/Areas select America' | debconf-set-selections \
8489
&& echo 'tzdata tzdata/Zones/America select Los_Angeles' | debconf-set-selections \
8590
&& 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} \
91+
&& apt-get install -y ccache software-properties-common git curl sudo python3-pip \
92+
&& curl -LsSf https://astral.sh/uv/install.sh | sh \
93+
&& export PATH="$HOME/.local/bin:$PATH" \
94+
&& uv venv /opt/venv --python ${PYTHON_VERSION} \
95+
&& rm -f /usr/bin/python3 /usr/bin/python3-config /usr/bin/pip \
96+
&& ln -s /opt/venv/bin/python3 /usr/bin/python3 \
97+
&& ln -s /opt/venv/bin/python3-config /usr/bin/python3-config \
98+
&& ln -s /opt/venv/bin/pip /usr/bin/pip \
10699
&& python3 --version && python3 -m pip --version
107100

108101
ARG PIP_INDEX_URL UV_INDEX_URL
@@ -111,9 +104,9 @@ ARG PYTORCH_CUDA_INDEX_BASE_URL
111104
ARG PYTORCH_CUDA_NIGHTLY_INDEX_BASE_URL
112105
ARG PIP_KEYRING_PROVIDER UV_KEYRING_PROVIDER
113106

114-
# Install uv for faster pip installs
115-
RUN --mount=type=cache,target=/root/.cache/uv \
116-
python3 -m pip install uv
107+
# Activate virtual environment and add uv to PATH
108+
ENV PATH="/opt/venv/bin:/root/.local/bin:$PATH"
109+
ENV VIRTUAL_ENV="/opt/venv"
117110

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

148141
# cuda arch list used by torch
@@ -172,7 +165,7 @@ ENV UV_INDEX_STRATEGY="unsafe-best-match"
172165
ENV UV_LINK_MODE=copy
173166

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

178171
COPY . .
@@ -269,7 +262,7 @@ COPY requirements/lint.txt requirements/lint.txt
269262
COPY requirements/test.txt requirements/test.txt
270263
COPY requirements/dev.txt requirements/dev.txt
271264
RUN --mount=type=cache,target=/root/.cache/uv \
272-
uv pip install --system -r requirements/dev.txt \
265+
uv pip install --python /opt/venv/bin/python3 -r requirements/dev.txt \
273266
--extra-index-url ${PYTORCH_CUDA_INDEX_BASE_URL}/cu$(echo $CUDA_VERSION | cut -d. -f1,2 | tr -d '.')
274267
#################### DEV IMAGE ####################
275268

-8.42 KB
Loading

0 commit comments

Comments
 (0)