diff --git a/.dockerignore b/.dockerignore index 2597755..6f0c85e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,7 +5,14 @@ # 前端构建产物和依赖(后端构建不需要) frontend/node_modules frontend/dist +frontend/.vite frontend/.cache +**/*.tsbuildinfo + +# 前端 Vite 缓存 +frontend/node_modules/.vite +frontend/node_modules/.cache +frontend/node_modules/.tmp # 日志 **/*.log diff --git a/run.sh b/run.sh index 5ee4e4a..b8380f1 100755 --- a/run.sh +++ b/run.sh @@ -306,13 +306,18 @@ cmd_logs() { clean_frontend_artifacts() { info "清理前端旧构建产物..." 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/.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() { info "清理 embed static 旧文件..." + # rm -rf + mkdir 确保 dotfiles 也被清除 // Logan.Li + rm -rf "$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() { @@ -323,6 +328,14 @@ clean_go_artifacts() { 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 build_frontend_embed() { clean_frontend_artifacts @@ -744,6 +757,7 @@ cmd_docker() { case "$action" in up|upgrade|update) banner "========== Docker Compose 启动/升级 ($BUILD_VERSION) ==========" + clean_all_artifacts if [ "$fresh_build" -eq 1 ]; then info "全量重建镜像 (--no-cache)..." $DOCKER_COMPOSE build --no-cache @@ -774,6 +788,7 @@ cmd_docker() { ;; build) info "构建 Docker 镜像..." + clean_all_artifacts $DOCKER_COMPOSE build success "镜像构建完成" ;; @@ -794,6 +809,7 @@ cmd_docker() { info "清理前磁盘使用:" echo " $(df -h / | awk 'NR==2{print $3, "used /", $2, "total ("$5")"}')" echo "" + clean_all_artifacts info "清理 dangling 镜像..." docker image prune -f 2>/dev/null || true info "清理构建缓存..." @@ -1481,6 +1497,11 @@ main() { cmd_help ;; + # 清理构建产物 + clean) + clean_all_artifacts + ;; + *) error "未知命令: $cmd" cmd_help