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:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main # triggers automatically on pushes to main
|
- main
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
name: Deploy TurboTrades
|
name: Deploy to turbotrades.dev
|
||||||
runs-on: Turbo-Dev
|
runs-on: Turbo-Dev
|
||||||
|
|
||||||
steps:
|
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
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: "20"
|
node-version: "24"
|
||||||
cache: "npm"
|
|
||||||
|
|
||||||
- name: Install Backend Dependencies
|
- name: Install Backend Dependencies
|
||||||
run: npm ci --production
|
run: npm ci --production
|
||||||
@@ -55,10 +37,7 @@ 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
|
||||||
# Deploy via SSH
|
|
||||||
# -------------------------
|
|
||||||
- name: Deploy via SSH (Gitea + password)
|
|
||||||
uses: appleboy/ssh-action@v1.0.0
|
uses: appleboy/ssh-action@v1.0.0
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.SERVER_HOST }}
|
host: ${{ secrets.SERVER_HOST }}
|
||||||
@@ -66,60 +45,91 @@ jobs:
|
|||||||
password: ${{ secrets.SERVER_PASSWORD }}
|
password: ${{ secrets.SERVER_PASSWORD }}
|
||||||
port: ${{ secrets.SERVER_PORT || 22 }}
|
port: ${{ secrets.SERVER_PORT || 22 }}
|
||||||
script: |
|
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
|
cd /root/ttbackend
|
||||||
|
|
||||||
|
# Stop the application
|
||||||
|
echo "⏸️ Stopping backend..."
|
||||||
pm2 stop turbotrades-backend || echo "Backend not running"
|
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
|
if [ -d "/root/ttbackend-backup" ]; then
|
||||||
rm -rf /root/ttbackend-backup-old
|
rm -rf /root/ttbackend-backup-old
|
||||||
mv /root/ttbackend-backup /root/ttbackend-backup-old
|
mv /root/ttbackend-backup /root/ttbackend-backup-old
|
||||||
fi
|
fi
|
||||||
mkdir -p /root/ttbackend-backup
|
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
|
if [ -d ".git" ]; then
|
||||||
|
echo "📥 Pulling latest code..."
|
||||||
git fetch origin
|
git fetch origin
|
||||||
git reset --hard origin/main
|
git reset --hard origin/main
|
||||||
git clean -fd
|
git clean -fd
|
||||||
else
|
else
|
||||||
|
echo "📥 Cloning repository..."
|
||||||
cd /root
|
cd /root
|
||||||
rm -rf ttbackend
|
rm -rf ttbackend/*
|
||||||
git clone https://username:${{ secrets.SERVER_PASSWORD }}@git.turbotrades.dev/iDefineHD/TurboTrades.git ttbackend
|
git clone https://git.turbotrades.dev/iDefineHD/TurboTrades.git ttbackend
|
||||||
cd ttbackend
|
cd ttbackend
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Install backend dependencies
|
||||||
|
echo "📦 Installing backend dependencies..."
|
||||||
npm ci --production
|
npm ci --production
|
||||||
|
|
||||||
|
# Build frontend
|
||||||
|
echo "🎨 Building frontend..."
|
||||||
cd frontend
|
cd frontend
|
||||||
npm ci
|
npm ci
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
|
# Deploy frontend to nginx directory
|
||||||
|
echo "🚀 Deploying frontend to /var/www/html/turbotrades..."
|
||||||
rm -rf /var/www/html/turbotrades/*
|
rm -rf /var/www/html/turbotrades/*
|
||||||
cp -r dist/* /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
|
||||||
cd /root/ttbackend
|
cd /root/ttbackend
|
||||||
|
|
||||||
|
# Start backend with PM2
|
||||||
|
echo "▶️ Starting backend..."
|
||||||
pm2 start ecosystem.config.js --env production
|
pm2 start ecosystem.config.js --env production
|
||||||
pm2 save
|
pm2 save
|
||||||
echo "✅ Deployment complete!"
|
|
||||||
pm2 list
|
|
||||||
|
|
||||||
# -------------------------
|
# Verify deployment
|
||||||
# Health Check
|
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
|
- name: Health Check
|
||||||
run: |
|
run: |
|
||||||
|
echo "⏳ Waiting for services to start..."
|
||||||
sleep 15
|
sleep 15
|
||||||
|
|
||||||
|
echo "🏥 Checking backend health..."
|
||||||
curl -f https://api.turbotrades.dev/api/health || echo "⚠️ Backend health check failed"
|
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"
|
curl -f https://turbotrades.dev || echo "⚠️ Frontend check failed"
|
||||||
|
|
||||||
# -------------------------
|
|
||||||
# Notifications
|
|
||||||
# -------------------------
|
|
||||||
- name: Notify Success
|
- name: Notify Success
|
||||||
if: success()
|
if: success()
|
||||||
run: |
|
run: |
|
||||||
@@ -132,7 +142,8 @@ jobs:
|
|||||||
- name: Notify Failure
|
- name: Notify Failure
|
||||||
if: failure()
|
if: failure()
|
||||||
run: |
|
run: |
|
||||||
echo "❌ Deployment failed! Check logs above."
|
echo "❌ Deployment failed!"
|
||||||
|
echo "Check the logs above for details"
|
||||||
|
|
||||||
- name: Rollback on Failure
|
- name: Rollback on Failure
|
||||||
if: failure()
|
if: failure()
|
||||||
@@ -143,12 +154,19 @@ jobs:
|
|||||||
password: ${{ secrets.SERVER_PASSWORD}}
|
password: ${{ secrets.SERVER_PASSWORD}}
|
||||||
port: ${{ secrets.SERVER_PORT || 22 }}
|
port: ${{ secrets.SERVER_PORT || 22 }}
|
||||||
script: |
|
script: |
|
||||||
echo "🔄 Rolling back..."
|
echo "🔄 Rolling back to previous version..."
|
||||||
|
|
||||||
if [ -d "/root/ttbackend-backup" ]; then
|
if [ -d "/root/ttbackend-backup" ]; then
|
||||||
rsync -a --delete /root/ttbackend-backup/ /root/ttbackend/
|
echo "📦 Restoring backend from backup..."
|
||||||
cd /root/ttbackend
|
cd /root
|
||||||
pm2 start ecosystem.config.js --env production
|
rm -rf ttbackend
|
||||||
|
cp -r ttbackend-backup ttbackend
|
||||||
|
cd ttbackend
|
||||||
|
|
||||||
|
echo "▶️ Restarting backend..."
|
||||||
|
pm2 restart turbotrades-backend
|
||||||
pm2 save
|
pm2 save
|
||||||
|
|
||||||
echo "✅ Rollback complete"
|
echo "✅ Rollback complete"
|
||||||
else
|
else
|
||||||
echo "❌ No backup found!"
|
echo "❌ No backup found!"
|
||||||
|
|||||||
Reference in New Issue
Block a user