|
| 1 | +######################## BASE IMAGE ########################## |
| 2 | +FROM ubuntu:24.04 AS base |
| 3 | + |
| 4 | +ARG PYTHON_VERSION=3.12 |
| 5 | + |
| 6 | +# set the environment variables |
| 7 | +ENV PATH="/root/.local/bin:${PATH}" |
| 8 | +ENV DEBIAN_FRONTEND=noninteractive |
| 9 | + |
| 10 | +# uv environment variables |
| 11 | +ENV UV_HTTP_TIMEOUT=500 |
| 12 | +ENV VIRTUAL_ENV="/opt/venv" |
| 13 | +ENV UV_PYTHON_INSTALL_DIR=/opt/uv/python |
| 14 | +ENV UV_LINK_MODE="copy" |
| 15 | +ENV PATH="$VIRTUAL_ENV/bin:$PATH" |
| 16 | + |
| 17 | + |
| 18 | +# install dependencies |
| 19 | +RUN echo 'tzdata tzdata/Areas select America' | debconf-set-selections \ |
| 20 | + && echo 'tzdata tzdata/Zones/America select Los_Angeles' | debconf-set-selections \ |
| 21 | + && apt update -y \ |
| 22 | + && apt install -y curl \ |
| 23 | + && rm -rf /var/lib/apt/lists/* \ |
| 24 | + && apt clean |
| 25 | + |
| 26 | +# install uv |
| 27 | +RUN curl -LsSf https://astral.sh/uv/install.sh | sh |
| 28 | + |
| 29 | +# install python |
| 30 | +RUN uv venv --python ${PYTHON_VERSION} --seed ${VIRTUAL_ENV} |
| 31 | + |
| 32 | +######################### BUILD IMAGE ######################### |
| 33 | +FROM base AS build-image |
| 34 | + |
| 35 | +ARG SGLANG_REPO_REF=main |
| 36 | + |
| 37 | +# set the environment variables |
| 38 | +ENV PATH="/root/.cargo/bin:${PATH}" |
| 39 | + |
| 40 | +# install dependencies |
| 41 | +RUN apt update -y \ |
| 42 | + && apt install -y git build-essential libssl-dev pkg-config \ |
| 43 | + && rm -rf /var/lib/apt/lists/* \ |
| 44 | + && apt clean |
| 45 | + |
| 46 | +# install rustup from rustup.rs |
| 47 | +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ |
| 48 | + && rustc --version && cargo --version |
| 49 | + |
| 50 | +# pull the github repository |
| 51 | +RUN cd /opt \ |
| 52 | + && git clone --depth=1 https://github.com/sgl-project/sglang.git \ |
| 53 | + && cd /opt/sglang \ |
| 54 | + && git checkout ${SGLANG_REPO_REF} |
| 55 | + |
| 56 | +# working directory |
| 57 | +WORKDIR /opt/sglang/sgl-router |
| 58 | + |
| 59 | +# build the rust dependencies |
| 60 | +RUN cargo build --release \ |
| 61 | + && uv build \ |
| 62 | + && rm -rf /root/.cache |
| 63 | + |
| 64 | +######################### ROUTER IMAGE ######################### |
| 65 | +FROM base AS router-image |
| 66 | + |
| 67 | +# Copy the built package from the build image |
| 68 | +COPY --from=build-image /opt/sglang/sgl-router/dist/*.whl dist/ |
| 69 | + |
| 70 | +# Build the package and install |
| 71 | +RUN uv pip install --force-reinstall dist/*.whl |
| 72 | + |
| 73 | +# Clean up unnecessary files to reduce the image size |
| 74 | +RUN rm -rf /root/.cache \ |
| 75 | + && apt purge -y --auto-remove curl |
| 76 | + |
| 77 | +# Set the entrypoint to the main command |
| 78 | +ENTRYPOINT ["python3", "-m", "sglang_router.launch_router"] |
0 commit comments