Files
web/deploy.sh
2026-03-17 01:26:33 +08:00

57 lines
1.7 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
# 一键部署 api、web、admin 三个服务Docker
# 用法:
# 本地/当前机部署:./deploy.sh
# 部署到远程机: DEPLOY_HOST=user@192.168.10.241 ./deploy.sh
set -e
ROOT="$(cd "$(dirname "$0")" && pwd)"
cd "$ROOT"
echo "=========================================="
echo " yh_web 部署 (api + web + admin)"
echo " 域名: https://yuheng.yuxindazhineng.com"
echo "=========================================="
run_deploy() {
local dir="$1"
cd "$dir"
if [ -f server/.env ]; then
set -a
source server/.env
set +a
echo "[OK] 已加载 server/.env"
fi
echo ""
echo "[1/3] 构建镜像 (api + web + admin)..."
docker compose build --no-cache 2>/dev/null || docker-compose build --no-cache
echo ""
echo "[2/3] 停止旧容器..."
docker compose down 2>/dev/null || docker-compose down
echo ""
echo "[3/3] 启动三个服务 + Mongo..."
docker compose up -d 2>/dev/null || docker-compose up -d
cd "$ROOT"
echo ""
echo "=========================================="
echo " 部署完成"
echo " api:9527 web:9528 admin:9529"
echo " 访问: https://yuheng.yuxindazhineng.com"
echo "=========================================="
}
if [ -n "$DEPLOY_HOST" ]; then
echo "远程部署到: $DEPLOY_HOST"
echo "同步项目目录..."
rsync -az --delete \
--exclude '.git' \
--exclude 'node_modules' \
--exclude 'web/dist' \
--exclude 'admin/dist' \
--exclude 'logs' \
"$ROOT/" "$DEPLOY_HOST:${DEPLOY_PATH:-project/yh_web}/"
echo "在远程执行部署..."
ssh "$DEPLOY_HOST" "cd ${DEPLOY_PATH:-project/yh_web} && chmod +x deploy.sh && ./deploy.sh"
else
run_deploy "$ROOT"
fi