stanalone

This commit is contained in:
root 2026-05-21 05:15:48 -05:00
parent b7585c4333
commit a250fa2d62
8 changed files with 124 additions and 3 deletions

1
.python-version Normal file
View file

@ -0,0 +1 @@
3.8.18

33
Caddyfile Normal file
View file

@ -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"
}
}

29
Dockerfile Normal file
View file

@ -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

View file

@ -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

1
deploystaticfiles.sh Normal file
View file

@ -0,0 +1 @@
docker compose exec web python manage.py collectstatic --noinput

56
docker-compose.yml Normal file
View file

@ -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:

Binary file not shown.

View file

@ -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
@ -21,3 +20,5 @@ Pillow>=3.0
django-sekizai>=0.9
six
pytz
gunicorn>=20.1.0
psycopg2-binary>=2.9.0