diff --git a/README.md b/README.md index 2c98a23..d8fa9bf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,39 @@ # The Fallen Birdy Form +## 🚀 Schneller Einstieg + +Für einen schnellen Start des Projekts verwenden Sie die bereitgestellten Skripte: + +### Start des Projekts +```bash +./start_project.sh +``` + +Das Start-Skript führt automatisch folgende Schritte aus: +- Erstellt eine `.env` Datei mit Entwicklungseinstellungen +- Baut und startet alle Docker Container (Web, Datenbank, Traefik) +- Führt Django Migrations aus +- Lädt Testdaten (Fixtures) +- Erstellt einen Admin-Benutzer +- Sammelt statische Dateien + +**Nach dem Start ist die Anwendung verfügbar unter:** +- **Hauptanwendung**: [http://localhost:8008](http://localhost:8008) +- **Admin-Panel**: [http://localhost:8008/admin](http://localhost:8008/admin) + +**Standard Admin-Zugang:** +- Benutzername: `admin` +- Passwort: `admin` + +### Stop des Projekts +```bash +./stop_project.sh +``` + +Das Stop-Skript stoppt alle Container und räumt auf. + +--- + ## Throw old database In case you've got an preexisting database, delete it and do the following: @@ -82,7 +116,16 @@ CSRF_TRUSTED_ORIGINS=[os.getenv('CSRF_TRUSTED_ORIGINS')] ## How to use this project? -### Development +### Einfachster Weg (Empfohlen) +Verwenden Sie die bereitgestellten Skripte für einen schnellen Start: +```bash +./start_project.sh # Projekt starten +./stop_project.sh # Projekt stoppen +``` + +### Manueller Weg + +#### Development Build the images and spin up the containers: @@ -92,8 +135,8 @@ $ docker-compose up -d --build Test it out: -1. [http://django.localhost:8008/](http://django.localhost:8008/) -1. [http://django.localhost:8081/](http://django.localhost:8081/) +1. [http://localhost:8008/](http://localhost:8008/) - Hauptanwendung +1. [http://localhost:8081/](http://localhost:8081/) - Traefik Dashboard ### Production diff --git a/start_project.sh b/start_project.sh new file mode 100755 index 0000000..1b3ce34 --- /dev/null +++ b/start_project.sh @@ -0,0 +1,142 @@ +#!/bin/bash + +# Django FBF Projekt Startup Script +# Dieses Skript startet das Projekt und erstellt einen Admin-Benutzer + +set -e # Script bei Fehlern beenden + +echo "🚀 Django FBF Projekt wird gestartet..." + +# Überprüfen ob Docker läuft +if ! docker info > /dev/null 2>&1; then + echo "❌ Docker ist nicht gestartet. Bitte starten Sie Docker Desktop." + exit 1 +fi + +# .env Datei erstellen falls sie nicht existiert +if [ ! -f .env ]; then + echo "📝 Erstelle .env Datei..." + cp .env.example .env + + # Secret Key generieren + SECRET_KEY=$(openssl rand -base64 50 | tr -d "=+/" | cut -c1-50) + + # .env Datei mit Entwicklungseinstellungen anpassen + cat > .env << EOF +# APP URL +APP_URL='http://localhost:8008' + +# Allowed Hosts (für Traefik Route - nur ein Host) +ALLOWED_HOSTS='localhost' + +# Database +DB_HOST='db' +DB_NAME='db_fbf' +DB_PASSWORD='superSecret' +DB_PORT='5432' +DB_USER='fbf' + +# Debugging +DEBUG='True' + +# Secrets +SECRET_KEY='${SECRET_KEY}' + +# CSRF +CSRF_TRUSTED_ORIGINS='http://localhost:8008,http://127.0.0.1:8008' + +# Email (Optional - für lokale Entwicklung) +DEFAULT_FROM_EMAIL='admin@localhost' +EMAIL_HOST_PASSWORD='' +EMAIL_HOST_USER='' +EMAIL_HOST='' +EMAIL_PORT=25 +EOF + echo "✅ .env Datei erstellt" +else + echo "📄 .env Datei bereits vorhanden" +fi + +# Docker Container stoppen falls sie laufen +echo "🛑 Stoppe eventuell laufende Container..." +docker compose down --remove-orphans > /dev/null 2>&1 || true + +# Docker Images bauen und Container starten +echo "🔨 Baue Docker Images..." +docker compose build --no-cache + +echo "🐳 Starte Docker Container..." +docker compose up -d + +# Warten bis die Datenbank bereit ist +echo "⏳ Warte auf Datenbankverbindung..." +until docker compose exec db pg_isready -U fbf -d db_fbf > /dev/null 2>&1; do + echo " ... Datenbank startet noch..." + sleep 2 +done + +echo "✅ Datenbank ist bereit" + +# Warten bis der Web-Container läuft +echo "⏳ Warte auf Web-Container..." +sleep 10 + +# Django Migrations ausführen +echo "🔄 Führe Django Migrations aus..." +docker compose exec -T web python manage.py makemigrations +docker compose exec -T web python manage.py migrate + +# Fixtures laden (falls vorhanden) +if [ -d "app/fixtures" ] && [ "$(ls -A app/fixtures)" ]; then + echo "📦 Lade Fixtures..." + for fixture in app/fixtures/*.json; do + if [ -f "$fixture" ]; then + echo " Lade $(basename "$fixture")..." + docker compose exec -T web python manage.py loaddata "fixtures/$(basename "$fixture")" || true + fi + done +fi + +# Admin-Benutzer erstellen +echo "👤 Erstelle Admin-Benutzer..." +cat << 'EOF' | docker compose exec -T web python manage.py shell +from django.contrib.auth.models import User + +# Überprüfen ob Admin-User bereits existiert +if User.objects.filter(username='admin').exists(): + print("Admin-Benutzer existiert bereits") + user = User.objects.get(username='admin') + user.set_password('admin') + user.is_superuser = True + user.is_staff = True + user.save() + print("Admin-Passwort wurde auf 'admin' zurückgesetzt") +else: + # Neuen Admin-User erstellen + User.objects.create_superuser('admin', 'admin@localhost', 'admin') + print("Admin-Benutzer erstellt") + print("Benutzername: admin") + print("Passwort: admin") +EOF + +# Static Files sammeln +echo "📁 Sammle Static Files..." +docker compose exec -T web python manage.py collectstatic --noinput --clear + +echo "" +echo "🎉 Projekt erfolgreich gestartet!" +echo "" +echo "📋 Informationen:" +echo " 🌐 Anwendung: http://localhost:8008" +echo " 🔧 Admin-Panel: http://localhost:8008/admin" +echo " 👤 Admin-Login:" +echo " Benutzername: admin" +echo " Passwort: admin" +echo "" +echo "📝 Nützliche Befehle:" +echo " docker compose logs -f web # Logs anzeigen" +echo " docker compose down # Projekt stoppen" +echo " docker compose up -d # Projekt starten" +echo "" +echo "🔍 Container Status:" +docker compose ps diff --git a/stop_project.sh b/stop_project.sh new file mode 100755 index 0000000..e197e9a --- /dev/null +++ b/stop_project.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Django FBF Projekt Stopp Script + +echo "🛑 Stoppe Django FBF Projekt..." + +# Docker Container stoppen +docker compose down + +echo "✅ Projekt gestoppt" +echo "" +echo "📝 Zum erneuten Starten verwenden Sie:" +echo " ./start_project.sh"