refactor(run.sh): optimize build artifact cleanup

- clean_frontend_artifacts: add .vite/.cache/.tmp/*.tsbuildinfo cleanup
- clean_embed_static: rm -rf + mkdir handles dotfiles (was rm static/*)
- new clean_all_artifacts: unified cleanup for all deployment modes
- docker up/build/clean now call clean_all_artifacts before building
- .dockerignore: exclude .vite/*.tsbuildinfo/node cache dirs
- add ./run.sh clean standalone command
This commit is contained in:
attacker committed 2026-06-28 03:35:36 +00:00
1 parent 7ed4ce8d3a
commit da01cbb119
2 files changed
+29 -1

No files matched your search

+7
View File
@@ -5,7 +5,14 @@
# 前端构建产物和依赖(后端构建不需要) # 前端构建产物和依赖(后端构建不需要)
frontend/node_modules frontend/node_modules
frontend/dist frontend/dist
frontend/.vite
frontend/.cache frontend/.cache
**/*.tsbuildinfo
# 前端 Vite 缓存
frontend/node_modules/.vite
frontend/node_modules/.cache
frontend/node_modules/.tmp
# 日志 # 日志
**/*.log **/*.log
+22 -1
View File
@@ -306,13 +306,18 @@ cmd_logs() {
clean_frontend_artifacts() { clean_frontend_artifacts() {
info "清理前端旧构建产物..." info "清理前端旧构建产物..."
rm -rf "$SCRIPT_DIR/$FRONTEND_DIR/dist" rm -rf "$SCRIPT_DIR/$FRONTEND_DIR/dist"
rm -rf "$SCRIPT_DIR/$FRONTEND_DIR/.vite"
rm -rf "$SCRIPT_DIR/$FRONTEND_DIR/node_modules/.vite" rm -rf "$SCRIPT_DIR/$FRONTEND_DIR/node_modules/.vite"
rm -rf "$SCRIPT_DIR/$FRONTEND_DIR/node_modules/.cache"
rm -rf "$SCRIPT_DIR/$FRONTEND_DIR/node_modules/.tmp"
find "$SCRIPT_DIR/$FRONTEND_DIR" -maxdepth 3 -name "*.tsbuildinfo" -delete 2>/dev/null || true
} }
clean_embed_static() { clean_embed_static() {
info "清理 embed static 旧文件..." info "清理 embed static 旧文件..."
# rm -rf + mkdir 确保 dotfiles 也被清除 // Logan.Li
rm -rf "$SCRIPT_DIR/$BACKEND_DIR/static"
mkdir -p "$SCRIPT_DIR/$BACKEND_DIR/static" mkdir -p "$SCRIPT_DIR/$BACKEND_DIR/static"
find "$SCRIPT_DIR/$BACKEND_DIR/static" -mindepth 1 -delete 2>/dev/null || rm -rf "$SCRIPT_DIR/$BACKEND_DIR/static"/*
} }
clean_go_artifacts() { clean_go_artifacts() {
@@ -323,6 +328,14 @@ clean_go_artifacts() {
rm -f "$SCRIPT_DIR/$BACKEND_DIR"/aiops-* rm -f "$SCRIPT_DIR/$BACKEND_DIR"/aiops-*
} }
# 全量清理(docker/build 前调用,确保零残留)// Logan.Li
clean_all_artifacts() {
clean_frontend_artifacts
clean_embed_static
clean_go_artifacts
success "构建产物清理完成"
}
# 构建前端并同步到 backend/static(二进制 / embed 镜像共用)// Logan.Li # 构建前端并同步到 backend/static(二进制 / embed 镜像共用)// Logan.Li
build_frontend_embed() { build_frontend_embed() {
clean_frontend_artifacts clean_frontend_artifacts
@@ -744,6 +757,7 @@ cmd_docker() {
case "$action" in case "$action" in
up|upgrade|update) up|upgrade|update)
banner "========== Docker Compose 启动/升级 ($BUILD_VERSION) ==========" banner "========== Docker Compose 启动/升级 ($BUILD_VERSION) =========="
clean_all_artifacts
if [ "$fresh_build" -eq 1 ]; then if [ "$fresh_build" -eq 1 ]; then
info "全量重建镜像 (--no-cache)..." info "全量重建镜像 (--no-cache)..."
$DOCKER_COMPOSE build --no-cache $DOCKER_COMPOSE build --no-cache
@@ -774,6 +788,7 @@ cmd_docker() {
;; ;;
build) build)
info "构建 Docker 镜像..." info "构建 Docker 镜像..."
clean_all_artifacts
$DOCKER_COMPOSE build $DOCKER_COMPOSE build
success "镜像构建完成" success "镜像构建完成"
;; ;;
@@ -794,6 +809,7 @@ cmd_docker() {
info "清理前磁盘使用:" info "清理前磁盘使用:"
echo " $(df -h / | awk 'NR==2{print $3, "used /", $2, "total ("$5")"}')" echo " $(df -h / | awk 'NR==2{print $3, "used /", $2, "total ("$5")"}')"
echo "" echo ""
clean_all_artifacts
info "清理 dangling 镜像..." info "清理 dangling 镜像..."
docker image prune -f 2>/dev/null || true docker image prune -f 2>/dev/null || true
info "清理构建缓存..." info "清理构建缓存..."
@@ -1481,6 +1497,11 @@ main() {
cmd_help cmd_help
;; ;;
# 清理构建产物
clean)
clean_all_artifacts
;;
*) *)
error "未知命令: $cmd" error "未知命令: $cmd"
cmd_help cmd_help