Skip to main content

EssayBot Server Deployment

EssayBot Server (Backend) uses GitHub Actions with a self-hosted runner on the A6000 server.


Server Details

EnvironmentPathBranchTrigger
Production/opt/Essaybot-servermainPush to release/prod
UAT/opt/Essaybot-server-UATqdrant-migrationPush to qdrant-migration

Server: A6000 (self-hosted GitHub runner)


Ports

EnvironmentExpressFlaskPM2 Namespace
PROD80016000prod
UAT80026001uat
Shared ServicePort
MongoDB27017
Redis6379
RabbitMQ5672
Qdrant6333

PM2 Process Names

EnvironmentExpressFlaskWorker
PRODessaybot-expressessaybot-flaskessaybot-worker
UATessaybot-express-uatessaybot-flask-uatessaybot-worker-uat

Deployment Triggers

Automatic (GitHub Actions)

Push to branch → GitHub Action triggers → Deploy to corresponding environment
BranchDeploys To
release/prodProduction
qdrant-migrationUAT

Manual (Workflow Dispatch)

  1. Go to ActionsDeploy EssayBot Server
  2. Click Run workflow
  3. Select environment (UAT or PROD)
  4. Optionally specify a branch

Deployment Steps (What the CI Does)

  1. Backup current deployment
  2. Pull latest code from branch
  3. Create .env file from GitHub Secrets
  4. Install Node.js dependencies (npm ci)
  5. Setup Python venv and install requirements
  6. Start Docker services (RabbitMQ, Redis)
  7. Restart PM2 services (Express, Flask, Worker)
  8. Health check on /health endpoints
  9. Notify Teams channel

GitHub Secrets Required

Environment-Specific

SecretDescription
MONGO_URI_UATMongoDB connection string for UAT
MONGO_URI_PRODMongoDB connection string for PROD
ESSAYBOT_PRODUCTION_URL_UATUI URL for UAT (https://uat.essaybot.dashlab.studio)
ESSAYBOT_PRODUCTION_URL_PRODUI URL for PROD (https://essaybot.dashlab.studio)
DASH_PORTAL_PRODUCTION_URL_UATDashPortal URL for UAT
DASH_PORTAL_PRODUCTION_URL_PRODDashPortal URL for PROD
MINIO_BUCKET_UATMinIO bucket for UAT (essaybot-uat)
MINIO_BUCKET_PRODMinIO bucket for PROD (essaybot)

Shared (Both Environments)

SecretDescription
JWT_SECRETJWT signing secret
EXTERNAL_JWT_SECRETDashPortal cross-auth secret
MINIO_ACCESS_KEYMinIO access key
MINIO_SECRET_KEYMinIO secret key
MINIO_ENDPOINTMinIO endpoint URL
OLLAMA_URLvLLM completions endpoint
OLLAMA_MODEL_URLvLLM base URL
VISION_MODELVision model name
EMBEDDING_MODELEmbedding model name
AWS_REGIONAWS region for S3 compatibility
GH_PATGitHub Personal Access Token
TEAMS_WEBHOOK_URLMS Teams notification webhook

PM2 Commands

Check Status

# UAT
sudo -u deploy pm2 status --namespace uat

# PROD
sudo -u deploy pm2 status --namespace prod

View Logs

# UAT
sudo -u deploy pm2 logs --namespace uat --lines 100

# PROD
sudo -u deploy pm2 logs --namespace prod --lines 100

Restart Services

# UAT
sudo -u deploy pm2 restart all --namespace uat

# PROD
sudo -u deploy pm2 restart all --namespace prod

Full Restart (Delete + Start)

# UAT
cd /opt/Essaybot-server-UAT
sudo -u deploy pm2 delete all --namespace uat
sudo -u deploy NAMESPACE=uat pm2 start ecosystem.config.js --only essaybot-express-uat --namespace uat
sudo -u deploy NAMESPACE=uat pm2 start ecosystem.config.js --only essaybot-flask-uat --namespace uat
sudo -u deploy NAMESPACE=uat pm2 start ecosystem.config.js --only essaybot-worker-uat --namespace uat

# PROD
cd /opt/Essaybot-server
sudo -u deploy pm2 delete all --namespace prod
sudo -u deploy NAMESPACE=prod pm2 start ecosystem.config.js --env production --only essaybot-express --namespace prod
sudo -u deploy NAMESPACE=prod pm2 start ecosystem.config.js --env production --only essaybot-flask --namespace prod
sudo -u deploy NAMESPACE=prod pm2 start ecosystem.config.js --env production --only essaybot-worker --namespace prod

Docker Services

# Check status
docker ps

# Restart RabbitMQ and Redis
docker compose restart rabbitmq redis

Health Check Endpoints

EnvironmentExpressFlask
UAThttp://localhost:8002/healthhttp://localhost:6001/health
PRODhttp://localhost:8001/healthhttp://localhost:6000/health

Rollback

On deployment failure, the CI automatically restores from the latest backup in /opt/Essaybot-server[-UAT]/backups/.

Manual Rollback

# List backups
ls -la /opt/Essaybot-server-UAT/backups/

# Restore specific backup
cd /opt/Essaybot-server-UAT
sudo -u deploy tar -xzf backups/backup-20240115-120000.tar.gz -C .
sudo -u deploy pm2 restart all --namespace uat

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

IssueCheck
Services not startingpm2 logs --namespace uat --lines 50
Port already in uselsof -ti:8002 then kill -9 <PID>
MinIO errorsVerify .env has correct MINIO_* values
JWT auth failuresCheck EXTERNAL_JWT_SECRET length (should be 15 chars)
RabbitMQ connectiondocker ps — ensure essaybot-rabbitmq is running