From 06a304579cf9198baf40d630823674c9cfe37f17 Mon Sep 17 00:00:00 2001 From: acidburnmonkey Date: Wed, 6 Aug 2025 02:37:54 -0400 Subject: [PATCH 1/2] docker builder --- Dockerfile | 38 ++++++++++++++++++++++++++++++++++++++ nginx.conf | 25 +++++++++++++++++++++++++ start.sh | 6 ++++++ 3 files changed, 69 insertions(+) create mode 100644 Dockerfile create mode 100644 nginx.conf create mode 100644 start.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fc93131 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM python:3.13-alpine + +# install nginx and runtime deps, plus a build-deps group for uv sync +RUN apk add --no-cache nginx libffi openssl +RUN apk add --no-cache --virtual .build-deps build-base libffi-dev openssl-dev python3-dev + + # grab uv CLI +RUN mkdir -p /usr/local/bin \ + && wget -qO /usr/local/bin/uv https://ghcr.io/astral-sh/uv:latest/uv \ + && wget -qO /usr/local/bin/uvx https://ghcr.io/astral-sh/uv:latest/uvx \ + && chmod +x /usr/local/bin/uv /usr/local/bin/uvx + +WORKDIR /app + +# install your Python deps +COPY uv.lock pyproject.toml ./ +RUN uv sync --frozen --no-cache \ + # drop build tools once deps are in place + && apk del .build-deps + +# copy in the rest of your Django project +COPY . . + +# collectstatic +RUN uv run python manage.py collectstatic --noinput + +# copy nginx config +COPY nginx.conf /etc/nginx/nginx.conf + +EXPOSE 80 + +# start.sh should launch both nginx and uvicorn +COPY start.sh /start.sh +RUN chmod +x /start.sh + +CMD ["/start.sh"] + + diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..270fb79 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,25 @@ +server { + listen 80; + server_name acidarchon.com www.acidarchon.com localhost; + + # Serve static files + location /static/ { + alias /app/staticfiles/; + expires 30d; + add_header Cache-Control "public, immutable"; + } + + # Proxy to Django + location / { + proxy_pass http://web:8000; # 'web' is the service name + 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; + + # WebSocket support + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } +} diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..419f2bc --- /dev/null +++ b/start.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# Start uvicorn in background +uv run uvicorn mysite.asgi:application --host 127.0.0.1 --port 8000 & + +# Start nginx in foreground +nginx -g "daemon off;" From 93225d39581957923c44e755276c3f2228108616 Mon Sep 17 00:00:00 2001 From: acidburnmonkey Date: Wed, 6 Aug 2025 02:47:15 -0400 Subject: [PATCH 2/2] modified: nginx.conf --- nginx.conf | 58 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/nginx.conf b/nginx.conf index 270fb79..fdccc87 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,25 +1,45 @@ -server { - listen 80; - server_name acidarchon.com www.acidarchon.com localhost; +# user & worker settings +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; - # Serve static files - location /static/ { - alias /app/staticfiles/; - expires 30d; - add_header Cache-Control "public, immutable"; +events { + worker_connections 1024; +} + +http { + # basic settings + include /etc/nginx/mime.types; + default_type application/octet-stream; + sendfile on; + keepalive_timeout 65; + + # upstream for Uvicorn + upstream app { + server 127.0.0.1:8000; } - # Proxy to Django - location / { - proxy_pass http://web:8000; # 'web' is the service name - 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; + server { + listen 80; + server_name _; - # WebSocket support - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; + # serve static files + location /static/ { + alias /app/static/; + expires 30d; + add_header Cache-Control "public"; + } + + # proxy everything else to Uvicorn + location / { + proxy_pass http://app; + 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; + } } } + +