"feat: Implement Docker Compose for backend and frontend servers"
This commit is contained in:
parent
ef6a8f7b81
commit
359cb4a219
@ -1 +1,178 @@
|
|||||||
|
# 🏭 MYP Backend - Standalone Server Konfiguration
|
||||||
|
# Backend-Service als vollständig unabhängiger Server
|
||||||
|
|
||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
# === BACKEND SERVICE ===
|
||||||
|
backend:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
args:
|
||||||
|
- BUILDKIT_INLINE_CACHE=1
|
||||||
|
image: myp/backend:latest
|
||||||
|
container_name: myp-backend-standalone
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
environment:
|
||||||
|
# Flask-Konfiguration
|
||||||
|
- FLASK_APP=app.py
|
||||||
|
- FLASK_ENV=${FLASK_ENV:-production}
|
||||||
|
- PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
# Datenbank
|
||||||
|
- DATABASE_PATH=${DATABASE_PATH:-instance/myp.db}
|
||||||
|
|
||||||
|
# Sicherheit
|
||||||
|
- SECRET_KEY=${SECRET_KEY:-7445630171969DFAC92C53CEC92E67A9CB2E00B3CB2F}
|
||||||
|
- JWT_SECRET=${JWT_SECRET:-secure-jwt-secret}
|
||||||
|
|
||||||
|
# CORS-Konfiguration für Frontend-Zugriff
|
||||||
|
- CORS_ORIGINS=${CORS_ORIGINS:-http://localhost:3000,https://frontend.myp.local}
|
||||||
|
|
||||||
|
# Drucker-Konfiguration
|
||||||
|
- "PRINTERS=${PRINTERS:-{\"Drucker 1\": {\"ip\": \"192.168.0.100\"}, \"Drucker 2\": {\"ip\": \"192.168.0.101\"}, \"Drucker 3\": {\"ip\": \"192.168.0.102\"}, \"Drucker 4\": {\"ip\": \"192.168.0.103\"}, \"Drucker 5\": {\"ip\": \"192.168.0.104\"}, \"Drucker 6\": {\"ip\": \"192.168.0.106\"}}}"
|
||||||
|
|
||||||
|
# TAPO Smart Plug
|
||||||
|
- TAPO_USERNAME=${TAPO_USERNAME:-till.tomczak@mercedes-benz.com}
|
||||||
|
- TAPO_PASSWORD=${TAPO_PASSWORD:-744563017196A}
|
||||||
|
|
||||||
|
# Netzwerk
|
||||||
|
- HOST=0.0.0.0
|
||||||
|
- PORT=5000
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
- LOG_LEVEL=${LOG_LEVEL:-INFO}
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- backend_instance:/app/instance
|
||||||
|
- backend_logs:/app/logs
|
||||||
|
- backend_migrations:/app/migrations
|
||||||
|
- ./config:/app/config:ro
|
||||||
|
|
||||||
|
ports:
|
||||||
|
- "5000:5000" # Direkter Port-Zugang für Backend-Server
|
||||||
|
|
||||||
|
networks:
|
||||||
|
- backend-network
|
||||||
|
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 40s
|
||||||
|
|
||||||
|
labels:
|
||||||
|
- "service.type=backend"
|
||||||
|
- "service.name=myp-backend"
|
||||||
|
- "service.environment=${FLASK_ENV:-production}"
|
||||||
|
|
||||||
|
# === BACKEND DATENBANK (Optional: Separate PostgreSQL) ===
|
||||||
|
backend-db:
|
||||||
|
image: postgres:15-alpine
|
||||||
|
container_name: myp-backend-db
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
environment:
|
||||||
|
- POSTGRES_DB=${DB_NAME:-myp_backend}
|
||||||
|
- POSTGRES_USER=${DB_USER:-myp_user}
|
||||||
|
- POSTGRES_PASSWORD=${DB_PASSWORD:-secure_password}
|
||||||
|
- POSTGRES_HOST_AUTH_METHOD=trust
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- backend_db_data:/var/lib/postgresql/data
|
||||||
|
- ./sql/init:/docker-entrypoint-initdb.d:ro
|
||||||
|
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
|
||||||
|
networks:
|
||||||
|
- backend-network
|
||||||
|
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-myp_user} -d ${DB_NAME:-myp_backend}"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
# === BACKEND CACHE (Redis) ===
|
||||||
|
backend-cache:
|
||||||
|
image: redis:7.2-alpine
|
||||||
|
container_name: myp-backend-cache
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD:-backend_cache_password}
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- backend_cache_data:/data
|
||||||
|
|
||||||
|
ports:
|
||||||
|
- "6379:6379"
|
||||||
|
|
||||||
|
networks:
|
||||||
|
- backend-network
|
||||||
|
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "redis-cli", "ping"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 3
|
||||||
|
|
||||||
|
# === PERSISTENTE VOLUMES ===
|
||||||
|
volumes:
|
||||||
|
backend_instance:
|
||||||
|
driver: local
|
||||||
|
driver_opts:
|
||||||
|
type: none
|
||||||
|
o: bind
|
||||||
|
device: ./instance
|
||||||
|
|
||||||
|
backend_logs:
|
||||||
|
driver: local
|
||||||
|
driver_opts:
|
||||||
|
type: none
|
||||||
|
o: bind
|
||||||
|
device: ./logs
|
||||||
|
|
||||||
|
backend_migrations:
|
||||||
|
driver: local
|
||||||
|
driver_opts:
|
||||||
|
type: none
|
||||||
|
o: bind
|
||||||
|
device: ./migrations
|
||||||
|
|
||||||
|
backend_db_data:
|
||||||
|
driver: local
|
||||||
|
|
||||||
|
backend_cache_data:
|
||||||
|
driver: local
|
||||||
|
|
||||||
|
# === BACKEND-NETZWERK ===
|
||||||
|
networks:
|
||||||
|
backend-network:
|
||||||
|
driver: bridge
|
||||||
|
driver_opts:
|
||||||
|
com.docker.network.enable_ipv6: "false"
|
||||||
|
com.docker.network.bridge.enable_ip_masquerade: "true"
|
||||||
|
labels:
|
||||||
|
- "description=MYP Backend Server Netzwerk"
|
||||||
|
- "project=myp-backend"
|
||||||
|
- "tier=backend"
|
||||||
|
|
||||||
|
# === KONFIGURATION FÜR BACKEND ===
|
||||||
|
x-backend-defaults: &backend-defaults
|
||||||
|
restart: unless-stopped
|
||||||
|
logging:
|
||||||
|
driver: "json-file"
|
||||||
|
options:
|
||||||
|
max-size: "10m"
|
||||||
|
max-file: "3"
|
||||||
|
labels: "service,environment,tier"
|
||||||
|
|
||||||
|
x-healthcheck-backend: &backend-healthcheck
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 40s
|
66
backend/env.backend
Normal file
66
backend/env.backend
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
# 🏭 MYP Backend - Standalone Server Konfiguration
|
||||||
|
# Umgebungsvariablen ausschließlich für den Backend-Server
|
||||||
|
|
||||||
|
# === FLASK KONFIGURATION ===
|
||||||
|
FLASK_APP=app.py
|
||||||
|
FLASK_ENV=production
|
||||||
|
PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
# === DATENBANK KONFIGURATION ===
|
||||||
|
# SQLite (Default)
|
||||||
|
DATABASE_PATH=instance/myp.db
|
||||||
|
|
||||||
|
# PostgreSQL (Optional)
|
||||||
|
DB_NAME=myp_backend
|
||||||
|
DB_USER=myp_user
|
||||||
|
DB_PASSWORD=secure_backend_password
|
||||||
|
DB_HOST=localhost
|
||||||
|
DB_PORT=5432
|
||||||
|
|
||||||
|
# === SICHERHEIT ===
|
||||||
|
SECRET_KEY=7445630171969DFAC92C53CEC92E67A9CB2E00B3CB2F
|
||||||
|
JWT_SECRET=secure-jwt-secret-backend-2024
|
||||||
|
JWT_ACCESS_TOKEN_EXPIRES=3600
|
||||||
|
JWT_REFRESH_TOKEN_EXPIRES=2592000
|
||||||
|
|
||||||
|
# === CORS KONFIGURATION ===
|
||||||
|
# Erlaubte Frontend-Origins
|
||||||
|
CORS_ORIGINS=http://localhost:3000,https://frontend.myp.local,https://myp.frontend.local
|
||||||
|
|
||||||
|
# === DRUCKER KONFIGURATION ===
|
||||||
|
PRINTERS={"Drucker 1": {"ip": "192.168.0.100"}, "Drucker 2": {"ip": "192.168.0.101"}, "Drucker 3": {"ip": "192.168.0.102"}, "Drucker 4": {"ip": "192.168.0.103"}, "Drucker 5": {"ip": "192.168.0.104"}, "Drucker 6": {"ip": "192.168.0.106"}}
|
||||||
|
|
||||||
|
# === TAPO SMART PLUG ===
|
||||||
|
TAPO_USERNAME=till.tomczak@mercedes-benz.com
|
||||||
|
TAPO_PASSWORD=744563017196A
|
||||||
|
|
||||||
|
# === NETZWERK KONFIGURATION ===
|
||||||
|
HOST=0.0.0.0
|
||||||
|
PORT=5000
|
||||||
|
BACKEND_URL=http://localhost:5000
|
||||||
|
|
||||||
|
# === CACHE KONFIGURATION ===
|
||||||
|
REDIS_PASSWORD=backend_cache_password
|
||||||
|
REDIS_HOST=localhost
|
||||||
|
REDIS_PORT=6379
|
||||||
|
REDIS_DB=0
|
||||||
|
|
||||||
|
# === LOGGING ===
|
||||||
|
LOG_LEVEL=INFO
|
||||||
|
LOG_FILE=logs/backend.log
|
||||||
|
LOG_MAX_SIZE=10485760
|
||||||
|
LOG_BACKUP_COUNT=5
|
||||||
|
|
||||||
|
# === DATEISYSTEM ===
|
||||||
|
UPLOAD_FOLDER=uploads
|
||||||
|
MAX_CONTENT_LENGTH=16777216
|
||||||
|
|
||||||
|
# === MONITORING ===
|
||||||
|
HEALTH_CHECK_INTERVAL=30
|
||||||
|
METRICS_ENABLED=true
|
||||||
|
METRICS_PORT=9090
|
||||||
|
|
||||||
|
# === ENTWICKLUNG ===
|
||||||
|
DEBUG=false
|
||||||
|
TESTING=false
|
||||||
|
DEVELOPMENT=false
|
130
backend/start-backend-server.sh
Normal file
130
backend/start-backend-server.sh
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 🏭 MYP Backend - Standalone Server Start
|
||||||
|
# Startet den Backend-Server vollständig unabhängig vom Frontend
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🏭 MYP Backend - Standalone Server wird gestartet..."
|
||||||
|
|
||||||
|
# Farben für Terminal-Ausgabe
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Funktionen
|
||||||
|
log_info() {
|
||||||
|
echo -e "${BLUE}[INFO]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
log_success() {
|
||||||
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
log_warning() {
|
||||||
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
log_error() {
|
||||||
|
echo -e "${RED}[ERROR]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Arbeitsverzeichnis setzen
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
cd "$SCRIPT_DIR"
|
||||||
|
|
||||||
|
log_info "Arbeitsverzeichnis: $SCRIPT_DIR"
|
||||||
|
|
||||||
|
# Umgebungsvariablen laden
|
||||||
|
if [ -f ".env.backend" ]; then
|
||||||
|
log_info "Lade Backend-Umgebungsvariablen..."
|
||||||
|
export $(cat .env.backend | grep -v '^#' | xargs)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Prüfe Docker-Installation
|
||||||
|
if ! command -v docker &> /dev/null; then
|
||||||
|
log_error "Docker ist nicht installiert!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v docker-compose &> /dev/null; then
|
||||||
|
log_error "Docker Compose ist nicht installiert!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_success "Docker-Installation verifiziert"
|
||||||
|
|
||||||
|
# Alte Container stoppen und entfernen
|
||||||
|
log_info "Stoppe eventuell laufende Backend-Container..."
|
||||||
|
docker-compose -f docker-compose.backend.yml down --remove-orphans 2>/dev/null || true
|
||||||
|
|
||||||
|
# Images aufräumen (optional)
|
||||||
|
if [ "$1" = "--clean" ]; then
|
||||||
|
log_info "Räume alte Backend-Images auf..."
|
||||||
|
docker-compose -f docker-compose.backend.yml down --rmi all --volumes 2>/dev/null || true
|
||||||
|
docker system prune -f
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Notwendige Verzeichnisse erstellen
|
||||||
|
log_info "Erstelle notwendige Verzeichnisse..."
|
||||||
|
mkdir -p instance logs migrations/versions config
|
||||||
|
|
||||||
|
# Backend-Container builden und starten
|
||||||
|
log_info "Backend-Container werden gebaut und gestartet..."
|
||||||
|
docker-compose -f docker-compose.backend.yml up --build -d
|
||||||
|
|
||||||
|
# Warten auf Backend-Start
|
||||||
|
log_info "Warte auf Backend-Service..."
|
||||||
|
timeout=120
|
||||||
|
counter=0
|
||||||
|
|
||||||
|
while [ $counter -lt $timeout ]; do
|
||||||
|
if curl -f http://localhost:5000/health >/dev/null 2>&1; then
|
||||||
|
log_success "Backend-Server ist bereit!"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $((counter % 10)) -eq 0 ]; then
|
||||||
|
log_info "Warte auf Backend-Service... ($counter/$timeout Sekunden)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
counter=$((counter + 1))
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $counter -eq $timeout ]; then
|
||||||
|
log_error "Backend-Service konnte nicht gestartet werden!"
|
||||||
|
log_info "Zeige Backend-Logs:"
|
||||||
|
docker-compose -f docker-compose.backend.yml logs backend
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Migrationen ausführen
|
||||||
|
log_info "Führe Datenbank-Migrationen aus..."
|
||||||
|
docker-compose -f docker-compose.backend.yml exec backend flask db upgrade || log_warning "Migrationen fehlgeschlagen oder nicht erforderlich"
|
||||||
|
|
||||||
|
# Service-Status anzeigen
|
||||||
|
log_info "Backend-Service Status:"
|
||||||
|
docker-compose -f docker-compose.backend.yml ps
|
||||||
|
|
||||||
|
# URLs anzeigen
|
||||||
|
echo ""
|
||||||
|
log_success "🎉 Backend-Server erfolgreich gestartet!"
|
||||||
|
echo ""
|
||||||
|
echo "📡 Backend-API: http://localhost:5000"
|
||||||
|
echo "🔧 Backend-Health: http://localhost:5000/health"
|
||||||
|
echo "📋 Backend-Swagger: http://localhost:5000/swagger"
|
||||||
|
echo "🗄️ PostgreSQL: localhost:5432"
|
||||||
|
echo "⚡ Redis-Cache: localhost:6379"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Logs anzeigen (optional)
|
||||||
|
if [ "$1" = "--logs" ] || [ "$2" = "--logs" ]; then
|
||||||
|
log_info "Zeige Backend-Logs (Strg+C zum Beenden):"
|
||||||
|
docker-compose -f docker-compose.backend.yml logs -f
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_info "Verwende 'docker-compose -f docker-compose.backend.yml logs -f' um Logs zu verfolgen"
|
||||||
|
log_info "Verwende 'docker-compose -f docker-compose.backend.yml down' um den Server zu stoppen"
|
151
frontend/docker-compose.frontend.yml
Normal file
151
frontend/docker-compose.frontend.yml
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
# 🎨 MYP Frontend - Standalone Server Konfiguration
|
||||||
|
# Frontend-Service als vollständig unabhängiger Server
|
||||||
|
|
||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
# === FRONTEND SERVICE ===
|
||||||
|
frontend:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
args:
|
||||||
|
- BUILDKIT_INLINE_CACHE=1
|
||||||
|
- NODE_ENV=${NODE_ENV:-production}
|
||||||
|
image: myp/frontend:latest
|
||||||
|
container_name: myp-frontend-standalone
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=${NODE_ENV:-production}
|
||||||
|
- NEXT_TELEMETRY_DISABLED=1
|
||||||
|
|
||||||
|
# Backend API Konfiguration
|
||||||
|
- NEXT_PUBLIC_API_URL=${BACKEND_API_URL:-http://localhost:5000/api}
|
||||||
|
- NEXT_PUBLIC_BACKEND_HOST=${BACKEND_HOST:-localhost:5000}
|
||||||
|
|
||||||
|
# Frontend Server
|
||||||
|
- PORT=3000
|
||||||
|
- HOSTNAME=0.0.0.0
|
||||||
|
|
||||||
|
# Auth Konfiguration
|
||||||
|
- NEXTAUTH_URL=${FRONTEND_URL:-http://localhost:3000}
|
||||||
|
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET:-frontend-auth-secret}
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- frontend_data:/app/.next
|
||||||
|
- frontend_cache:/app/.next/cache
|
||||||
|
- ./public:/app/public:ro
|
||||||
|
|
||||||
|
ports:
|
||||||
|
- "3000:3000" # Direkter Port-Zugang für Frontend-Server
|
||||||
|
|
||||||
|
networks:
|
||||||
|
- frontend-network
|
||||||
|
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 40s
|
||||||
|
|
||||||
|
labels:
|
||||||
|
- "service.type=frontend"
|
||||||
|
- "service.name=myp-frontend"
|
||||||
|
- "service.environment=${NODE_ENV:-production}"
|
||||||
|
|
||||||
|
# === FRONTEND CACHE (Optional: Redis für Session Management) ===
|
||||||
|
frontend-cache:
|
||||||
|
image: redis:7.2-alpine
|
||||||
|
container_name: myp-frontend-cache
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
command: redis-server --appendonly yes --requirepass ${FRONTEND_REDIS_PASSWORD:-frontend_cache_password}
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- frontend_redis_data:/data
|
||||||
|
|
||||||
|
ports:
|
||||||
|
- "6380:6379" # Separater Port vom Backend-Cache
|
||||||
|
|
||||||
|
networks:
|
||||||
|
- frontend-network
|
||||||
|
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "redis-cli", "ping"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 3
|
||||||
|
|
||||||
|
# === FRONTEND CDN/NGINX (Statische Assets) ===
|
||||||
|
frontend-cdn:
|
||||||
|
image: nginx:alpine
|
||||||
|
container_name: myp-frontend-cdn
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- ./public:/usr/share/nginx/html/static:ro
|
||||||
|
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
||||||
|
- frontend_cdn_cache:/var/cache/nginx
|
||||||
|
|
||||||
|
ports:
|
||||||
|
- "8080:80" # Separater Port für statische Assets
|
||||||
|
|
||||||
|
networks:
|
||||||
|
- frontend-network
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- frontend
|
||||||
|
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://localhost/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
|
||||||
|
labels:
|
||||||
|
- "service.type=cdn"
|
||||||
|
- "service.name=myp-frontend-cdn"
|
||||||
|
|
||||||
|
# === PERSISTENTE VOLUMES ===
|
||||||
|
volumes:
|
||||||
|
frontend_data:
|
||||||
|
driver: local
|
||||||
|
|
||||||
|
frontend_cache:
|
||||||
|
driver: local
|
||||||
|
|
||||||
|
frontend_redis_data:
|
||||||
|
driver: local
|
||||||
|
|
||||||
|
frontend_cdn_cache:
|
||||||
|
driver: local
|
||||||
|
|
||||||
|
# === FRONTEND-NETZWERK ===
|
||||||
|
networks:
|
||||||
|
frontend-network:
|
||||||
|
driver: bridge
|
||||||
|
driver_opts:
|
||||||
|
com.docker.network.enable_ipv6: "false"
|
||||||
|
com.docker.network.bridge.enable_ip_masquerade: "true"
|
||||||
|
labels:
|
||||||
|
- "description=MYP Frontend Server Netzwerk"
|
||||||
|
- "project=myp-frontend"
|
||||||
|
- "tier=frontend"
|
||||||
|
|
||||||
|
# === KONFIGURATION FÜR FRONTEND ===
|
||||||
|
x-frontend-defaults: &frontend-defaults
|
||||||
|
restart: unless-stopped
|
||||||
|
logging:
|
||||||
|
driver: "json-file"
|
||||||
|
options:
|
||||||
|
max-size: "10m"
|
||||||
|
max-file: "3"
|
||||||
|
labels: "service,environment,tier"
|
||||||
|
|
||||||
|
x-healthcheck-frontend: &frontend-healthcheck
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 40s
|
64
frontend/env.frontend
Normal file
64
frontend/env.frontend
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
# 🎨 MYP Frontend - Standalone Server Konfiguration
|
||||||
|
# Umgebungsvariablen ausschließlich für den Frontend-Server
|
||||||
|
|
||||||
|
# === NODE.JS KONFIGURATION ===
|
||||||
|
NODE_ENV=production
|
||||||
|
NEXT_TELEMETRY_DISABLED=1
|
||||||
|
|
||||||
|
# === FRONTEND SERVER ===
|
||||||
|
PORT=3000
|
||||||
|
HOSTNAME=0.0.0.0
|
||||||
|
FRONTEND_URL=http://localhost:3000
|
||||||
|
|
||||||
|
# === BACKEND API KONFIGURATION ===
|
||||||
|
# Backend-Server Verbindung (HTTP)
|
||||||
|
BACKEND_API_URL=http://localhost:5000/api
|
||||||
|
BACKEND_HOST=localhost:5000
|
||||||
|
NEXT_PUBLIC_API_URL=http://localhost:5000/api
|
||||||
|
NEXT_PUBLIC_BACKEND_HOST=localhost:5000
|
||||||
|
|
||||||
|
# === AUTHENTIFIZIERUNG ===
|
||||||
|
NEXTAUTH_URL=http://localhost:3000
|
||||||
|
NEXTAUTH_SECRET=frontend-auth-secret-2024
|
||||||
|
JWT_SECRET=frontend-jwt-secret-2024
|
||||||
|
|
||||||
|
# OAuth Provider (falls verwendet)
|
||||||
|
GOOGLE_CLIENT_ID=
|
||||||
|
GOOGLE_CLIENT_SECRET=
|
||||||
|
MICROSOFT_CLIENT_ID=
|
||||||
|
MICROSOFT_CLIENT_SECRET=
|
||||||
|
|
||||||
|
# === DATABASE (Frontend-spezifisch, falls Session Store) ===
|
||||||
|
# Hinweis: Frontend sollte normalerweise KEINE direkte DB-Verbindung haben
|
||||||
|
# Diese Werte sind nur für Session-Management relevant
|
||||||
|
FRONTEND_DB_PATH=db/frontend.db
|
||||||
|
|
||||||
|
# === CACHE KONFIGURATION ===
|
||||||
|
# Frontend-spezifischer Redis Cache (separater Port!)
|
||||||
|
FRONTEND_REDIS_PASSWORD=frontend_cache_password
|
||||||
|
FRONTEND_REDIS_HOST=localhost
|
||||||
|
FRONTEND_REDIS_PORT=6380
|
||||||
|
FRONTEND_REDIS_DB=1
|
||||||
|
|
||||||
|
# === CDN KONFIGURATION ===
|
||||||
|
CDN_URL=http://localhost:8080
|
||||||
|
ASSETS_URL=http://localhost:8080/static
|
||||||
|
|
||||||
|
# === SICHERHEIT ===
|
||||||
|
# CSP (Content Security Policy)
|
||||||
|
CSP_SCRIPT_SRC="'self' 'unsafe-inline' 'unsafe-eval'"
|
||||||
|
CSP_STYLE_SRC="'self' 'unsafe-inline'"
|
||||||
|
CSP_IMG_SRC="'self' data: https:"
|
||||||
|
CSP_CONNECT_SRC="'self' ws: wss: http://localhost:5000"
|
||||||
|
|
||||||
|
# === MONITORING ===
|
||||||
|
ANALYTICS_ENABLED=true
|
||||||
|
ERROR_REPORTING_ENABLED=true
|
||||||
|
|
||||||
|
# === ENTWICKLUNG ===
|
||||||
|
DEBUG=false
|
||||||
|
NEXT_DEBUG=false
|
||||||
|
|
||||||
|
# === BUILD KONFIGURATION ===
|
||||||
|
ANALYZE=false
|
||||||
|
BUNDLE_ANALYZER=false
|
162
frontend/start-frontend-server.sh
Normal file
162
frontend/start-frontend-server.sh
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 🎨 MYP Frontend - Standalone Server Start
|
||||||
|
# Startet den Frontend-Server vollständig unabhängig vom Backend
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🎨 MYP Frontend - Standalone Server wird gestartet..."
|
||||||
|
|
||||||
|
# Farben für Terminal-Ausgabe
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Funktionen
|
||||||
|
log_info() {
|
||||||
|
echo -e "${BLUE}[INFO]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
log_success() {
|
||||||
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
log_warning() {
|
||||||
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
log_error() {
|
||||||
|
echo -e "${RED}[ERROR]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Arbeitsverzeichnis setzen
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
cd "$SCRIPT_DIR"
|
||||||
|
|
||||||
|
log_info "Arbeitsverzeichnis: $SCRIPT_DIR"
|
||||||
|
|
||||||
|
# Umgebungsvariablen laden
|
||||||
|
if [ -f ".env.frontend" ]; then
|
||||||
|
log_info "Lade Frontend-Umgebungsvariablen..."
|
||||||
|
export $(cat .env.frontend | grep -v '^#' | xargs)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Prüfe Docker-Installation
|
||||||
|
if ! command -v docker &> /dev/null; then
|
||||||
|
log_error "Docker ist nicht installiert!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v docker-compose &> /dev/null; then
|
||||||
|
log_error "Docker Compose ist nicht installiert!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_success "Docker-Installation verifiziert"
|
||||||
|
|
||||||
|
# Backend-Verfügbarkeit prüfen
|
||||||
|
BACKEND_URL=${BACKEND_API_URL:-http://localhost:5000}
|
||||||
|
log_info "Prüfe Backend-Verfügbarkeit: $BACKEND_URL"
|
||||||
|
|
||||||
|
if ! curl -f "$BACKEND_URL/health" >/dev/null 2>&1; then
|
||||||
|
log_warning "Backend-Server ist nicht verfügbar!"
|
||||||
|
log_warning "Stellen Sie sicher, dass der Backend-Server läuft:"
|
||||||
|
log_warning "cd ../backend && ./start-backend-server.sh"
|
||||||
|
|
||||||
|
read -p "Möchten Sie trotzdem fortfahren? [y/N]: " -n 1 -r
|
||||||
|
echo
|
||||||
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
log_info "Abgebrochen."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Alte Container stoppen und entfernen
|
||||||
|
log_info "Stoppe eventuell laufende Frontend-Container..."
|
||||||
|
docker-compose -f docker-compose.frontend.yml down --remove-orphans 2>/dev/null || true
|
||||||
|
|
||||||
|
# Images aufräumen (optional)
|
||||||
|
if [ "$1" = "--clean" ]; then
|
||||||
|
log_info "Räume alte Frontend-Images auf..."
|
||||||
|
docker-compose -f docker-compose.frontend.yml down --rmi all --volumes 2>/dev/null || true
|
||||||
|
docker system prune -f
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Notwendige Verzeichnisse erstellen
|
||||||
|
log_info "Erstelle notwendige Verzeichnisse..."
|
||||||
|
mkdir -p .next public/uploads
|
||||||
|
|
||||||
|
# Node.js Dependencies prüfen
|
||||||
|
if [ ! -d "node_modules" ] || [ ! -f "package-lock.json" ]; then
|
||||||
|
log_info "Installiere Node.js Dependencies..."
|
||||||
|
if command -v pnpm &> /dev/null; then
|
||||||
|
pnpm install
|
||||||
|
elif command -v npm &> /dev/null; then
|
||||||
|
npm install
|
||||||
|
else
|
||||||
|
log_warning "Weder pnpm noch npm gefunden. Dependencies werden im Container installiert."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Frontend-Container builden und starten
|
||||||
|
log_info "Frontend-Container werden gebaut und gestartet..."
|
||||||
|
docker-compose -f docker-compose.frontend.yml up --build -d
|
||||||
|
|
||||||
|
# Warten auf Frontend-Start
|
||||||
|
log_info "Warte auf Frontend-Service..."
|
||||||
|
timeout=120
|
||||||
|
counter=0
|
||||||
|
|
||||||
|
while [ $counter -lt $timeout ]; do
|
||||||
|
if curl -f http://localhost:3000/health >/dev/null 2>&1; then
|
||||||
|
log_success "Frontend-Server ist bereit!"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Fallback: Prüfe, ob der Container läuft
|
||||||
|
if [ $counter -gt 30 ] && curl -f http://localhost:3000 >/dev/null 2>&1; then
|
||||||
|
log_success "Frontend-Server ist bereit!"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $((counter % 10)) -eq 0 ]; then
|
||||||
|
log_info "Warte auf Frontend-Service... ($counter/$timeout Sekunden)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
counter=$((counter + 1))
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $counter -eq $timeout ]; then
|
||||||
|
log_error "Frontend-Service konnte nicht gestartet werden!"
|
||||||
|
log_info "Zeige Frontend-Logs:"
|
||||||
|
docker-compose -f docker-compose.frontend.yml logs frontend
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Service-Status anzeigen
|
||||||
|
log_info "Frontend-Service Status:"
|
||||||
|
docker-compose -f docker-compose.frontend.yml ps
|
||||||
|
|
||||||
|
# URLs anzeigen
|
||||||
|
echo ""
|
||||||
|
log_success "🎉 Frontend-Server erfolgreich gestartet!"
|
||||||
|
echo ""
|
||||||
|
echo "🌐 Frontend-App: http://localhost:3000"
|
||||||
|
echo "🔧 Frontend-Health: http://localhost:3000/health"
|
||||||
|
echo "📦 CDN-Assets: http://localhost:8080"
|
||||||
|
echo "⚡ Frontend-Cache: localhost:6380"
|
||||||
|
echo ""
|
||||||
|
echo "🔗 Verbindet sich mit Backend: ${BACKEND_API_URL:-http://localhost:5000}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Logs anzeigen (optional)
|
||||||
|
if [ "$1" = "--logs" ] || [ "$2" = "--logs" ]; then
|
||||||
|
log_info "Zeige Frontend-Logs (Strg+C zum Beenden):"
|
||||||
|
docker-compose -f docker-compose.frontend.yml logs -f
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_info "Verwende 'docker-compose -f docker-compose.frontend.yml logs -f' um Logs zu verfolgen"
|
||||||
|
log_info "Verwende 'docker-compose -f docker-compose.frontend.yml down' um den Server zu stoppen"
|
Loading…
x
Reference in New Issue
Block a user