Files
whale-town-end/deploy.sh.example
moyin a907e64f40 feat: 添加生产环境部署配置
- 添加 Dockerfile 和 docker-compose.yml 支持容器化部署
- 添加 PM2 配置文件 ecosystem.config.js
- 添加部署脚本模板 deploy.sh.example
- 添加 Gitea webhook 处理器模板 webhook-handler.js.example
- 添加生产环境配置模板 .env.production.example
- 添加详细的部署指南 DEPLOYMENT.md
- 更新 .gitignore 排除敏感配置文件
2025-12-17 15:37:40 +08:00

54 lines
1.3 KiB
Bash
Raw Permalink 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
# 部署脚本模板 - 用于 Gitea Webhook 自动部署
# 复制此文件为 deploy.sh 并根据服务器环境修改配置
set -e
echo "开始部署 Pixel Game Server..."
# 项目路径(根据你的服务器实际路径修改)
PROJECT_PATH="/var/www/pixel-game-server"
BACKUP_PATH="/var/backups/pixel-game-server"
# 创建备份
echo "创建备份..."
mkdir -p $BACKUP_PATH
cp -r $PROJECT_PATH $BACKUP_PATH/backup-$(date +%Y%m%d-%H%M%S)
# 进入项目目录
cd $PROJECT_PATH
# 拉取最新代码
echo "拉取最新代码..."
git pull origin main
# 安装/更新依赖
echo "安装依赖..."
pnpm install --frozen-lockfile
# 构建项目
echo "构建项目..."
pnpm run build
# 重启服务
echo "重启服务..."
if command -v pm2 &> /dev/null; then
# 使用 PM2
pm2 restart pixel-game-server || pm2 start dist/main.js --name pixel-game-server
elif command -v docker-compose &> /dev/null; then
# 使用 Docker Compose
docker-compose down
docker-compose up -d --build
else
# 使用 systemd
sudo systemctl restart pixel-game-server
fi
echo "部署完成!"
# 清理旧备份保留最近5个
find $BACKUP_PATH -maxdepth 1 -type d -name "backup-*" | sort -r | tail -n +6 | xargs rm -rf
echo "服务状态检查..."
sleep 5
curl -f http://localhost:3000/health || echo "警告:服务健康检查失败"