xykj-plus/claude-ecc/build-local.sh
2026-06-13 13:48:51 +08:00

61 lines
2.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# build-local.sh — 本地打包测试脚本
# 说明:执行与 release.sh 中完全相同的 Docker build 过程,用于在发布前验证本地打包环节是否畅通无阻,避免直接在生产部署时碰到打包报错。
# 用法:
# ./build-local.sh
# ./build-local.sh --no-cache
# ./build-local.sh --skip-ts
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ADMIN_DIR="${SCRIPT_DIR}/admin-xy"
DEV_ASSISTANT_DIR="${SCRIPT_DIR}/dev-assistant"
BRIDGE_DIR="${DEV_ASSISTANT_DIR}/bridge"
NO_CACHE=""
SKIP_TS=false
for arg in "$@"; do
case "$arg" in
--no-cache) NO_CACHE="--no-cache" ;;
--skip-ts) SKIP_TS=true ;;
--help|-h)
echo "用法: ./build-local.sh [--no-cache] [--skip-ts]"
exit 0
;;
esac
done
echo "=== 开始本地打包验证 ==="
# 像 release.sh 一样处理外部依赖bridge 编译)
if ${SKIP_TS}; then
echo "=> 跳过 dev-assistant bridge TypeScript 构建(--skip-ts"
else
echo "=> [0/3] 安装 dev-assistant 依赖并编译 bridge ..."
( cd "${DEV_ASSISTANT_DIR}" && npm install --no-audit --no-fund )
( cd "${BRIDGE_DIR}" && npm run build )
fi
echo "=> [1/3] 构建后端镜像 admin-xy-server:latest ..."
docker build ${NO_CACHE} -t admin-xy-server:latest "${ADMIN_DIR}/server"
echo "=> [2/3] 构建前端镜像 admin-xy-web:latest ..."
# 默认使用开发环境的占位 URL 进行本地校验构建(发布时 release.sh 会用自己的 origin 覆盖)
docker build ${NO_CACHE} \
--file "${ADMIN_DIR}/web/Dockerfile" \
--build-arg "VITE_DEV_ASSISTANT_HTTP=http://localhost:9020" \
--build-arg "VITE_DEV_ASSISTANT_WS=ws://localhost:9020/copilot" \
-t admin-xy-web:latest "${SCRIPT_DIR}"
echo "=> [3/3] 构建桥接镜像 dev-assistant-bridge:latest ..."
docker build ${NO_CACHE} -t dev-assistant-bridge:latest "${BRIDGE_DIR}"
echo "======================"
echo " ✓ 本地打包校验成功"
echo "======================"
echo "最新构建出的镜像:"
docker images --format 'table {{.Repository}}\t{{.Tag}}\t{{.Size}}' | grep -E '(admin-xy|dev-assistant)' || true