Implement single token mode for authentication. Update login and vali… #242
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy NestJS to Server | |
| on: | |
| push: | |
| branches: | |
| - main # 监听 main 分支 | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '18' # 替换为你的 Node 版本 | |
| - name: Install Dependencies | |
| run: npm install --legacy-peer-deps | |
| - name: Build NestJS | |
| run: npm run build | |
| - name: Create remote directory | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USERNAME }} | |
| password: ${{ secrets.SERVER_PASSWORD }} | |
| script: | | |
| mkdir -p /www/workspace/yishe-nest | |
| chmod 755 /www/workspace/yishe-nest | |
| - name: Upload files to server | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USERNAME }} | |
| password: ${{ secrets.SERVER_PASSWORD }} | |
| source: "dist,package.json,package-lock.json" | |
| target: /www/workspace/yishe-nest | |
| strip_components: 0 | |
| overwrite: true | |
| debug: true | |
| - name: SSH into server and restart with PM2 | |
| id: deploy | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USERNAME }} | |
| password: ${{ secrets.SERVER_PASSWORD }} | |
| script: | | |
| cd /www/workspace/yishe-nest | |
| # 安装系统依赖 | |
| apt-get update | |
| apt-get install -y build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev pkg-config | |
| # 清理旧的 node_modules | |
| rm -rf node_modules | |
| # 使用 Node.js 18 版本 | |
| export NVM_DIR="$HOME/.nvm" | |
| [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | |
| nvm use 18 | |
| # 安装依赖 | |
| npm install --production --legacy-peer-deps | |
| if [ ! -d "node_modules" ]; then | |
| echo "::error::node_modules 目录创建失败" | |
| exit 1 | |
| fi | |
| # 创建 TypeORM 配置文件 | |
| cat > dist/config/typeorm.config.js << 'EOL' | |
| module.exports = { | |
| type: 'mysql', | |
| host: process.env.DB_HOST, | |
| port: parseInt(process.env.DB_PORT, 10) || 3306, | |
| username: process.env.DB_USERNAME, | |
| password: process.env.DB_PASSWORD, | |
| database: process.env.DB_DATABASE, | |
| entities: ['dist/**/*.entity{.ts,.js}'], | |
| synchronize: false, | |
| logging: true, | |
| maxQueryExecutionTime: 1000, | |
| extra: { | |
| connectionLimit: 10, | |
| queueLimit: 0, | |
| waitForConnections: true, | |
| connectTimeout: 60000, | |
| acquireTimeout: 60000, | |
| timeout: 60000, | |
| maxIdle: 10, | |
| idleTimeout: 60000, | |
| enableKeepAlive: true, | |
| keepAliveInitialDelay: 0, | |
| }, | |
| poolSize: 10, | |
| keepConnectionAlive: true, | |
| }; | |
| EOL | |
| # 调整 MySQL 配置 | |
| mysql -e "SET GLOBAL max_allowed_packet=67108864;" || true | |
| # 如果使用的是宝塔面板,可以通过修改配置文件 | |
| if [ -f "/www/server/mysql/etc/my.cnf" ]; then | |
| sed -i '/max_allowed_packet/d' /www/server/mysql/etc/my.cnf | |
| echo "max_allowed_packet=64M" >> /www/server/mysql/etc/my.cnf | |
| /etc/init.d/mysqld restart || true | |
| fi | |
| # 重启服务 | |
| pm2 delete yishe-nest || true | |
| pm2 start dist/main.js --name yishe-nest --env production | |
| sleep 5 | |
| if ! pm2 list | grep -q "yishe-nest.*online"; then | |
| echo "::error::服务启动失败" | |
| exit 1 | |
| fi | |
| - name: Send Feishu Notification | |
| if: steps.deploy.outcome == 'success' | |
| run: | | |
| curl -X POST ${{ secrets.FEISHU_WEBHOOK_URL }} \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "msg_type": "text", | |
| "content": { | |
| "text": "🎉 衣设后台服务部署成功!\n\n📌 部署信息:\n• 环境:生产环境\n• 分支:main\n• 时间:'"$(date +'%Y-%m-%d %H:%M:%S')"'\n• 服务器:'"${{ secrets.SERVER_HOST }}"'\n\n✨ 服务已通过 PM2 启动,运行状态正常。\n\n💡 如需查看服务状态,请使用命令:pm2 status yishe-nest" | |
| } | |
| }' | |
| - name: Send Failure Notification | |
| if: steps.deploy.outcome == 'failure' | |
| run: | | |
| curl -X POST ${{ secrets.FEISHU_WEBHOOK_URL }} \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "msg_type": "text", | |
| "content": { | |
| "text": "❌ NestJS 项目部署失败!\n分支: main\n时间: '"$(date +'%Y-%m-%d %H:%M:%S')"'" | |
| } | |
| }' |