From 8412358206aa28b87843069f72164cebe3933f41 Mon Sep 17 00:00:00 2001 From: Shadi Date: Fri, 24 Oct 2025 19:24:10 +0330 Subject: [PATCH] done --- Dockerfile | 24 +++++++++++++- docker-compose.yml | 78 +++++++++++++++++++++++++++++++++++++++++++++- nginx/nginx.conf | 42 ++++++++++++++++++++++++- 3 files changed, 141 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 26a8f8a..ee61595 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,23 @@ -# ADD DOCKERFILE CONTENT HERE \ No newline at end of file +FROM python:3.11-slim + +WORKDIR /app + +RUN apt-get update && apt-get install -y \ + postgresql-client \ + gcc \ + python3-dev \ + musl-dev \ + libpq-dev \ + && rm -rf /var/lib/apt/lists/* + +COPY requirements.txt /app/ +RUN pip install --upgrade pip +RUN pip install -r requirements.txt + +COPY . /app/ + +WORKDIR /app/app + +RUN python manage.py collectstatic --noinput || true + +CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "config.wsgi:application"] diff --git a/docker-compose.yml b/docker-compose.yml index a3437d1..886c357 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1 +1,77 @@ -# ADD Docker Compose CONTENT HERE \ No newline at end of file +version: '3.8' + +services: + db: + image: postgres:15-alpine + volumes: + - postgres_data:/var/lib/postgresql/data + environment: + - POSTGRES_DB=${POSTGRES_DB} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + networks: + - app-network + restart: always + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"] + interval: 10s + timeout: 5s + retries: 5 + + redis: + image: redis:7-alpine + volumes: + - redis_data:/data + networks: + - app-network + restart: always + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 10s + timeout: 3s + retries: 5 + + web: + build: . + command: gunicorn --bind 0.0.0.0:8000 --workers 3 config.wsgi:application + volumes: + - ./app:/app/app + - static_volume:/app/app/staticfiles + - media_volume:/app/app/media + expose: + - "8000" + env_file: + - .env + depends_on: + db: + condition: service_healthy + redis: + condition: service_healthy + networks: + - app-network + restart: always + + nginx: + image: nginx:alpine + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro + - static_volume:/app/app/staticfiles + - media_volume:/app/app/media + ports: + - "80:80" + - "443:443" + depends_on: + - web + networks: + - app-network + restart: always + +volumes: + postgres_data: + redis_data: + static_volume: + media_volume: + +networks: + app-network: + driver: bridge diff --git a/nginx/nginx.conf b/nginx/nginx.conf index ed468cf..f11a171 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1 +1,41 @@ -# ADD NGINX CONTENT HERE \ No newline at end of file +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + upstream django { + server web:8000; + } + + server { + listen 80; + server_name _; + + client_max_body_size 100M; + + # Static files + location /static/ { + alias /app/staticfiles/; + expires 30d; + } + + # Media files + location /media/ { + alias /app/media/; + expires 30d; + } + + # Proxy all other requests to Django + location / { + proxy_pass http://django; + 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_redirect off; + } + } +}