Some checks failed
Deploy to Production / Deploy to turbotrades.dev (push) Failing after 14s
113 lines
3.4 KiB
YAML
113 lines
3.4 KiB
YAML
name: Deploy to Production
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
deploy:
|
|
name: Deploy to turbotrades.dev
|
|
runs-on: Turbo-Dev
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "24"
|
|
|
|
- name: Install Backend Dependencies
|
|
run: npm install --production
|
|
|
|
- name: Install Frontend Dependencies
|
|
run: |
|
|
cd frontend
|
|
npm install
|
|
|
|
- name: Build Frontend
|
|
run: |
|
|
cd frontend
|
|
npm run build
|
|
env:
|
|
NODE_ENV: production
|
|
VITE_API_URL: https://api.turbotrades.dev
|
|
VITE_WS_URL: https://ws.turbotrades.dev
|
|
|
|
- name: Install SSH Client
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y sshpass rsync
|
|
|
|
- name: Deploy to Server
|
|
env:
|
|
SERVER_HOST: ${{ secrets.SERVER_HOST }}
|
|
SERVER_USER: ${{ secrets.SERVER_USER }}
|
|
SERVER_PASSWORD: ${{ secrets.SERVER_PASSWORD }}
|
|
run: |
|
|
echo "🚀 Starting deployment..."
|
|
|
|
# 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
|
|
|
|
# Install backend dependencies
|
|
echo "📦 Installing backend dependencies..."
|
|
npm install --production
|
|
|
|
# Set frontend permissions
|
|
echo "🔒 Setting frontend permissions..."
|
|
chown -R www-data:www-data /var/www/html/turbotrades
|
|
chmod -R 755 /var/www/html/turbotrades
|
|
|
|
# Restart backend with PM2
|
|
echo "🔄 Restarting backend..."
|
|
pm2 restart turbotrades-backend 2>/dev/null || pm2 start ecosystem.config.js --env production
|
|
pm2 save
|
|
|
|
echo "✅ Deployment complete!"
|
|
pm2 list
|
|
EOF
|
|
|
|
- name: Health Check
|
|
run: |
|
|
echo "⏳ Waiting for services to start..."
|
|
sleep 10
|
|
|
|
echo "🏥 Checking backend..."
|
|
curl -f https://api.turbotrades.dev/api/health || echo "⚠️ Backend check failed"
|
|
|
|
echo "🏥 Checking frontend..."
|
|
curl -f https://turbotrades.dev || echo "⚠️ Frontend check failed"
|
|
|
|
- name: Notify Success
|
|
if: success()
|
|
run: |
|
|
echo "✅ Deployment successful!"
|
|
echo "🌐 Frontend: https://turbotrades.dev"
|
|
echo "🔧 Backend: https://api.turbotrades.dev"
|
|
echo "💬 WebSocket: https://ws.turbotrades.dev"
|
|
|
|
- name: Notify Failure
|
|
if: failure()
|
|
run: |
|
|
echo "❌ Deployment failed!"
|
|
echo "Check the logs above for details"
|