From b6743c655ed24ac7f82a971a134d200148e4ffc6 Mon Sep 17 00:00:00 2001 From: Arthur Cheng Date: Fri, 6 Jun 2025 07:19:52 +0000 Subject: [PATCH 1/2] Add docker file for router build --- docker/Dockerfile.router | 76 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 docker/Dockerfile.router diff --git a/docker/Dockerfile.router b/docker/Dockerfile.router new file mode 100644 index 00000000000..bb9f75b3696 --- /dev/null +++ b/docker/Dockerfile.router @@ -0,0 +1,76 @@ +######################## BASE IMAGE ########################## +FROM ubuntu:24.04 AS base + +ARG PYTHON_VERSION=3.12 + +# set the environment variables +ENV PATH="/root/.local/bin:${PATH}" +ENV DEBIAN_FRONTEND=noninteractive + +# uv environment variables +ENV UV_HTTP_TIMEOUT=500 +ENV VIRTUAL_ENV="/opt/venv" +ENV UV_PYTHON_INSTALL_DIR=/opt/uv/python +ENV UV_INDEX_STRATEGY="unsafe-best-match" +ENV UV_LINK_MODE="copy" +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + + +# install dependencies +RUN echo 'tzdata tzdata/Areas select America' | debconf-set-selections \ + && echo 'tzdata tzdata/Zones/America select Los_Angeles' | debconf-set-selections \ + && apt update -y \ + && apt install -y curl \ + && rm -rf /var/lib/apt/lists/* \ + && apt clean + +# install uv +RUN curl -LsSf https://astral.sh/uv/install.sh | sh + +# install python +RUN uv venv --python ${PYTHON_VERSION} --seed ${VIRTUAL_ENV} + +######################### BUILD IMAGE ######################### +FROM base AS build-image + +# set the environment variables +ENV PATH="/root/.cargo/bin:${PATH}" + +# install dependencies +RUN apt update -y \ + && apt install -y git build-essential libssl-dev pkg-config \ + && rm -rf /var/lib/apt/lists/* \ + && apt clean + +# install rustup from rustup.rs +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ + && rustc --version && cargo --version + +# pull the github repository +RUN cd /opt \ + && git clone --depth=1 https://github.com/sgl-project/sglang.git \ + && cd /opt/sglang \ + && git checkout main + +# working directory +WORKDIR /opt/sglang/sgl-router + +# build the rust dependencies +RUN cargo build \ + && uv build \ + && rm -rf /root/.cache + +######################### ROUTER IMAGE ######################### +FROM base AS router-image + +# Copy the built package from the build image +COPY --from=build-image /opt/sglang/sgl-router/dist/*.whl dist/ + +# Build the package and install +RUN uv pip install --force-reinstall dist/*.whl + +# Clean up unnecessary files to reduce the image size +RUN rm -rf /root/.cache + +# Set the entrypoint to the main command +ENTRYPOINT ["python3", "-m", "sglang_router.launch_router"] From 157f6443b55a3cd7ae26b8aab9b85dcf14e89fc4 Mon Sep 17 00:00:00 2001 From: Arthur Cheng Date: Fri, 6 Jun 2025 07:45:00 +0000 Subject: [PATCH 2/2] address comments from gemini --- docker/Dockerfile.router | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docker/Dockerfile.router b/docker/Dockerfile.router index bb9f75b3696..07633e50230 100644 --- a/docker/Dockerfile.router +++ b/docker/Dockerfile.router @@ -11,7 +11,6 @@ ENV DEBIAN_FRONTEND=noninteractive ENV UV_HTTP_TIMEOUT=500 ENV VIRTUAL_ENV="/opt/venv" ENV UV_PYTHON_INSTALL_DIR=/opt/uv/python -ENV UV_INDEX_STRATEGY="unsafe-best-match" ENV UV_LINK_MODE="copy" ENV PATH="$VIRTUAL_ENV/bin:$PATH" @@ -33,6 +32,8 @@ RUN uv venv --python ${PYTHON_VERSION} --seed ${VIRTUAL_ENV} ######################### BUILD IMAGE ######################### FROM base AS build-image +ARG SGLANG_REPO_REF=main + # set the environment variables ENV PATH="/root/.cargo/bin:${PATH}" @@ -50,13 +51,13 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ RUN cd /opt \ && git clone --depth=1 https://github.com/sgl-project/sglang.git \ && cd /opt/sglang \ - && git checkout main + && git checkout ${SGLANG_REPO_REF} # working directory WORKDIR /opt/sglang/sgl-router # build the rust dependencies -RUN cargo build \ +RUN cargo build --release \ && uv build \ && rm -rf /root/.cache @@ -70,7 +71,8 @@ COPY --from=build-image /opt/sglang/sgl-router/dist/*.whl dist/ RUN uv pip install --force-reinstall dist/*.whl # Clean up unnecessary files to reduce the image size -RUN rm -rf /root/.cache +RUN rm -rf /root/.cache \ + && apt purge -y --auto-remove curl # Set the entrypoint to the main command ENTRYPOINT ["python3", "-m", "sglang_router.launch_router"]