This repository provides a production-ready setup for deploying a RoyBrains- MogTok Erp Django application using Docker Compose, Nginx, and Certbot (Let's Encrypt SSL).
- Python 3.14+ (Minimum required for better support)
- pip (latest version recommended)
Before starting, make sure you have:
- Docker
- Docker Compose
- A registered domain name pointing to your server IP
If you want to run the project without Docker:
First, create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activatepython -m venv venv
venv\Scripts\activateAfter activation, your terminal should show (venv).
Make sure Python 3.14+ is installed, then run:
pip install --upgrade pip
pip install -r requirements.txtCreate a .env file and set required values (see below).
python manage.py migrate
python manage.py runserverYour app will be available at:
http://127.0.0.1:8000/
Create a .env file in the project root using the following template:
ENVIRONMENT="PRODUCTION" # PRODUCTION or DEVELOPMENT
# Hosts
# Single: example.com
# Multiple: example.com,learn.example.com
ALLOWED_HOSTS=example.com
# CSRF Trusted Origins
# Single: https://example.com
# Multiple: https://learn.example.com,https://example.com
CSRF_TRUSTED_ORIGINS=https://learn.example.com,https://example.com
# database type
DB_TYPE="LOCAL" # LOCAL or REMOTE
# Database (PostgreSQL)
DB_URL=ep-ad-df-182938-pooler.asp-southeast-2.aws.neon.tech
DB_PASS=akjncadlcoirv
DB_USER=admin_mk
DB_NAME=root-db
DB_PORT=5432
# AWS Credentials
AWS_ACCESS_KEY_ID=adcdadsvwvraefefefwr
AWS_SECRET_ACCESS_KEY=acfav/swrvrfvadvrgthrtsdvfgetgh
# S3 Configuration
AWS_STORAGE_BUCKET_NAME=example-bucket
AWS_S3_REGION_NAME=ap-south-1
AWS_S3_SIGNATURE_VERSION=s3v4
AWS_QUERYSTRING_EXPIRE=3600
AWS_S3_CUSTOM_DOMAIN=ajhbcakdhbckdbjv.cloudfront.net
AWS_LOCATION=static
⚠️ Important: Never commit your real.envfile to GitHub.
Before running the application for the first time, you must enable the pg_trgm extension in your PostgreSQL database.
This extension is required for advanced text search and similarity features used in the system.
Connect to your PostgreSQL database and execute:
CREATE EXTENSION IF NOT EXISTS pg_trgm;psql -h <DB_HOST> -U <DB_USER> -d <DB_NAME>Then run:
CREATE EXTENSION IF NOT EXISTS pg_trgm;
⚠️ Note: Make sure your database user has sufficient privileges to create extensions.
For local development without password authentication, configure your database in:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': DB_NAME,
'HOST': DB_URL,
'PORT': DB_PORT # default postgres port 5432
}
}Use this only in development mode.
Edit the domain name in:
Replace {domain.com} with your actual domain.
server_name {domain.com};And in SSL section:
ssl_certificate /etc/letsencrypt/live/{domain.com}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{domain.com}/privkey.pem;
server_name {domain.com};Initially, keep only port 80 enabled to generate SSL certificates.
Once certificates are generated, uncomment the 443 block and enable HTTPS redirect.
Edit docker-compose.yml and replace email and domain in the Certbot service.
certbot:
image: certbot/certbot
container_name: certbot
profiles: ["certbot"]
volumes:
- ./certbot/conf:/etc/letsencrypt
- ./certbot/www:/var/www/certbot
command: certonly --webroot -w /var/www/certbot \
--email your@email.com \
-d yourdomain.com \
--agree-tosReplace:
your@email.comyourdomain.com
For successful Docker image builds, only the following PostgreSQL driver version is supported:
psycopg[c]==3.2.12
Before building Docker images or running docker compose, make sure:
- All
psycopg,psycopg2,psycopg-binary, or other variants - Are replaced with:
psycopg[c]==3.2.12
In your requirements.txt file.
Example:
psycopg[c]==3.2.12Failure to do this may cause Docker build errors.
Run Certbot profile first:
docker compose --profile certbot up --buildThis will:
- Start Nginx
- Verify domain
- Generate SSL certificates
After certificates are created:
- Uncomment
443SSL block - Enable HTTPS redirect
- Comment temporary HTTP settings
Then reload containers.
Run:
docker compose up -dThis will start all production services.
To stop and restart:
docker compose down
docker compose up -dIf you make changes:
docker compose down
docker compose up --build -d- Make sure your domain DNS is pointing to your server IP
- Ports 80 and 443 must be open
- Certificates are stored in
./certbot/conf - Certbot auto-renew can be added later using cron
Contributions are welcome!
Feel free to:
- Improve documentation
- Add automation
- Enhance security
Create a pull request anytime.
If you face any issues, open an issue in the repository or contact the maintainer.
Happy Deploying! 🚀