From a94cf6fe1e8eee6595dcfb412474fae823d2df01 Mon Sep 17 00:00:00 2001 From: Stephan Kerkman Date: Thu, 28 May 2026 10:07:18 +0200 Subject: [PATCH] feat: Docker Compose deployment with Nginx and Gunicorn Co-Authored-By: Claude Sonnet 4.6 --- Dockerfile | 14 ++++++++++++++ docker-compose.yml | 32 ++++++++++++++++++++++++++++++++ nginx/default.conf | 24 ++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 nginx/default.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..59ce1ec --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM python:3.12-slim + +WORKDIR /app + +RUN apt-get update && apt-get install -y --no-install-recommends \ + libpq-dev gcc \ + && rm -rf /var/lib/apt/lists/* + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +EXPOSE 8000 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2c91eaa --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +services: + web: + build: . + env_file: .env + volumes: + - db:/app/db.sqlite3 + - media:/app/media + - static:/app/staticfiles + expose: + - "8000" + command: > + sh -c "python manage.py migrate --noinput && + python manage.py collectstatic --noinput && + gunicorn plantdb.wsgi:application --bind 0.0.0.0:8000 --workers 2" + restart: unless-stopped + + nginx: + image: nginx:alpine + ports: + - "80:80" + volumes: + - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro + - media:/app/media:ro + - static:/app/staticfiles:ro + depends_on: + - web + restart: unless-stopped + +volumes: + db: + media: + static: diff --git a/nginx/default.conf b/nginx/default.conf new file mode 100644 index 0000000..d4de274 --- /dev/null +++ b/nginx/default.conf @@ -0,0 +1,24 @@ +upstream django { + server web:8000; +} + +server { + listen 80; + client_max_body_size 20M; + + location /static/ { + alias /app/staticfiles/; + } + + location /media/ { + alias /app/media/; + } + + 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; + } +}