fix(deploy): force rebuild Docker images by default

- deploy.sh deploy now uses --no-cache by default to ensure
  @iconsulting/shared package is correctly bundled into images
- Add --cache option if user wants to use Docker cache for faster builds
- This fixes the "Cannot find module '@iconsulting/shared'" error
  that occurred when Docker used cached images without the latest shared code

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-26 00:42:29 -08:00
parent 7975982fc3
commit 0c13140445
1 changed files with 35 additions and 12 deletions

View File

@ -358,19 +358,24 @@ do_build() {
# 构建 Docker 镜像
build_docker_images() {
local service=${1:-}
local no_cache=${2:-}
log_step "构建 Docker 镜像..."
log_step "构建 Docker 镜像${no_cache:+ (--no-cache)}..."
if [ -n "$service" ] && [ "$service" != "all" ]; then
if [ -n "$service" ] && [ "$service" != "all" ] && [ "$service" != "--no-cache" ]; then
local docker_service="${DOCKER_SERVICES[$service]}"
if [ -n "$docker_service" ]; then
$DOCKER_COMPOSE build "$docker_service"
$DOCKER_COMPOSE build $no_cache "$docker_service"
else
log_error "未知服务: $service"
return 1
fi
else
$DOCKER_COMPOSE build
# 如果第一个参数是 --no-cache则构建全部
if [ "$service" = "--no-cache" ]; then
no_cache="--no-cache"
fi
$DOCKER_COMPOSE build $no_cache
fi
log_success "Docker 镜像构建完成"
@ -909,22 +914,39 @@ do_clean() {
#===============================================================================
do_deploy() {
local mode=${1:-docker}
local mode=${1:-all}
local use_cache=false
log_info "开始完整部署 (模式: $mode)..."
# 检查参数: --cache 使用缓存,否则默认 --no-cache
for arg in "$@"; do
if [ "$arg" = "--cache" ]; then
use_cache=true
fi
done
if [ "$use_cache" = true ]; then
log_info "开始完整部署 (使用Docker缓存)..."
else
log_info "开始完整部署 (--no-cache 确保最新代码)..."
fi
check_environment
# 构建
# 构建代码 (在 builder 容器中)
do_build all
# 如果是 Docker 模式,构建镜像
if [ "$mode" = "docker" ]; then
build_docker_images
if [ "$mode" = "docker" ] || [ "$mode" = "all" ]; then
if [ "$use_cache" = true ]; then
build_docker_images ""
else
# deploy 命令默认使用 --no-cache确保 shared 包被正确打包到镜像
build_docker_images "" "--no-cache"
fi
fi
# 启动
do_start all "$mode"
do_start all docker
# 配置 Kong 路由
setup_kong_routes
@ -1623,8 +1645,9 @@ show_help() {
clean [target] 清理
target: build, deps, docker, logs, all
deploy [mode] 完整部署 (构建 + 启动)
mode: docker (默认), local
deploy [--cache] 完整部署 (构建 + 重建镜像 + 启动)
默认使用 --no-cache 确保 shared 包被正确打包
--cache: 可选,使用 Docker 缓存加速构建
deploy-full 完整部署 (含 SSL 证书自动申请)