deploy: b300 build scripts with pip cache mount + no-build-isolation fast path
Base image already has torch 2.13, but pyproject build-system.requires pulls it into pip's isolated build env on every build (~6GB via throttled mirror, 47min). --no-build-isolation reuses the base env; build.sh picks Dockerfile.fast (--no-deps) when python/pyproject.toml is unchanged.
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
# 优化版(2026-09-24):解决清华源限流下每次构建重下 torch 的问题。
|
||||||
|
# 要点:
|
||||||
|
# 1. pyproject build-system.requires 含 torch==2.13.0,pip 隔离构建环境每次都重下 ~6GB。
|
||||||
|
# 基底镜像已装 torch 2.13 → 用 --no-build-isolation 复用,构建环境零下载。
|
||||||
|
# 2. 基底缺 setuptools-scm(版本打戳要用),单层预装 + pip cache mount,只下载一次。
|
||||||
|
# 3. RUN 的 pip cache mount 持久化在宿主机,依赖解析命中的包不再重复下载。
|
||||||
|
FROM uhub.service.ucloud.cn/umirror/sglang:dev-dsv41
|
||||||
|
|
||||||
|
ARG PIP_INDEX=https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
|
ENV PIP_INDEX_URL=${PIP_INDEX}
|
||||||
|
|
||||||
|
# 构建后端(pyproject build-system.requires,torch 除外——基底已有)
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
|
pip install "setuptools>=61" "setuptools-scm>=8" "setuptools-rust>=1.11" wheel
|
||||||
|
|
||||||
|
# 整个源码树(含 .git,用于 setuptools-scm 版本打戳)
|
||||||
|
COPY sglang/ /sgl-workspace/sglang/
|
||||||
|
|
||||||
|
# editable 安装,全量依赖解析(pyproject.toml 变化时走这个)
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
|
pip install --no-build-isolation -e /sgl-workspace/sglang/python
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# fast 路径:python/pyproject.toml 未变化时使用(build.sh 自动判断)。
|
||||||
|
# --no-deps 跳过全部依赖解析(连 index 元数据请求都省掉),纯源码迭代秒级完成。
|
||||||
|
# 依赖有变化时必须走 Dockerfile 全量路径(build.sh 按 pyproject sha256 自动切换)。
|
||||||
|
FROM uhub.service.ucloud.cn/umirror/sglang:dev-dsv41
|
||||||
|
|
||||||
|
ARG PIP_INDEX=https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
|
ENV PIP_INDEX_URL=${PIP_INDEX}
|
||||||
|
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
|
pip install "setuptools>=61" "setuptools-scm>=8" "setuptools-rust>=1.11" wheel
|
||||||
|
|
||||||
|
COPY sglang/ /sgl-workspace/sglang/
|
||||||
|
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
|
pip install --no-deps --no-build-isolation -e /sgl-workspace/sglang/python
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# 用法: /data/ymk/build/build.sh [tag]
|
||||||
|
# 默认 tag: ymkymx/sglang:<分支>-<sha9>-local-<UTC构建日期时间>(命名规则见 AGENTS.md)
|
||||||
|
# 另打 <分支>-latest-local 别名。
|
||||||
|
#
|
||||||
|
# 依赖路径自动选择:
|
||||||
|
# python/pyproject.toml 的 sha256 与上次成功构建一致 → Dockerfile.fast(--no-deps,秒级)
|
||||||
|
# 不一致(或 FULL=1)→ Dockerfile 全量依赖解析,成功后记录新 hash
|
||||||
|
set -euo pipefail
|
||||||
|
cd /data/ymk
|
||||||
|
SHA=$(git -C sglang rev-parse --short=9 HEAD)
|
||||||
|
BR=$(git -C sglang rev-parse --abbrev-ref HEAD)
|
||||||
|
DT=$(date -u +%Y%m%d-%H%M)
|
||||||
|
TAG=${1:-ymkymx/sglang:$BR-$SHA-local-$DT}
|
||||||
|
|
||||||
|
HASH_FILE=build/.last_pyproject_sha256
|
||||||
|
CUR=$(sha256sum sglang/python/pyproject.toml | cut -d' ' -f1)
|
||||||
|
PREV=$(cat "$HASH_FILE" 2>/dev/null || echo none)
|
||||||
|
|
||||||
|
DOCKERFILE=build/Dockerfile
|
||||||
|
if [ "$CUR" = "$PREV" ] && [ "${FULL:-0}" != "1" ]; then
|
||||||
|
DOCKERFILE=build/Dockerfile.fast
|
||||||
|
echo "== pyproject 未变,走 fast 路径(--no-deps)"
|
||||||
|
else
|
||||||
|
echo "== pyproject 有变化或 FULL=1,走全量依赖解析"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "== building $TAG from sglang@$(git -C sglang log --oneline -1) [$DOCKERFILE]"
|
||||||
|
docker build -f "$DOCKERFILE" -t "$TAG" .
|
||||||
|
# 构建成功才记录 hash / 打别名
|
||||||
|
echo "$CUR" > "$HASH_FILE"
|
||||||
|
docker tag "$TAG" "ymkymx/sglang:$BR-latest-local"
|
||||||
|
echo "== done: $TAG (别名 $BR-latest-local)"
|
||||||
Reference in New Issue
Block a user