执行摘要
- 一句话:修复 release docker 构建因为 dirty repo 失败
- 推荐动作:该 PR 值得快速合并,修复了明确的 CI 阻塞问题。后续可考虑更通用方案(如统一在容器内重新 checkout 而非手动恢复特定文件列表),但当前方案已足够。
功能与动机
Release Docker 构建在 ROCm CI wheels 变更后失败,错误信息为 Repo is dirty。根本原因是 .dockerignore 排除了 .clang-format 和 .gitattributes 等追踪文件,容器内工作树缺少这些文件,而 Git 干净性检查仍会检查它们,导致不一致。修复通过恢复这些文件来保持一致,同时保持 Docker 上下文精简。
实现拆解
- 修改
.dockerignore:移除排除 .clang-format 和 .gitattributes 的行,使这两个文件重新包含在 Docker 上下文中。其他非构建路径如 docs/、.github/、.pre-commit-config.yaml、format.sh 仍被忽略。
- 增强
tools/check_repo.sh:在脚本开头检测 Docker 环境(/.dockerenv 文件存在),如果是,则使用 git checkout-index 从 Git 索引中恢复被 .dockerignore 排除的追踪文件(docs、.github、.pre-commit-config.yaml、format.sh),然后再执行 git diff --quiet 检查干净性。这样即使 Docker 上下文中缺少这些文件,也能恢复它们,避免假阳性 dirty 错误。
关键文件:
.dockerignore(模块 构建脚本;类别 infra;类型 configuration): 移除了对 .clang-format 和 .gitattributes 的排除,使它们重新包含在 Docker 上下文中,避免工作树不完整。
tools/check_repo.sh(模块 构建脚本;类别 infra;类型 core-logic): 添加 Docker 环境下恢复被忽略追踪文件的逻辑,确保 git diff --quiet 能正确判断仓库干净性。
关键符号:未识别
关键源码片段
tools/check_repo.sh
添加 Docker 环境下恢复被忽略追踪文件的逻辑,确保 git diff --quiet 能正确判断仓库干净性。
#!/bin/bash
# Checks whether the repo is clean and whether tags are available (necessary to correctly produce vllm version at build time)
# Some Docker builds intentionally omit tracked, non-build files from the
# context. Restore only those paths from the mounted .git object database before
# checking cleanliness so release builds still see a coherent worktree.
if [ -f /.dockerenv ]; then
# 使用 git ls-files 列出被 .dockerignore 排除的追踪文件路径
# 然后通过 git checkout-index 从 Git 索引还原到工作树
git ls-files -z -- docs .github .pre-commit-config.yaml format.sh \
| git checkout-index -f -z --stdin
fi
if ! git diff --quiet; then
echo "Repo is dirty" >&2
exit 1
fi
评论区精华
无 review 评论。
风险与影响
- 风险:风险很低。变更仅影响 Docker 构建流程和
.dockerignore,且已通过 git diff --check、bash -n tools/check_repo.sh 和临时工作树模拟验证。恢复文件的逻辑仅限 Docker 环境,不影响常规构建。
- 影响:影响范围小,仅限 release Docker 构建流程。修复后这些构建不再因文件缺失而失败,其他自动化流程(如 CI 基础构建)不受影响。团队无需额外操作。
- 风险标记:仅影响Docker构建流程
关联脉络
- PR #44370 [ROCm][CI] Move Model Executor test step from MI250 to MI300 (gfx942): 同样是 ROCm CI 相关的变更,本 PR 的动机中提到‘after ROCm CI wheels change’,可能与这次 CI 调整有关。
参与讨论