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 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-24 18:53:44 -08:00
parent 45a594d39a
commit ea013b79be
1 changed files with 28 additions and 10 deletions

View File

@ -597,13 +597,30 @@ start_all() {
do_status do_status
} }
# 重新构建 Docker 镜像 (--no-cache) # 重新构建 Docker 镜像
do_rebuild() { do_rebuild() {
local target=${1:-all} local target=${1:-all}
local no_cache=""
local cache_msg=""
if [ "$target" = "all" ]; then # 检查是否有 --no-cache 参数
log_step "重新构建所有服务镜像 (--no-cache)..." for arg in "$@"; do
$DOCKER_COMPOSE build --no-cache 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 "重启所有后端服务..." log_step "重启所有后端服务..."
@ -622,8 +639,8 @@ do_rebuild() {
*) service_name="$target-service" ;; *) service_name="$target-service" ;;
esac esac
log_step "重新构建 $target 镜像 (--no-cache)..." log_step "重新构建 $target 镜像${cache_msg}..."
$DOCKER_COMPOSE build --no-cache "$service_name" $DOCKER_COMPOSE build $no_cache "$service_name"
# 重启服务使用新镜像 # 重启服务使用新镜像
log_step "重启 $target 服务..." log_step "重启 $target 服务..."
@ -1404,10 +1421,11 @@ show_help() {
conversation, user, payment, knowledge, evolution, conversation, user, payment, knowledge, evolution,
web-client, admin-client web-client, admin-client
rebuild [target] 重新构建 Docker 镜像 (--no-cache) rebuild [target] [--no-cache]
重新构建 Docker 镜像并重启服务
target: all, conversation, user, payment, knowledge, evolution, target: all, conversation, user, payment, knowledge, evolution,
nginx, kong nginx, kong
⚠️ 完全重新构建,忽略缓存 --no-cache: 可选,忽略缓存完全重新构建
start [target] [mode] 启动服务 start [target] [mode] 启动服务
target: all, infra, kong, nginx, backend, target: all, infra, kong, nginx, backend,
@ -1467,8 +1485,8 @@ show_help() {
./deploy.sh logs conversation 200 # 查看对话服务最近200行日志 ./deploy.sh logs conversation 200 # 查看对话服务最近200行日志
./deploy.sh clean all # 清理所有构建产物和依赖 ./deploy.sh clean all # 清理所有构建产物和依赖
./deploy.sh full-reset # ⚠️ 重置所有数据库数据 ./deploy.sh full-reset # ⚠️ 重置所有数据库数据
./deploy.sh rebuild conversation # 重新构建对话服务镜像 (--no-cache) ./deploy.sh rebuild conversation # 重新构建对话服务镜像 (使用缓存)
./deploy.sh rebuild all # 重新构建所有服务镜像 (--no-cache) ./deploy.sh rebuild conversation --no-cache # 完全重新构建 (忽略缓存)
./deploy.sh db init # 初始化数据库 (首次部署) ./deploy.sh db init # 初始化数据库 (首次部署)
./deploy.sh db backup # 备份数据库 ./deploy.sh db backup # 备份数据库
./deploy.sh db migrate # 执行数据库迁移 ./deploy.sh db migrate # 执行数据库迁移