- Prerequisites
- Local Development Setup
- Production Deployment Options
- Heroku Deployment
- Railway Deployment
- AWS Deployment
- Docker Deployment
- Environment Configuration
- Database Setup
- Static Files Configuration
- Security Considerations
- Monitoring & Maintenance
- Troubleshooting
- Python: 3.8+ (recommended: 3.11+)
- Memory: Minimum 2GB RAM (4GB+ recommended for AI models)
- Storage: 1GB+ free space
- OS: Windows, macOS, or Linux
- GitHub: For code repository
- Heroku/Railway/AWS: For hosting (choose one)
- Domain Name: Optional (for custom domain)
git clone <your-repository-url>
cd Hackathon# Windows
python -m venv venv
venv\Scripts\activate
# macOS/Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtCreate .env file in project root:
DEBUG=True
SECRET_KEY=your-secret-key-here
ALLOWED_HOSTS=localhost,127.0.0.1
DATABASE_URL=sqlite:///db.sqlite3python manage.py makemigrations
python manage.py migratepython manage.py createsuperuserpython manage.py runserverAccess: http://127.0.0.1:8000
| Platform | Pros | Cons | Best For |
|---|---|---|---|
| Heroku | Easy setup, free tier | Limited resources | Prototypes, demos |
| Railway | Fast deployment, good free tier | Newer platform | Small to medium projects |
| AWS | Scalable, powerful | Complex setup, costs | Production, enterprise |
| DigitalOcean | Good performance, reasonable cost | Manual setup | Small businesses |
| Vercel | Fast, good for frontend | Limited backend support | Frontend-heavy apps |
# Windows
# Download from: https://devcenter.heroku.com/articles/heroku-cli
# macOS
brew install heroku/brew/heroku
# Linux
curl https://cli-assets.heroku.com/install.sh | shheroku loginheroku create sahay-ai-career-mentorheroku buildpacks:add heroku/python
heroku buildpacks:add https://github.com/heroku/heroku-buildpack-aptCreate Procfile in project root:
web: gunicorn career_mentor_web.wsgi --log-file -
Add these lines to requirements.txt:
gunicorn==21.2.0
whitenoise==6.6.0
dj-database-url==2.1.0
psycopg2-binary==2.9.9
Add to career_mentor_web/settings.py:
import dj_database_url
import os
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = 'DEVELOPMENT' in os.environ
ALLOWED_HOSTS = ['your-app-name.herokuapp.com', 'localhost', '127.0.0.1']
# Database
DATABASES = {
'default': dj_database_url.parse(os.environ.get('DATABASE_URL'))
}
# Static files
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
# Media files
MEDIA_ROOT = os.path.join(BASE_DIR, 'mediafiles')git add .
git commit -m "Deploy to Heroku"
git push heroku main
# Run migrations
heroku run python manage.py migrate
# Create superuser (optional)
heroku run python manage.py createsuperuserheroku config:set SECRET_KEY=your-production-secret-key
heroku config:set DEBUG=False
heroku config:set ALLOWED_HOSTS=your-app-name.herokuapp.comnpm install -g @railway/clirailway loginrailway initCreate railway.json in project root:
{
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "gunicorn career_mentor_web.wsgi --log-file -",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}railway upIn Railway dashboard:
- Set
SECRET_KEY - Set
DEBUG=False - Set
ALLOWED_HOSTS
- Create AWS account
- Install AWS CLI
- Configure credentials
# Launch Ubuntu instance
# t2.medium or larger for AI models
# Configure security groups for ports 22, 80, 443ssh -i your-key.pem ubuntu@your-ec2-ip
# Update system
sudo apt update && sudo apt upgrade -y
# Install Python, Nginx, etc.
sudo apt install python3-pip python3-venv nginx git -y# Clone repository
git clone <your-repo>
cd Hackathon
# Setup virtual environment
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# Setup environment variables
nano .envCreate /etc/systemd/system/sahay-ai.service:
[Unit]
Description=Sahay AI Gunicorn daemon
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/Hackathon
Environment="PATH=/home/ubuntu/Hackathon/venv/bin"
ExecStart=/home/ubuntu/Hackathon/venv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/Hackathon/sahay-ai.sock career_mentor_web.wsgi:application
[Install]
WantedBy=multi-user.targetCreate /etc/nginx/sites-available/sahay-ai:
server {
listen 80;
server_name your-domain.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/ubuntu/Hackathon;
}
location /media/ {
root /home/ubuntu/Hackathon;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/Hackathon/sahay-ai.sock;
}
}sudo systemctl start sahay-ai
sudo systemctl enable sahay-ai
sudo ln -s /etc/nginx/sites-available/sahay-ai /etc/nginx/sites-enabled
sudo systemctl restart nginxCreate Dockerfile in project root:
FROM python:3.11-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set work directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy project
COPY . .
# Collect static files
RUN python manage.py collectstatic --noinput
# Run gunicorn
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "career_mentor_web.wsgi:application"]version: '3.8'
services:
web:
build: .
ports:
- "8000:8000"
environment:
- DEBUG=False
- SECRET_KEY=your-secret-key
volumes:
- ./media:/app/media
- ./staticfiles:/app/staticfiles
depends_on:
- db
db:
image: postgres:13
environment:
- POSTGRES_DB=sahay_ai
- POSTGRES_USER=sahay_user
- POSTGRES_PASSWORD=sahay_password
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:docker-compose up --buildUpdate career_mentor_web/settings.py:
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY', 'your-secret-key-here')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG', 'False').lower() == 'true'
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', 'localhost,127.0.0.1').split(',')
# Database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Use PostgreSQL in production
if not DEBUG:
import dj_database_url
DATABASES['default'] = dj_database_url.parse(os.environ.get('DATABASE_URL'))
# Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
# Media files
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# Security settings
if not DEBUG:
SECURE_BROWSER_XSS_FILTER = True
SECURE_CONTENT_TYPE_NOSNIFF = True
X_FRAME_OPTIONS = 'DENY'
SECURE_HSTS_SECONDS = 31536000
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = Truepython manage.py makemigrations
python manage.py migrate# Install psycopg2
pip install psycopg2-binary
# Update requirements.txt
echo "psycopg2-binary==2.9.9" >> requirements.txt
# Run migrations
python manage.py migrate# Backup
python manage.py dumpdata > backup.json
# Restore
python manage.py loaddata backup.jsonpython manage.py collectstatic --noinputAdd to MIDDLEWARE in settings.py:
MIDDLEWARE = [
# ... other middleware
'whitenoise.middleware.WhiteNoiseMiddleware',
# ... other middleware
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'# For AWS S3 or other CDN
STATIC_URL = 'https://your-cdn-domain.com/static/'
MEDIA_URL = 'https://your-cdn-domain.com/media/'# Never commit these to version control
SECRET_KEY=your-super-secret-key
DEBUG=False
ALLOWED_HOSTS=your-domain.com
DATABASE_URL=postgres://user:pass@host:port/dbAdd to settings.py:
SECURE_BROWSER_XSS_FILTER = True
SECURE_CONTENT_TYPE_NOSNIFF = True
X_FRAME_OPTIONS = 'DENY'
SECURE_HSTS_SECONDS = 31536000
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = True# Force HTTPS
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')Add to settings.py:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': 'django.log',
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'INFO',
'propagate': True,
},
},
}Add to career_advisor/views.py:
from django.http import JsonResponse
def health_check(request):
return JsonResponse({'status': 'healthy'})# Monitor CPU and memory
htop
# Monitor logs
tail -f django.log
# Monitor database
python manage.py dbshellpython manage.py collectstatic --noinput
# Check STATIC_ROOT and STATICFILES_STORAGE settings# Check DATABASE_URL format
# Ensure database is running
# Check credentials# Check available memory
# Verify model files are downloaded
# Check internet connection for model downloads# Check MEDIA_ROOT permissions
# Ensure directory exists
# Check file size limits# Check Django settings
python manage.py check --deploy
# Test database connection
python manage.py dbshell
# Check static files
python manage.py findstatic admin/css/base.css
# Monitor logs
tail -f /var/log/nginx/error.log- All tests passing
- Environment variables configured
- Database migrations ready
- Static files collected
- Security settings updated
- Logging configured
- Code pushed to repository
- Build successful
- Database migrated
- Static files served
- Health check passing
- SSL certificate installed
- Application accessible
- All features working
- Performance acceptable
- Monitoring active
- Backup configured
- Documentation updated
# One-command deployment
git add . && git commit -m "Deploy" && git push heroku main && heroku run python manage.py migrate# Deploy to Railway
railway up# Test production settings locally
DEBUG=False python manage.py runserver- GitHub Issues: Report bugs and feature requests
- Documentation: Check project README.md
- Community: Django forums and Stack Overflow
Your Sahay AI application is now ready for deployment! Choose the platform that best fits your needs and follow the corresponding guide.
Good luck with your hackathon presentation! 🚀
Built with ❤️ by Soham Tripathy