Production Setup
This guide walks through deploying Dharini on AWS infrastructure for production use.
Prerequisites
Section titled “Prerequisites”- AWS Account with appropriate permissions
- Domain name for your deployment
- SSH key pair for EC2 access
Step 1: Set Up AWS RDS Database
Section titled “Step 1: Set Up AWS RDS Database”Create PostgreSQL RDS Instance
Section titled “Create PostgreSQL RDS Instance”-
Go to AWS RDS Console
-
Click Create database
-
Choose the following settings:
- Engine: PostgreSQL 16.x
- Template: Production
- DB instance identifier:
dharini-prod-db - Master username:
postgres(or your choice) - Master password: Set a strong password
- Instance class: db.t3.micro (or larger based on needs)
- Storage: 20 GB GP3
- Enable storage autoscaling: Yes
- Multi-AZ: Optional (recommended for high availability)
-
Connectivity:
- VPC: Choose your VPC
- Public access: No (unless needed)
- VPC security group: Create new or use existing
- Availability Zone: No preference
-
Additional configuration:
- Initial database name:
postgres - Enable automated backups: Yes
- Backup retention: 7 days (or more)
- Enable encryption: Yes
- Initial database name:
-
Click Create database
Configure Security Group
Section titled “Configure Security Group”Add inbound rule to the RDS security group:
- Type: PostgreSQL
- Port: 5432
- Source: Your EC2 instance’s security group or private IP
Install PostGIS Extension
Section titled “Install PostGIS Extension”Connect to your RDS instance:
psql -h dharini-prod-db.xxxxxxxxx.region.rds.amazonaws.com -U postgres -d postgresRun the following SQL:
CREATE EXTENSION IF NOT EXISTS postgis;CREATE EXTENSION IF NOT EXISTS postgis_topology;CREATE EXTENSION IF NOT EXISTS "uuid-ossp";Step 2: Set Up AWS S3 Bucket
Section titled “Step 2: Set Up AWS S3 Bucket”-
Go to AWS S3 Console
-
Click Create bucket
-
Configure:
- Bucket name:
dharini-prod-storage(must be globally unique) - Region: Same as your EC2 instance
- Block Public Access: Enable (keep bucket private)
- Versioning: Optional
- Encryption: Enable (SSE-S3 or SSE-KMS)
- Bucket name:
-
Create IAM user with S3 access:
- Go to IAM Console
- Create user
dharini-s3-access - Attach policy with S3 bucket access
- Generate access keys
- Save Access Key ID and Secret Access Key
Step 3: Launch EC2 Instance
Section titled “Step 3: Launch EC2 Instance”Create Instance
Section titled “Create Instance”- Go to EC2 Console
- Click Launch Instance
- Configure:
- Name:
dharini-prod - AMI: Ubuntu Server 24.04 LTS
- Instance type: t3.medium (or larger)
- Key pair: Select or create new
- VPC: Same VPC as RDS
- Security group: Create new with rules below
- Name:
Security Group Configuration
Section titled “Security Group Configuration”Add the following inbound rules:
| Type | Port | Source | Description |
|---|---|---|---|
| SSH | 22 | Your IP | SSH access |
| HTTP | 80 | 0.0.0.0/0 | Web traffic |
| HTTPS | 443 | 0.0.0.0/0 | Secure web |
Step 4: Install Docker
Section titled “Step 4: Install Docker”SSH into your EC2 instance:
ssh -i your-key.pem ubuntu@your-ec2-ipInstall Docker:
# Update package indexsudo apt-get update
# Install prerequisitessudo apt-get install -y ca-certificates curl gnupg lsb-release
# Add Docker's official GPG keysudo mkdir -p /etc/apt/keyringscurl -fsSL https://download.docker.com/linux/ubuntu/gpg | \ sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Set up the repositoryecho \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \ https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Update package index againsudo apt-get update
# Install Docker Engine and pluginssudo apt-get install -y docker-ce docker-ce-cli containerd.io \ docker-buildx-plugin docker-compose-plugin
# Add ubuntu user to docker groupsudo usermod -aG docker ubuntu
# Enable and start Dockersudo systemctl enable dockersudo systemctl start dockerLog out and back in for group changes to take effect:
exitssh -i your-key.pem ubuntu@your-ec2-ipVerify Docker installation:
docker --versiondocker compose versionStep 5: Clone Repository
Section titled “Step 5: Clone Repository”git clone https://github.com/dsih-artpark/dharini.gitcd dhariniStep 6: Configure Environment Variables
Section titled “Step 6: Configure Environment Variables”Create a .env file in the repository root. See Environment Variables for complete reference.
Minimum required configuration:
# ApplicationNODE_ENV=productionPORT=4000
# Database - RDSDB_HOST=dharini-prod-db.xxxxxxxxx.region.rds.amazonaws.comDB_PORT=5432DB_USERNAME=postgresDB_PASSWORD=your-rds-passwordDB_DATABASE=postgres
# Redis (Docker)REDIS_HOST=redisREDIS_PORT=6379
# AWS S3S3_REGION=ap-south-1S3_BUCKET=dharini-prod-storageS3_ACCESSKEYID=your-access-key-idS3_SECRETACCESSKEY=your-secret-access-keyS3_ENDPOINT=https://s3.ap-south-1.amazonaws.comS3_FOLDER=dharini-prod
# SecurityJWT_SECRET=generate-a-strong-random-secret
# Email (optional - configure based on provider)SENDGRID_API_KEY=GMAIL_USER=GMAIL_PASS=EMAIL_FROM=
# FrontendNEXT_PUBLIC_API_URL=https://your-domain.com/apiNEXT_PUBLIC_APP_ENV=productionStep 7: Start Docker Services
Section titled “Step 7: Start Docker Services”docker compose --profile production up -d --buildCheck service status:
docker psYou should see:
backend(running)frontend(running)apk-server(running)redis(running)
Step 8: Run Database Migrations
Section titled “Step 8: Run Database Migrations”docker exec -it backend npm run migration:runVerify tables were created:
PGSSLMODE=require psql -h your-rds-endpoint -U postgres -d postgres -c "\dt"Step 9: Set Up Nginx
Section titled “Step 9: Set Up Nginx”Install Nginx:
sudo apt-get install -y nginxCreate Nginx configuration. See Nginx Configuration for complete setup.
Step 10: Set Up SSL Certificates
Section titled “Step 10: Set Up SSL Certificates”Install Certbot:
sudo apt-get install -y certbot python3-certbot-nginxGenerate SSL certificate:
sudo certbot --nginx -d your-domain.comFollow the prompts to complete SSL setup.
Step 11: Configure DNS
Section titled “Step 11: Configure DNS”Point your domain to your EC2 instance:
- Go to your DNS provider
- Add an A record:
- Name:
@(or subdomain likein) - Type: A
- Value: Your EC2 public IP
- TTL: 300
- Name:
Step 12: Verify Deployment
Section titled “Step 12: Verify Deployment”- Visit
https://your-domain.com- should load the frontend - Visit
https://your-domain.com/api/docs- should load API documentation - Check logs for errors:
docker logs backend -fdocker logs frontend -fPost-Deployment
Section titled “Post-Deployment”- Set up monitoring (CloudWatch, Datadog, etc.)
- Configure automated backups
- Set up log aggregation
- Create admin user account
- Test all functionality
Next Steps
Section titled “Next Steps”- Environment Variables - Full configuration reference
- Nginx Configuration - Detailed reverse proxy setup
- Troubleshooting - Common issues and fixes