diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fe13f86 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# Use an official Python runtime as a base image +FROM python:3.13.5-slim-bookworm + +# 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 build-essential libpq-dev && \ + rm -rf /var/lib/apt/lists/* + +# Install Python dependencies +COPY requirements.txt /app/ +RUN pip install --upgrade pip && pip install -r requirements.txt + +# Copy project +COPY . /app/ + +# Run migrations & collect static in production (optional) +# CMD ["python", "manage.py", "migrate"] && ["python", "manage.py", "collectstatic", "--noinput"] + +# Command to run the server +# CMD ["gunicorn", "freekake_api.wsgi:application", "--bind", "0.0.0.0:8000"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..02a5996 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +services: + + web: + build: + context: . + dockerfile: ./Dockerfile + # command: gunicorn freekake_api.wsgi:application --bind 0.0.0.0:8000 + command: sh -c "gunicorn freekake_api.wsgi:application --bind 0.0.0.0:8000" + volumes: + - .:/app + - static_volume:/app/static + expose: + - "8000" + + nginx: + image: nginx:1.28-bookworm + ports: + - "80:80" + volumes: + - ./nginx.conf:/etc/nginx/conf.d/default.conf + - static_volume:/static + depends_on: + - web + +volumes: + static_volume: diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..2bf5267 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,30 @@ +# nginx.conf +client_max_body_size 8M; + +upstream django_app { + server freekake_api:8000; +} + +server { + listen 80; + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + client_max_body_size 50M; + + location / { + proxy_pass http://web:8000; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_redirect off; + } + + # OPTIONAL: serve static files if needed + location /static/ { + alias /static/; + } + + location /media/ { + alias /media/; + } +}