From 3cc143f69687b2a4a76b65c88647816b963c2baa Mon Sep 17 00:00:00 2001 From: iDefineHD Date: Sun, 11 Jan 2026 00:39:17 +0000 Subject: [PATCH] Fix: Remove npm cache and use password auth --- .gitea/workflows/deploy.yml | 114 +++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 48 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 6406211..6d9d5e9 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -3,40 +3,22 @@ name: Deploy to Production on: push: branches: - - main # triggers automatically on pushes to main + - main + workflow_dispatch: jobs: deploy: - name: Deploy TurboTrades + name: Deploy to turbotrades.dev runs-on: Turbo-Dev steps: - # ------------------------- - # DEBUG: Verify workflow trigger & secrets - # ------------------------- - - name: Debug Info - run: | - echo "🟒 Workflow triggered!" - echo "Branch: $GITHUB_REF" - echo "Commit: $GITHUB_SHA" - echo "Actor: $GITHUB_ACTOR" - echo "Repository: $GITHUB_REPOSITORY" - echo "Server host secret set? $(if [ -z '${{ secrets.SERVER_HOST }}' ]; then echo '❌'; else echo 'βœ…'; fi)" - echo "Server user secret set? $(if [ -z '${{ secrets.SERVER_USER }}' ]; then echo '❌'; else echo 'βœ…'; fi)" - echo "Server password secret set? $(if [ -z '${{ secrets.SERVER_PASSWORD }}' ]; then echo '❌'; else echo 'βœ…'; fi)" - echo "Runner OS: $RUNNER_OS" - - # ------------------------- - # Checkout code - # ------------------------- - name: Checkout code uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: "20" - cache: "npm" + node-version: "24" - name: Install Backend Dependencies run: npm ci --production @@ -55,10 +37,7 @@ jobs: VITE_API_URL: https://api.turbotrades.dev VITE_WS_URL: https://ws.turbotrades.dev - # ------------------------- - # Deploy via SSH - # ------------------------- - - name: Deploy via SSH (Gitea + password) + - name: Deploy to Production uses: appleboy/ssh-action@v1.0.0 with: host: ${{ secrets.SERVER_HOST }} @@ -66,60 +45,91 @@ jobs: password: ${{ secrets.SERVER_PASSWORD }} port: ${{ secrets.SERVER_PORT || 22 }} script: | - echo "πŸš€ Starting deployment..." + echo "πŸš€ Starting deployment to turbotrades.dev..." - mkdir -p /root/ttbackend /root/ttbackend/logs /var/www/html/turbotrades + # Create directories if they don't exist + mkdir -p /root/ttbackend + mkdir -p /root/ttbackend/logs + mkdir -p /var/www/html/turbotrades + + # Navigate to backend directory cd /root/ttbackend + # Stop the application + echo "⏸️ Stopping backend..." pm2 stop turbotrades-backend || echo "Backend not running" - pm2 delete turbotrades-backend || true + # Backup current version + echo "πŸ’Ύ Creating backup..." if [ -d "/root/ttbackend-backup" ]; then rm -rf /root/ttbackend-backup-old mv /root/ttbackend-backup /root/ttbackend-backup-old fi mkdir -p /root/ttbackend-backup - rsync -a --delete /root/ttbackend/ /root/ttbackend-backup/ || true + cp -r /root/ttbackend/* /root/ttbackend-backup/ 2>/dev/null || true + # Clone or pull repository if [ -d ".git" ]; then + echo "πŸ“₯ Pulling latest code..." git fetch origin git reset --hard origin/main git clean -fd else + echo "πŸ“₯ Cloning repository..." cd /root - rm -rf ttbackend - git clone https://username:${{ secrets.SERVER_PASSWORD }}@git.turbotrades.dev/iDefineHD/TurboTrades.git ttbackend + rm -rf ttbackend/* + git clone https://git.turbotrades.dev/iDefineHD/TurboTrades.git ttbackend cd ttbackend fi + # Install backend dependencies + echo "πŸ“¦ Installing backend dependencies..." npm ci --production + + # Build frontend + echo "🎨 Building frontend..." cd frontend npm ci npm run build + # Deploy frontend to nginx directory + echo "πŸš€ Deploying frontend to /var/www/html/turbotrades..." rm -rf /var/www/html/turbotrades/* cp -r dist/* /var/www/html/turbotrades/ + + # Set proper permissions chown -R www-data:www-data /var/www/html/turbotrades chmod -R 755 /var/www/html/turbotrades + # Back to backend directory cd /root/ttbackend + + # Start backend with PM2 + echo "▢️ Starting backend..." pm2 start ecosystem.config.js --env production pm2 save - echo "βœ… Deployment complete!" - pm2 list - # ------------------------- - # Health Check - # ------------------------- + # Verify deployment + echo "βœ… Deployment complete!" + echo "" + echo "πŸ“Š PM2 Status:" + pm2 list + echo "" + echo "🌐 Frontend: https://turbotrades.dev" + echo "πŸ”§ Backend: https://api.turbotrades.dev" + echo "πŸ’¬ WebSocket: https://ws.turbotrades.dev" + - name: Health Check run: | + echo "⏳ Waiting for services to start..." sleep 15 - curl -f https://api.turbotrades.dev/api/health || echo "⚠️ Backend health check failed" - curl -f https://turbotrades.dev || echo "⚠️ Frontend check failed" - # ------------------------- - # Notifications - # ------------------------- + echo "πŸ₯ Checking backend health..." + curl -f https://api.turbotrades.dev/api/health || echo "⚠️ Backend health check failed" + + echo "πŸ₯ Checking frontend..." + curl -f https://turbotrades.dev || echo "⚠️ Frontend check failed" + - name: Notify Success if: success() run: | @@ -132,7 +142,8 @@ jobs: - name: Notify Failure if: failure() run: | - echo "❌ Deployment failed! Check logs above." + echo "❌ Deployment failed!" + echo "Check the logs above for details" - name: Rollback on Failure if: failure() @@ -140,15 +151,22 @@ jobs: with: host: ${{ secrets.SERVER_HOST }} username: ${{ secrets.SERVER_USER }} - password: ${{ secrets.SERVER_PASSWORD }} + password: ${{ secrets.SERVER_PASSWORD}} port: ${{ secrets.SERVER_PORT || 22 }} script: | - echo "πŸ”„ Rolling back..." + echo "πŸ”„ Rolling back to previous version..." + if [ -d "/root/ttbackend-backup" ]; then - rsync -a --delete /root/ttbackend-backup/ /root/ttbackend/ - cd /root/ttbackend - pm2 start ecosystem.config.js --env production + echo "πŸ“¦ Restoring backend from backup..." + cd /root + rm -rf ttbackend + cp -r ttbackend-backup ttbackend + cd ttbackend + + echo "▢️ Restarting backend..." + pm2 restart turbotrades-backend pm2 save + echo "βœ… Rollback complete" else echo "❌ No backup found!"