From a250fa2d620c964652da7f9407fab37aabd83c67 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 21 May 2026 05:15:48 -0500 Subject: [PATCH] stanalone --- .python-version | 1 + Caddyfile | 33 +++++++++++++++++++++++++ Dockerfile | 29 ++++++++++++++++++++++ boday_it/settings.py | 2 +- deploystaticfiles.sh | 1 + docker-compose.yml | 56 +++++++++++++++++++++++++++++++++++++++++++ project.db | Bin 782336 -> 782336 bytes requirements.txt | 5 ++-- 8 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 .python-version create mode 100644 Caddyfile create mode 100644 Dockerfile create mode 100644 deploystaticfiles.sh create mode 100644 docker-compose.yml diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..9ad6380 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.8.18 diff --git a/Caddyfile b/Caddyfile new file mode 100644 index 0000000..bec974e --- /dev/null +++ b/Caddyfile @@ -0,0 +1,33 @@ +boday-it.ch { + # 1. Globale Komprimierung für schnellere Ladezeiten aktivieren + encode gzip zstd + + # 2. Statische Dateien (CSS, JS, Bilder) direkt über Caddy ausliefern + handle_path /static/* { + root * /code/staticfiles + file_server + } + + # 3. Medien-Dateien (User-Uploads) direkt über Caddy ausliefern + handle_path /media/* { + root * /code/mediafiles + file_server + } + + # 4. Alle anderen Anfragen direkt an den Django-Gunicorn-Container weiterleiten + handle { + reverse_proxy web:8000 + } + + # 5. Sicherheits-Header setzen (Optional, aber dringend empfohlen) + header { + # Verhindert, dass die Seite in einem fremden Frame geladen wird (Schutz vor Clickjacking) + X-Frame-Options "DENY" + # Aktiviert den Cross-Site-Scripting-Schutz im Browser + X-XSS-Protection "1; mode=block" + # Verhindert das automatische Erraten des Inhaltstyps (MIME-Sniffing) + X-Content-Type-Options "nosniff" + # Strict-Transport-Security (HSTS) - Erzwingt HTTPS im Browser für 1 Jahr + Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" + } +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..64e7738 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# 1. Verwende das offizielle Python 3.8.18 Image auf minimaler Debian-Basis +FROM python:3.8.18-slim + +# 2. Setze Umgebungsvariablen für Python +# Verhindert, dass Python .pyc-Dateien schreibt +ENV PYTHONDONTWRITEBYTECODE=1 +# Verhindert, dass Python Ausgaben puffert (wichtig für Echtzeit-Docker-Logs) +ENV PYTHONUNBUFFERED=1 + +# 3. Setze das Arbeitsverzeichnis im Container +WORKDIR /code + +# 4. Installiere System-Abhängigkeiten +# gcc und libpq-dev werden für PostgreSQL (psycopg2) und einige Python-Pakete benötigt +RUN apt-get update && apt-get install -y --no-install-recommends \ + gcc \ + libpq-dev \ + && rm -rf /var/lib/apt/lists/* + +# 5. Installiere die Python-Abhängigkeiten +# Zuerst requirements.txt kopieren, um den Docker-Cache optimal zu nutzen +COPY requirements.txt /code/ +RUN pip install --upgrade pip && pip install -r requirements.txt + +# 6. Kopiere den restlichen Django-Quellcode in den Container +COPY . /code/ + +# 7. Erstelle die Ordner für statische Medien (wichtig für die Caddy-Anbindung) +RUN mkdir -p /code/staticfiles /code/mediafiles diff --git a/boday_it/settings.py b/boday_it/settings.py index bb5c0e1..bdc0012 100644 --- a/boday_it/settings.py +++ b/boday_it/settings.py @@ -32,7 +32,7 @@ SECRET_KEY = '2^!=u2@h+36s^_ikb9=#)10gr#ymp1ds0d0*)d@b+e8%9$vv-v' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ['ww2.boday-it.ch', '127.0.0.1'] +ALLOWED_HOSTS = ['www.boday-it.ch', '127.0.0.1','boday-it.ch'] # Application definition diff --git a/deploystaticfiles.sh b/deploystaticfiles.sh new file mode 100644 index 0000000..5755475 --- /dev/null +++ b/deploystaticfiles.sh @@ -0,0 +1 @@ +docker compose exec web python manage.py collectstatic --noinput diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..eb3d2e9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,56 @@ +version: '3.8' + +services: + # Django Web Application (Python 3.8.18) + web: + build: + context: . + dockerfile: Dockerfile + command: gunicorn boday_it.wsgi:application --bind 0.0.0.0:8000 + volumes: + - .:/code + - static_volume:/code/staticfiles + - media_volume:/code/mediafiles + environment: + - DEBUG=0 + - SECRET_KEY=aldhguroqugaplslljdgzlshfz + - ALLOWED_HOSTS=boday-it.ch,www.boday-it.ch,web,localhost,127.0.0.1 + expose: + - "8000" + restart: always + depends_on: + - db + + # PostgreSQL Database Server + db: + image: postgres:15-alpine + volumes: + - postgres_data:/var/lib/postgresql/data + environment: + - POSTGRES_DB=djangodb + - POSTGRES_USER=djangouser + - POSTGRES_PASSWORD=asafdksdf + restart: always + + # Automatic Let's Encrypt SSL & Reverse Proxy (Caddy) + proxy: + image: caddy:2-alpine + ports: + - "80:80" # Natively handles HTTP-01 challenges + - "443:443" # Natively serves HTTPS + volumes: + - ./Caddyfile:/etc/caddy/Caddyfile + - static_volume:/code/staticfiles:ro + - media_volume:/code/mediafiles:ro + - caddy_data:/data + - caddy_config:/config + restart: always + depends_on: + - web + +volumes: + postgres_data: + static_volume: + media_volume: + caddy_data: # Important: Keeps your SSL certs safe across container restarts + caddy_config: diff --git a/project.db b/project.db index 37d18a587838fcc541c60e3c7171586d866f2481..492e75b67d0b7485ef25048ba1999e3e760d9d94 100644 GIT binary patch delta 355 zcmZp8px^L7e}Xh)^F$eE)@BC1WX6ptOLQ5Pn>qE`IrSKUmdyq!!1gq{bUs6_h6BWG1UODS=g{=3!NtnunxP5zR~kTxM!EDWDmOq7=!{ z_6zITftUk`Ik#U}&t;Op%);HXon3(2oojQ0fgR)a9%=3h79JMqE`IrSKUm}&*k^vzq4IHf!l&#RfXA?k&qKvr|0T(PiJQ3PutFJz#Y%8 aEXVA~h}$w&ko0sNS#GKAi|x5%Hvj;)+IC3* diff --git a/requirements.txt b/requirements.txt index 36d217d..a2a5e90 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ django-cms>=3.6,<3.7 djangocms-admin-style>=1.2,<1.3 django-treebeard>=4.0,<5.0 - djangocms-text-ckeditor>=3.7,<3.8 djangocms-link>=2.3 djangocms-style>=2.1 @@ -20,4 +19,6 @@ html5lib>=1.0.1 Pillow>=3.0 django-sekizai>=0.9 six -pytz \ No newline at end of file +pytz +gunicorn>=20.1.0 +psycopg2-binary>=2.9.0