Skip to content

Commit 95398ce

Browse files
committed
chore(deploy): prune stale build tags
1 parent bfe93b0 commit 95398ce

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ RUNTIME_ROOT=/root/cross-subject-knowledge ./scripts/deploy_vps.sh
301301
4. 在 VPS 上先构建新镜像,再停旧容器,避免“构建失败直接打挂线上”。
302302
5. 新容器通过 `/api/health` 健康检查后才算部署成功;失败则自动回滚到上一镜像。
303303
6. 运行时模型缓存保存在宿主机 `state/cache/`,避免每次发版都把 Hugging Face 缓存烘进镜像。
304-
7. 部署完成后自动清理悬空镜像,并只保留最近几份 `pre-*` 回滚镜像。
304+
7. 部署完成后自动清理悬空镜像,只保留最近几份 `pre-*` 回滚镜像,并删除历史 `build-*` tag
305305

306306
### 3. 服务器 (VPS) 迁移指南
307307
由于大头数据 (4GB+ 图片) 都在云端 CDN,如果未来需要更换服务器提供商,迁移将极其简单轻量:

docs/runtime_operations_overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Current production deploy is:
5858
4. Host model cache is reused or warmed before cutover
5959
5. Old container is replaced only after image build succeeds
6060
6. `/api/health` must pass or the script rolls back to the previous image
61-
7. Dangling images are pruned; only recent rollback tags are retained
61+
7. Dangling images are pruned; only recent rollback tags are retained and old `build-*` tags are removed
6262

6363
## Operational watchpoints
6464

scripts/deploy_vps.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ if [ -n "${old_pre_tags}" ]; then
136136
done <<< "${old_pre_tags}"
137137
fi
138138

139+
old_build_tags="$(docker images --format '{{.Repository}}:{{.Tag}}' | grep '^textbook-knowledge:build-' | grep -v "^${build_tag}$" || true)"
140+
if [ -n "${old_build_tags}" ]; then
141+
while IFS= read -r image_ref; do
142+
[ -n "${image_ref}" ] || continue
143+
docker rmi "${image_ref}" >/dev/null 2>&1 || true
144+
done <<< "${old_build_tags}"
145+
fi
146+
139147
echo "=== disk after deploy ==="
140148
df -h /
141149
docker system df

0 commit comments

Comments
 (0)