Simplify deployment - use direct SSH/rsync instead of actions
Some checks failed
Deploy to Production / Deploy to turbotrades.dev (push) Failing after 14s
Some checks failed
Deploy to Production / Deploy to turbotrades.dev (push) Failing after 14s
This commit is contained in:
@@ -4,7 +4,6 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
@@ -37,95 +36,63 @@ jobs:
|
|||||||
VITE_API_URL: https://api.turbotrades.dev
|
VITE_API_URL: https://api.turbotrades.dev
|
||||||
VITE_WS_URL: https://ws.turbotrades.dev
|
VITE_WS_URL: https://ws.turbotrades.dev
|
||||||
|
|
||||||
- name: Deploy to Production
|
- name: Install SSH Client
|
||||||
uses: appleboy/ssh-action@v1.0.0
|
run: |
|
||||||
with:
|
sudo apt-get update
|
||||||
host: ${{ secrets.SERVER_HOST }}
|
sudo apt-get install -y sshpass rsync
|
||||||
username: ${{ secrets.SERVER_USER }}
|
|
||||||
password: ${{ secrets.SERVER_PASSWORD }}
|
|
||||||
port: ${{ secrets.SERVER_PORT || 22 }}
|
|
||||||
script: |
|
|
||||||
echo "🚀 Starting deployment to turbotrades.dev..."
|
|
||||||
|
|
||||||
# Create directories if they don't exist
|
- name: Deploy to Server
|
||||||
mkdir -p /root/ttbackend
|
env:
|
||||||
mkdir -p /root/ttbackend/logs
|
SERVER_HOST: ${{ secrets.SERVER_HOST }}
|
||||||
mkdir -p /var/www/html/turbotrades
|
SERVER_USER: ${{ secrets.SERVER_USER }}
|
||||||
|
SERVER_PASSWORD: ${{ secrets.SERVER_PASSWORD }}
|
||||||
|
run: |
|
||||||
|
echo "🚀 Starting deployment..."
|
||||||
|
|
||||||
# Navigate to backend directory
|
# Deploy files via rsync
|
||||||
|
echo "📦 Syncing backend files..."
|
||||||
|
sshpass -p "$SERVER_PASSWORD" rsync -avz --delete \
|
||||||
|
--exclude 'node_modules' \
|
||||||
|
--exclude '.git' \
|
||||||
|
--exclude '.env' \
|
||||||
|
--exclude 'logs' \
|
||||||
|
-e "ssh -o StrictHostKeyChecking=no -p 22" \
|
||||||
|
./ ${SERVER_USER}@${SERVER_HOST}:/root/ttbackend/
|
||||||
|
|
||||||
|
echo "🎨 Syncing frontend build..."
|
||||||
|
sshpass -p "$SERVER_PASSWORD" rsync -avz --delete \
|
||||||
|
-e "ssh -o StrictHostKeyChecking=no -p 22" \
|
||||||
|
./frontend/dist/ ${SERVER_USER}@${SERVER_HOST}:/var/www/html/turbotrades/
|
||||||
|
|
||||||
|
echo "▶️ Running deployment commands on server..."
|
||||||
|
sshpass -p "$SERVER_PASSWORD" ssh -o StrictHostKeyChecking=no -p 22 ${SERVER_USER}@${SERVER_HOST} bash << 'EOF'
|
||||||
cd /root/ttbackend
|
cd /root/ttbackend
|
||||||
|
|
||||||
# Stop the application
|
|
||||||
echo "⏸️ Stopping backend..."
|
|
||||||
pm2 stop turbotrades-backend || echo "Backend not running"
|
|
||||||
|
|
||||||
# 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
|
|
||||||
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://git.turbotrades.dev/iDefineHD/TurboTrades.git ttbackend
|
|
||||||
cd ttbackend
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Install backend dependencies
|
# Install backend dependencies
|
||||||
echo "📦 Installing backend dependencies..."
|
echo "📦 Installing backend dependencies..."
|
||||||
npm install --production
|
npm install --production
|
||||||
|
|
||||||
# Build frontend
|
# Set frontend permissions
|
||||||
echo "🎨 Building frontend..."
|
echo "🔒 Setting frontend permissions..."
|
||||||
cd frontend
|
|
||||||
npm install
|
|
||||||
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
|
chown -R www-data:www-data /var/www/html/turbotrades
|
||||||
chmod -R 755 /var/www/html/turbotrades
|
chmod -R 755 /var/www/html/turbotrades
|
||||||
|
|
||||||
# Back to backend directory
|
# Restart backend with PM2
|
||||||
cd /root/ttbackend
|
echo "🔄 Restarting backend..."
|
||||||
|
pm2 restart turbotrades-backend 2>/dev/null || pm2 start ecosystem.config.js --env production
|
||||||
# Start backend with PM2
|
|
||||||
echo "▶️ Starting backend..."
|
|
||||||
pm2 start ecosystem.config.js --env production
|
|
||||||
pm2 save
|
pm2 save
|
||||||
|
|
||||||
# Verify deployment
|
|
||||||
echo "✅ Deployment complete!"
|
echo "✅ Deployment complete!"
|
||||||
echo ""
|
|
||||||
echo "📊 PM2 Status:"
|
|
||||||
pm2 list
|
pm2 list
|
||||||
echo ""
|
EOF
|
||||||
echo "🌐 Frontend: https://turbotrades.dev"
|
|
||||||
echo "🔧 Backend: https://api.turbotrades.dev"
|
|
||||||
echo "💬 WebSocket: https://ws.turbotrades.dev"
|
|
||||||
|
|
||||||
- name: Health Check
|
- name: Health Check
|
||||||
run: |
|
run: |
|
||||||
echo "⏳ Waiting for services to start..."
|
echo "⏳ Waiting for services to start..."
|
||||||
sleep 15
|
sleep 10
|
||||||
|
|
||||||
echo "🏥 Checking backend health..."
|
echo "🏥 Checking backend..."
|
||||||
curl -f https://api.turbotrades.dev/api/health || echo "⚠️ Backend health check failed"
|
curl -f https://api.turbotrades.dev/api/health || echo "⚠️ Backend check failed"
|
||||||
|
|
||||||
echo "🏥 Checking frontend..."
|
echo "🏥 Checking frontend..."
|
||||||
curl -f https://turbotrades.dev || echo "⚠️ Frontend check failed"
|
curl -f https://turbotrades.dev || echo "⚠️ Frontend check failed"
|
||||||
@@ -137,37 +104,9 @@ jobs:
|
|||||||
echo "🌐 Frontend: https://turbotrades.dev"
|
echo "🌐 Frontend: https://turbotrades.dev"
|
||||||
echo "🔧 Backend: https://api.turbotrades.dev"
|
echo "🔧 Backend: https://api.turbotrades.dev"
|
||||||
echo "💬 WebSocket: https://ws.turbotrades.dev"
|
echo "💬 WebSocket: https://ws.turbotrades.dev"
|
||||||
echo "📅 Time: $(date)"
|
|
||||||
|
|
||||||
- name: Notify Failure
|
- name: Notify Failure
|
||||||
if: failure()
|
if: failure()
|
||||||
run: |
|
run: |
|
||||||
echo "❌ Deployment failed!"
|
echo "❌ Deployment failed!"
|
||||||
echo "Check the logs above for details"
|
echo "Check the logs above for details"
|
||||||
|
|
||||||
- name: Rollback on Failure
|
|
||||||
if: failure()
|
|
||||||
uses: appleboy/ssh-action@v1.0.0
|
|
||||||
with:
|
|
||||||
host: ${{ secrets.SERVER_HOST }}
|
|
||||||
username: ${{ secrets.SERVER_USER }}
|
|
||||||
password: ${{ secrets.SERVER_PASSWORD}}
|
|
||||||
port: ${{ secrets.SERVER_PORT || 22 }}
|
|
||||||
script: |
|
|
||||||
echo "🔄 Rolling back to previous version..."
|
|
||||||
|
|
||||||
if [ -d "/root/ttbackend-backup" ]; then
|
|
||||||
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!"
|
|
||||||
fi
|
|
||||||
|
|||||||
Reference in New Issue
Block a user