From ea013b79be7c7d7550b2ca0b98ae963d6672478e Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 24 Jan 2026 18:53:44 -0800 Subject: [PATCH] fix(deploy): make --no-cache optional for rebuild command - rebuild now uses cache by default - only ignores cache when --no-cache is explicitly passed Usage: ./deploy.sh rebuild conversation # uses cache ./deploy.sh rebuild conversation --no-cache # ignores cache Co-Authored-By: Claude Opus 4.5 --- deploy.sh | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/deploy.sh b/deploy.sh index 455ce11..05df492 100755 --- a/deploy.sh +++ b/deploy.sh @@ -597,13 +597,30 @@ start_all() { do_status } -# 重新构建 Docker 镜像 (--no-cache) +# 重新构建 Docker 镜像 do_rebuild() { local target=${1:-all} + local no_cache="" + local cache_msg="" - if [ "$target" = "all" ]; then - log_step "重新构建所有服务镜像 (--no-cache)..." - $DOCKER_COMPOSE build --no-cache + # 检查是否有 --no-cache 参数 + for arg in "$@"; do + if [ "$arg" = "--no-cache" ]; then + no_cache="--no-cache" + cache_msg=" (--no-cache)" + fi + done + + if [ "$target" = "all" ] || [ "$target" = "--no-cache" ]; then + # 如果第一个参数是 --no-cache,则 target 是 all + if [ "$target" = "--no-cache" ]; then + target="all" + no_cache="--no-cache" + cache_msg=" (--no-cache)" + fi + + log_step "重新构建所有服务镜像${cache_msg}..." + $DOCKER_COMPOSE build $no_cache # 重启所有后端服务 log_step "重启所有后端服务..." @@ -622,8 +639,8 @@ do_rebuild() { *) service_name="$target-service" ;; esac - log_step "重新构建 $target 镜像 (--no-cache)..." - $DOCKER_COMPOSE build --no-cache "$service_name" + log_step "重新构建 $target 镜像${cache_msg}..." + $DOCKER_COMPOSE build $no_cache "$service_name" # 重启服务使用新镜像 log_step "重启 $target 服务..." @@ -1404,10 +1421,11 @@ show_help() { conversation, user, payment, knowledge, evolution, web-client, admin-client - rebuild [target] 重新构建 Docker 镜像 (--no-cache) + rebuild [target] [--no-cache] + 重新构建 Docker 镜像并重启服务 target: all, conversation, user, payment, knowledge, evolution, nginx, kong - ⚠️ 完全重新构建,忽略缓存 + --no-cache: 可选,忽略缓存完全重新构建 start [target] [mode] 启动服务 target: all, infra, kong, nginx, backend, @@ -1467,8 +1485,8 @@ show_help() { ./deploy.sh logs conversation 200 # 查看对话服务最近200行日志 ./deploy.sh clean all # 清理所有构建产物和依赖 ./deploy.sh full-reset # ⚠️ 重置所有数据库数据 - ./deploy.sh rebuild conversation # 重新构建对话服务镜像 (--no-cache) - ./deploy.sh rebuild all # 重新构建所有服务镜像 (--no-cache) + ./deploy.sh rebuild conversation # 重新构建对话服务镜像 (使用缓存) + ./deploy.sh rebuild conversation --no-cache # 完全重新构建 (忽略缓存) ./deploy.sh db init # 初始化数据库 (首次部署) ./deploy.sh db backup # 备份数据库 ./deploy.sh db migrate # 执行数据库迁移