2 Commits
bef4b50d6b
...
488f413672
| Author | SHA1 | Message | Date |
|---|---|---|---|
|
|
488f413672 |
feat(deploy): add automated Linux production deployment script deploy.sh
|
11 hours ago |
|
|
91e8a4d423 |
feat(prod): configure Gunicorn, WhiteNoise static file serving, and Nginx reverse proxy
|
11 hours ago |
8 changed files with 127 additions and 28 deletions
-
22.env.example
-
18backend/config/settings.py
-
30deploy.sh
-
17docker-compose.yml
-
6entrypoint.sh
-
16frontend/Dockerfile
-
43frontend/nginx.conf
-
3requirements.txt
@ -1,23 +1,23 @@ |
|||||
# Django Settings |
|
||||
DJANGO_SECRET_KEY=django-insecure-your-secret-key-here |
|
||||
DJANGO_DEBUG=True |
|
||||
ALLOWED_HOSTS=localhost,127.0.0.1,* |
|
||||
|
# Django Production Settings |
||||
|
DJANGO_SECRET_KEY=generate-a-strong-random-secret-key-here |
||||
|
DJANGO_DEBUG=False |
||||
|
ALLOWED_HOSTS=* |
||||
CORS_ALLOW_ALL_ORIGINS=True |
CORS_ALLOW_ALL_ORIGINS=True |
||||
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://localhost:5173 |
|
||||
|
CSRF_TRUSTED_ORIGINS=http://localhost,http://127.0.0.1,http://YOUR_SERVER_IP |
||||
|
|
||||
# Database Configuration (PostgreSQL) |
# Database Configuration (PostgreSQL) |
||||
POSTGRES_DB=divar_crawler |
POSTGRES_DB=divar_crawler |
||||
POSTGRES_USER=postgres |
POSTGRES_USER=postgres |
||||
POSTGRES_PASSWORD=postgres |
|
||||
POSTGRES_HOST=localhost |
|
||||
|
POSTGRES_PASSWORD=your_secure_postgres_password |
||||
|
POSTGRES_HOST=db |
||||
POSTGRES_PORT=5432 |
POSTGRES_PORT=5432 |
||||
|
|
||||
# Redis & Celery |
# Redis & Celery |
||||
REDIS_URL=redis://localhost:6379/0 |
|
||||
|
REDIS_URL=redis://redis:6379/0 |
||||
|
|
||||
# LLM Config (OpenAI / Gemini) |
|
||||
OPENAI_API_KEY=your-openai-api-key-here |
|
||||
# Optional: LLM_MODEL_NAME=gpt-4o-mini |
|
||||
|
# LLM Config (OpenAI / OpenRouter) |
||||
|
OPENAI_API_KEY=sk-or-v1-your-openrouter-key |
||||
|
OPENAI_MODEL=google/gemma-4-26b-a4b-it:free |
||||
|
|
||||
# Telegram Config |
# Telegram Config |
||||
TELEGRAM_BOT_TOKEN=your-telegram-bot-token-here |
TELEGRAM_BOT_TOKEN=your-telegram-bot-token-here |
||||
@ -0,0 +1,30 @@ |
|||||
|
#!/bin/bash |
||||
|
set -e |
||||
|
|
||||
|
echo "=== Divar Crawler Production Deployment Script ===" |
||||
|
|
||||
|
# Check if docker is installed |
||||
|
if ! command -v docker &> /dev/null; then |
||||
|
echo "Error: docker is not installed. Please install Docker and Docker Compose." |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
# Create .env from .env.example if missing |
||||
|
if [ ! -f .env ]; then |
||||
|
echo "Creating .env from .env.example..." |
||||
|
cp .env.example .env |
||||
|
echo "WARNING: Please edit .env and set your OPENAI_API_KEY and passwords before running!" |
||||
|
fi |
||||
|
|
||||
|
echo "Pulling latest code changes..." |
||||
|
git pull origin master || true |
||||
|
|
||||
|
echo "Building and launching containers..." |
||||
|
docker compose down || true |
||||
|
docker compose up -d --build |
||||
|
|
||||
|
echo "Checking container statuses..." |
||||
|
docker compose ps |
||||
|
|
||||
|
echo "=== Deployment Successful! ===" |
||||
|
echo "Access the application at http://localhost or your server's IP address." |
||||
@ -1,12 +1,20 @@ |
|||||
FROM node:22-slim |
|
||||
|
# Stage 1: Build Vite frontend |
||||
|
FROM node:22-alpine AS build |
||||
|
|
||||
WORKDIR /app/frontend |
WORKDIR /app/frontend |
||||
|
|
||||
COPY frontend/package*.json ./ |
COPY frontend/package*.json ./ |
||||
RUN npm install |
|
||||
|
RUN npm ci || npm install |
||||
|
|
||||
COPY frontend ./ |
COPY frontend ./ |
||||
|
RUN npm run build |
||||
|
|
||||
EXPOSE 5173 |
|
||||
|
# Stage 2: Production Nginx server |
||||
|
FROM nginx:alpine |
||||
|
|
||||
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"] |
|
||||
|
COPY --from=build /app/frontend/dist /usr/share/nginx/html |
||||
|
COPY frontend/nginx.conf /etc/nginx/conf.d/default.conf |
||||
|
|
||||
|
EXPOSE 80 |
||||
|
|
||||
|
CMD ["nginx", "-g", "daemon off;"] |
||||
@ -0,0 +1,43 @@ |
|||||
|
server { |
||||
|
listen 80; |
||||
|
server_name _; |
||||
|
|
||||
|
root /usr/share/nginx/html; |
||||
|
index index.html; |
||||
|
|
||||
|
# Gzip compression for fast asset loading |
||||
|
gzip on; |
||||
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; |
||||
|
|
||||
|
# Frontend SPA routing |
||||
|
location / { |
||||
|
try_files $uri $uri/ /index.html; |
||||
|
} |
||||
|
|
||||
|
# Proxy Django API requests |
||||
|
location /api/ { |
||||
|
proxy_pass http://backend:8000; |
||||
|
proxy_set_header Host $host; |
||||
|
proxy_set_header X-Real-IP $remote_addr; |
||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
||||
|
proxy_set_header X-Forwarded-Proto $scheme; |
||||
|
} |
||||
|
|
||||
|
# Proxy Django Admin interface |
||||
|
location /admin/ { |
||||
|
proxy_pass http://backend:8000; |
||||
|
proxy_set_header Host $host; |
||||
|
proxy_set_header X-Real-IP $remote_addr; |
||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
||||
|
proxy_set_header X-Forwarded-Proto $scheme; |
||||
|
} |
||||
|
|
||||
|
# Proxy Django static files (admin assets, etc.) |
||||
|
location /static/ { |
||||
|
proxy_pass http://backend:8000; |
||||
|
proxy_set_header Host $host; |
||||
|
proxy_set_header X-Real-IP $remote_addr; |
||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
||||
|
proxy_set_header X-Forwarded-Proto $scheme; |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue