@@ -13,8 +13,13 @@ ARG PYTHON_VERSION=3.12
13
13
# private registries that use a different repository naming conventions.
14
14
#
15
15
# 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
18
23
# TODO: Restore to base image after FlashInfer AOT wheel fixed
19
24
ARG FINAL_BASE_IMAGE=nvidia/cuda:${CUDA_VERSION}-devel-ubuntu22.04
20
25
@@ -75,34 +80,19 @@ ARG TARGETPLATFORM
75
80
ARG INSTALL_KV_CONNECTORS=false
76
81
ENV DEBIAN_FRONTEND=noninteractive
77
82
78
- ARG DEADSNAKES_MIRROR_URL
79
- ARG DEADSNAKES_GPGKEY_URL
80
83
ARG GET_PIP_URL
81
84
82
- # Install Python and other dependencies
85
+ # Install system dependencies and uv, then create Python virtual environment
83
86
RUN echo 'tzdata tzdata/Areas select America' | debconf-set-selections \
84
87
&& echo 'tzdata tzdata/Zones/America select Los_Angeles' | debconf-set-selections \
85
88
&& 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 \
106
96
&& python3 --version && python3 -m pip --version
107
97
108
98
ARG PIP_INDEX_URL UV_INDEX_URL
@@ -111,9 +101,9 @@ ARG PYTORCH_CUDA_INDEX_BASE_URL
111
101
ARG PYTORCH_CUDA_NIGHTLY_INDEX_BASE_URL
112
102
ARG PIP_KEYRING_PROVIDER UV_KEYRING_PROVIDER
113
103
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"
117
107
118
108
# This timeout (in seconds) is necessary when installing some dependencies via uv since it's likely to time out
119
109
# Reference: https://github.com/astral-sh/uv/pull/1694
@@ -142,7 +132,7 @@ WORKDIR /workspace
142
132
COPY requirements/common.txt requirements/common.txt
143
133
COPY requirements/cuda.txt requirements/cuda.txt
144
134
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 \
146
136
--extra-index-url ${PYTORCH_CUDA_INDEX_BASE_URL}/cu$(echo $CUDA_VERSION | cut -d. -f1,2 | tr -d '.' )
147
137
148
138
# cuda arch list used by torch
@@ -172,7 +162,7 @@ ENV UV_INDEX_STRATEGY="unsafe-best-match"
172
162
ENV UV_LINK_MODE=copy
173
163
174
164
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 \
176
166
--extra-index-url ${PYTORCH_CUDA_INDEX_BASE_URL}/cu$(echo $CUDA_VERSION | cut -d. -f1,2 | tr -d '.' )
177
167
178
168
COPY . .
@@ -269,7 +259,7 @@ COPY requirements/lint.txt requirements/lint.txt
269
259
COPY requirements/test.txt requirements/test.txt
270
260
COPY requirements/dev.txt requirements/dev.txt
271
261
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 \
273
263
--extra-index-url ${PYTORCH_CUDA_INDEX_BASE_URL}/cu$(echo $CUDA_VERSION | cut -d. -f1,2 | tr -d '.' )
274
264
# ################### DEV IMAGE ####################
275
265
0 commit comments