Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
# ADD DOCKERFILE CONTENT HERE
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"]
78 changes: 77 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1 +1,77 @@
# ADD Docker Compose CONTENT HERE
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
42 changes: 41 additions & 1 deletion nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1 +1,41 @@
# ADD NGINX CONTENT HERE
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;
}
}
}