Fix: Remove npm cache and use password auth
Some checks failed
Deploy to Production / Deploy to turbotrades.dev (push) Failing after 6s
Some checks failed
Deploy to Production / Deploy to turbotrades.dev (push) Failing after 6s
This commit is contained in:
@@ -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
|
||||
|
||||
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"
|
||||
|
||||
# -------------------------
|
||||
# Notifications
|
||||
# -------------------------
|
||||
- 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!"
|
||||
|
||||
Reference in New Issue
Block a user