Skip to main content

EssayBot UI Deployment

EssayBot UI uses GitHub Actions for automated CI/CD deployment to the A6000 server.


Environment Overview

PropertyProduction (PROD)UAT
Branchmaindynamic-update
Server Path/var/www/Essaybot-UI/var/www/Essaybot-UI-UAT
PM2 Namespaceproduat
PM2 App Nameessaybot-uiessaybot-ui-uat
Log Directory/var/www/Essaybot-UI/logs/var/www/Essaybot-UI-UAT/logs
Env File.env.prod.env.uat
API URLhttps://api.essaybot.dashlab.studiohttps://uat.api.essaybot.dashlab.studio

Deployment Triggers

Automatic Deployment

BranchEnvironment
Push to mainProduction
Push to dynamic-updateUAT

Manual Deployment

Trigger via GitHub Actions workflow_dispatch:

  1. Go to ActionsDeploy EssayBot UI
  2. Click Run workflow
  3. Select environment: UAT or PROD
  4. Optionally specify a custom branch

Environment Variables

VariableDescription
NODE_ENVAlways production
NAMESPACEprod or uat
PORTApplication port (from secrets)
NEXT_PUBLIC_ESSAYBOT_API_URLBackend API URL
NEXT_PUBLIC_ENVIRONMENTPROD or UAT
NEXT_PUBLIC_DASH_PORTAL_URLDASH Portal URL
LOG_LEVELinfo (prod) / debug (uat)

GitHub Secrets Required

SecretDescription
GH_PATGitHub Personal Access Token
TEAMS_WEBHOOK_URLMicrosoft Teams notification webhook
PORT_PRODProduction port number
PORT_UATUAT port number
ESSAYBOT_API_URL_PRODProduction API URL
ESSAYBOT_API_URL_UATUAT API URL
NEXT_PUBLIC_DASH_PORTAL_URL_PRODProduction DASH Portal URL
NEXT_PUBLIC_DASH_PORTAL_URL_UATUAT DASH Portal URL

Deployment Pipeline

┌─────────────────────────────────────────────────────────────────┐
│ UI DEPLOYMENT PIPELINE │
├─────────────────────────────────────────────────────────────────┤
│ │
│ 1. Setup Environment │
│ └── Determine PROD/UAT based on branch │
│ │
│ 2. Setup Log Directory │
│ └── Create logs folder, cleanup old logs (>30 days) │
│ │
│ 3. Teams Notification (Starting) │
│ │
│ 4. Backup Current Deployment │
│ └── Creates timestamped backup (excludes node_modules) │
│ │
│ 5. Pull Latest Code │
│ └── git fetch → checkout → reset --hard │
│ │
│ 6. Create Environment File │
│ └── Generate .env.prod or .env.uat from secrets │
│ │
│ 7. Install Dependencies │
│ └── npm ci (or npm install as fallback) │
│ │
│ 8. Build Next.js Application │
│ └── Clear .next cache → npm run build │
│ │
│ 9. Restart PM2 Service │
│ └── Zero-downtime reload or fresh start │
│ │
│ 10. Health Check │
│ └── Verify service is running on expected port │
│ │
│ 11. Cleanup │
│ └── Keep only 3 most recent backups │
│ │
│ 12. Teams Notification (Success/Failure) │
│ │
└─────────────────────────────────────────────────────────────────┘

PM2 Commands

Check Status

# Production
pm2 status --namespace prod

# UAT
pm2 status --namespace uat

View Logs

# Production
pm2 logs essaybot-ui --namespace prod

# UAT
pm2 logs essaybot-ui-uat --namespace uat

Restart Service

# Production
pm2 restart essaybot-ui --namespace prod

# UAT
pm2 restart essaybot-ui-uat --namespace uat

Stop Service

# Production
pm2 stop essaybot-ui --namespace prod

# UAT
pm2 stop essaybot-ui-uat --namespace uat

Manual Deployment (SSH)

If you need to deploy manually via SSH:

# 1. SSH into A6000 server
ssh deploy@<server-ip>

# 2. Navigate to project directory
cd /var/www/Essaybot-UI # PROD
cd /var/www/Essaybot-UI-UAT # UAT

# 3. Pull latest code
git fetch --all
git checkout main # PROD
git checkout dynamic-update # UAT
git reset --hard origin/main # PROD
git reset --hard origin/dynamic-update # UAT

# 4. Install dependencies
npm ci

# 5. Build
npm run build

# 6. Restart PM2
pm2 restart essaybot-ui --namespace prod # PROD
pm2 restart essaybot-ui-uat --namespace uat # UAT

# 7. Save PM2 state
pm2 save

Rollback

On deployment failure, the pipeline automatically:

  1. Restores the latest backup from /var/www/Essaybot-UI/backups/
  2. Sends failure notification to Teams

Manual Rollback

# List available backups
ls -lt /var/www/Essaybot-UI/backups/

# Restore specific backup
cd /var/www/Essaybot-UI
tar -xzf backups/backup-YYYYMMDD-HHMMSS.tar.gz -C .

# Restart service
pm2 restart essaybot-ui --namespace prod

Backup Retention

  • Automatic cleanup: Keeps only 3 most recent backups
  • Log cleanup: Removes logs older than 30 days
  • Backup location: <project-dir>/backups/
  • Backup format: backup-YYYYMMDD-HHMMSS.tar.gz

Troubleshooting

Service Not Starting

# Check PM2 logs
pm2 logs --lines 50 --namespace prod

# Check if port is in use
lsof -i :<PORT>

# Verify .env file exists
cat /var/www/Essaybot-UI/.env

Build Failures

# Clear Next.js cache
rm -rf .next

# Clear node_modules and reinstall
rm -rf node_modules
npm ci

# Rebuild
npm run build

Health Check Failures

# Test locally
curl -f http://localhost:<PORT>

# Check PM2 process status
pm2 jlist | jq '.[] | select(.namespace == "prod")'