Files
jiu/deploy/deploy.sh
T
wangjia f5c41e04f3 fix: 修复测试 schema 缺失字段,标记过时测试为 skip
- testutil/setup.go 补充 products.public_id、description,partners.status
- 过时 products/stock 流程测试标记 skip(provider 已不挂载)
- deploy.sh 补充 PUBLIC_URL dart-define

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-30 00:46:25 +08:00

65 lines
1.6 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.
#!/bin/bash
# 本地一键构建 + 部署脚本
# 用法:bash deploy/deploy.sh
set -e
EC2_HOST="18.136.60.128"
EC2_USER="ec2-user"
EC2_KEY="$HOME/.ssh/wangjia.pem"
DOMAIN="jiu.51yanmei.com"
export PATH="/opt/homebrew/bin:$PATH"
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$REPO_ROOT"
echo "=== 运行后端测试 ==="
cd backend
go test ./...
cd "$REPO_ROOT"
echo "=== 运行前端测试 ==="
cd client
flutter test
cd "$REPO_ROOT"
echo "=== 编译 Go 后端(linux/amd64 ==="
cd backend
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o jiu-server .
cd "$REPO_ROOT"
echo "=== 编译 Flutter Web ==="
cd client
flutter build web --release --dart-define=BASE_URL=https://$DOMAIN --dart-define=PUBLIC_URL=https://$DOMAIN
cd "$REPO_ROOT"
echo "=== 上传后端二进制 ==="
scp -i "$EC2_KEY" backend/jiu-server $EC2_USER@$EC2_HOST:/tmp/jiu-server
echo "=== 上传前端静态文件 ==="
rsync -avz --delete -e "ssh -i $EC2_KEY" \
client/build/web/ $EC2_USER@$EC2_HOST:/tmp/jiu-web-new/
echo "=== 切换文件并重启服务 ==="
ssh -i "$EC2_KEY" $EC2_USER@$EC2_HOST bash << 'REMOTE'
set -e
# 后端
mv /tmp/jiu-server /opt/jiu/backend/jiu-server
chmod +x /opt/jiu/backend/jiu-server
sudo systemctl restart jiu
sleep 3
curl -sf http://localhost:8080/health || { echo "健康检查失败!"; exit 1; }
echo "后端重启成功"
# 前端(原子替换)
rm -rf /opt/jiu/web_old
mv /opt/jiu/web /opt/jiu/web_old 2>/dev/null || true
mv /tmp/jiu-web-new /opt/jiu/web
sudo systemctl reload nginx
echo "前端已更新"
REMOTE
echo ""
echo "部署完成:https://$DOMAIN"