Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
FROM python:3.12-slim

# Copy uv from the official uv Docker image (pinned version for reproducibility)
COPY --from=ghcr.io/astral-sh/uv:0.8.3 /uv /uvx /bin/

# Set environment variables for uv
ENV UV_SYSTEM_PYTHON=1

WORKDIR /app

# hadolint ignore=DL3008
Expand All @@ -8,19 +14,28 @@ RUN --mount=type=cache,target=/var/lib/apt --mount=type=cache,target=/var/cache/
apt-get install -y --no-install-recommends git && \
rm -rf /var/lib/apt/lists/*

# Copy the pyproject.toml and the git metadata first (leverage Docker layer caching)
COPY pyproject.toml .
# Copy the git metadata and source code
COPY .git/ .git/

# Copy the rest of the application code
COPY src/ src/

ARG INSTALL_OPTIONAL_DEP=semantic_cache,lmcache
ENV INSTALL_OPTIONAL_DEP=${INSTALL_OPTIONAL_DEP}

# Install dependencies (use cache, and delete after install, to speed up the build)
RUN pip install --upgrade --no-cache-dir pip setuptools_scm && \
pip install --no-cache-dir .[$INSTALL_OPTIONAL_DEP]
# Install dependencies first (for better Docker layer caching)
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
if [ -n "$INSTALL_OPTIONAL_DEP" ]; then \
OLD_IFS="$IFS"; IFS=','; \
set --; \
for dep in $INSTALL_OPTIONAL_DEP; do \
[ -n "$dep" ] && set -- "$@" --extra "$dep"; \
done; \
IFS="$OLD_IFS"; \
uv sync --locked "$@"; \
else \
uv sync --locked; \
fi
Comment on lines +28 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The shell script for handling optional dependencies is vulnerable to filename expansion (globbing) if a dependency name contains a wildcard character (e.g., *). It's safer to disable globbing with set -f during word splitting. I've also added comments to improve readability.

    if [ -n "$INSTALL_OPTIONAL_DEP" ]; then
        # Prevent globbing
        set -f;
        OLD_IFS="$IFS"; IFS=',';
        set --;
        for dep in $INSTALL_OPTIONAL_DEP; do
            [ -n "$dep" ] && set -- "$@" --extra "$dep";
        done;
        IFS="$OLD_IFS";
        # Re-enable globbing
        set +f;
        uv sync --locked "$@";
    else
        uv sync --locked;
    fi


# Set the entrypoint
ENTRYPOINT ["vllm-router"]
Expand Down
Loading