EssayBot UI Deployment
EssayBot UI uses GitHub Actions for automated CI/CD deployment to the A6000 server.
Environment Overview
| Property | Production (PROD) | UAT |
|---|---|---|
| Branch | main | dynamic-update |
| Server Path | /var/www/Essaybot-UI | /var/www/Essaybot-UI-UAT |
| PM2 Namespace | prod | uat |
| PM2 App Name | essaybot-ui | essaybot-ui-uat |
| Log Directory | /var/www/Essaybot-UI/logs | /var/www/Essaybot-UI-UAT/logs |
| Env File | .env.prod | .env.uat |
| API URL | https://api.essaybot.dashlab.studio | https://uat.api.essaybot.dashlab.studio |
Deployment Triggers
Automatic Deployment
| Branch | Environment |
|---|---|
Push to main | Production |
Push to dynamic-update | UAT |
Manual Deployment
Trigger via GitHub Actions workflow_dispatch:
- Go to Actions → Deploy EssayBot UI
- Click Run workflow
- Select environment:
UATorPROD - Optionally specify a custom branch
Environment Variables
| Variable | Description |
|---|---|
NODE_ENV | Always production |
NAMESPACE | prod or uat |
PORT | Application port (from secrets) |
NEXT_PUBLIC_ESSAYBOT_API_URL | Backend API URL |
NEXT_PUBLIC_ENVIRONMENT | PROD or UAT |
NEXT_PUBLIC_DASH_PORTAL_URL | DASH Portal URL |
LOG_LEVEL | info (prod) / debug (uat) |
GitHub Secrets Required
| Secret | Description |
|---|---|
GH_PAT | GitHub Personal Access Token |
TEAMS_WEBHOOK_URL | Microsoft Teams notification webhook |
PORT_PROD | Production port number |
PORT_UAT | UAT port number |
ESSAYBOT_API_URL_PROD | Production API URL |
ESSAYBOT_API_URL_UAT | UAT API URL |
NEXT_PUBLIC_DASH_PORTAL_URL_PROD | Production DASH Portal URL |
NEXT_PUBLIC_DASH_PORTAL_URL_UAT | UAT 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:
- Restores the latest backup from
/var/www/Essaybot-UI/backups/ - 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")'