[Docker] Compile Python bytecode at image build time (#55422)

Signed-off-by: Nils Matteson <nilsmatteson@icloud.com>
Co-authored-by: Simon Mo <simon.mo@hey.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Nils Matteson
2026-10-01 02:20:17 +00:00
committed by GitHub
co-authored by Simon Mo mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 7314360c9e
commit 76d3929916
8 changed files with 9 additions and 0 deletions
+1
View File
@@ -906,6 +906,7 @@ ENV UV_INDEX_STRATEGY="unsafe-best-match"
ENV UV_LINK_MODE=copy
ENV UV_PYTHON_INSTALL_DIR=/opt/uv/python
ENV UV_CACHE_DIR=/opt/uv/cache
ENV UV_COMPILE_BYTECODE=1
RUN mkdir -p "${UV_PYTHON_INSTALL_DIR}" "${UV_CACHE_DIR}" \
&& chgrp -R 0 /opt/uv \
&& chmod -R g+rwX,a+rX /opt/uv
+2
View File
@@ -138,6 +138,8 @@ ENV TARGETARCH=${TARGETARCH}
######################### COMMON BASE IMAGE + PYTHON DEPS #########################
FROM base-common AS base-common-pydeps
ENV UV_COMPILE_BYTECODE=1
# PyTorch provides its own indexes for standard and nightly builds.
# PYTORCH_NIGHTLY=1 builds the CPU image against torch nightly (parity with the
# GPU torch-nightly lane); default 0 keeps the pinned release CPU build.
+1
View File
@@ -22,6 +22,7 @@ ENV HOME=/root \
RUSTUP_HOME=/root/.rustup \
UV_CACHE_DIR=$HOME/.cache/uv \
PATH=/root/.cargo/bin:/root/.rustup/bin:${VIRTUAL_ENV}/bin:$PATH
ENV UV_COMPILE_BYTECODE=1
RUN echo "DEBUG: VLLM_VERSION=${VLLM_VERSION}"
RUN --mount=type=cache,target=/var/cache/dnf \
+1
View File
@@ -898,6 +898,7 @@ COPY --from=test_smoke /vllm-smoke-ok /
# -----------------------
# Final vLLM image
FROM mori_base AS final_common
ENV UV_COMPILE_BYTECODE=1
RUN python3 -m pip install --upgrade pip && rm -rf /var/lib/apt/lists/*
+1
View File
@@ -920,6 +920,7 @@ COPY --from=test_smoke /vllm-smoke-ok /
# -----------------------
# Final vLLM image
FROM mori_base AS final_common
ENV UV_COMPILE_BYTECODE=1
RUN python3 -m pip install --upgrade pip && rm -rf /var/lib/apt/lists/*
+1
View File
@@ -655,6 +655,7 @@ RUN mkdir src && mv vllm src/vllm
# -----------------------
# Final vLLM image
FROM mori_base AS final
ENV UV_COMPILE_BYTECODE=1
RUN python3 -m pip install --upgrade pip && rm -rf /var/lib/apt/lists/*
+1
View File
@@ -196,6 +196,7 @@ ARG PIP_EXTRA_INDEX_URL="https://download.pytorch.org/whl/cpu"
ENV LD_LIBRARY_PATH="/opt/vllm/lib64/python${PYTHON_VERSION}/site-packages/torch/lib:/usr/local/lib:/opt/rh/gcc-toolset-14/root/usr/lib64:$LD_LIBRARY_PATH"
ENV C_INCLUDE_PATH="/usr/local/include:$C_INCLUDE_PATH"
ENV UV_LINK_MODE=copy
ENV UV_COMPILE_BYTECODE=1
ENV CARGO_HOME=/root/.cargo
ENV RUSTUP_HOME=/root/.rustup
ENV GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
+1
View File
@@ -205,6 +205,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \
/tmp/ucx_source /tmp/nixl_source
FROM vllm-base AS vllm-openai
ENV UV_COMPILE_BYTECODE=1
# Must match the ucx-nixl-build stage above: ARG does not cross stages, so a stale
# value here installs a meta package that disagrees with the wheel built there.