"feat: Add SSL configuration and docker-compose updates for frontend"

This commit is contained in:
Till Tomczak 2025-05-26 07:21:47 +02:00
parent 3b53e78799
commit 0e40ad1c12
6 changed files with 305 additions and 9 deletions

1
SSL_KONFIGURATION.md Normal file
View File

@ -0,0 +1 @@

95
docker-compose.yml Normal file
View File

@ -0,0 +1,95 @@
version: '3'
services:
# Backend (Flask) auf Port 443 mit SSL
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: myp-backend
restart: unless-stopped
hostname: raaspberry
ports:
- "80:80" # HTTP Fallback
- "443:443" # HTTPS
volumes:
- ./backend:/app
- ./backend/logs:/app/logs
- ./backend/instance:/app/instance
- backend_ssl:/opt/myp/ssl
networks:
- myp-network
environment:
- FLASK_APP=app/app.py
- FLASK_ENV=production
- SSL_ENABLED=true
- SSL_HOSTNAME=raaspberry
healthcheck:
test: ["CMD", "curl", "-k", "https://localhost:443/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# Next.js Frontend
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
container_name: myp-rp
restart: unless-stopped
environment:
- NODE_ENV=production
- NEXT_PUBLIC_API_URL=https://raaspberry:443
- NEXT_PUBLIC_BACKEND_HOST=raaspberry:443
volumes:
- ./frontend:/app
- /app/node_modules
- /app/.next
ports:
- "3000:3000"
networks:
- myp-network
healthcheck:
test: ["CMD", "wget", "--spider", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# Caddy Proxy für Frontend auf Port 443 mit SSL
caddy:
image: caddy:2.7-alpine
container_name: myp-caddy
restart: unless-stopped
hostname: m040tbaraspi001
ports:
- "80:80"
- "443:443"
volumes:
- ./frontend/docker/caddy/Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config
networks:
- myp-network
extra_hosts:
- "host.docker.internal:host-gateway"
- "raaspberry:backend"
- "m040tbaraspi001.de040.corpintra.net:127.0.0.1"
environment:
- CADDY_HOST=m040tbaraspi001.de040.corpintra.net
- CADDY_DOMAIN=m040tbaraspi001.de040.corpintra.net
cap_add:
- NET_ADMIN
depends_on:
- backend
- frontend
networks:
myp-network:
driver: bridge
volumes:
caddy_data:
caddy_config:
backend_ssl:

View File

@ -45,10 +45,11 @@ services:
- myp-network - myp-network
extra_hosts: extra_hosts:
- "host.docker.internal:host-gateway" - "host.docker.internal:host-gateway"
- "raspberrypi:192.168.0.105" - "raaspberry:192.168.0.105"
- "m040tbaraspi001.de040.corpintra.net:127.0.0.1"
environment: environment:
- CADDY_HOST=localhost - CADDY_HOST=m040tbaraspi001.de040.corpintra.net
- CADDY_DOMAIN=localhost - CADDY_DOMAIN=m040tbaraspi001.de040.corpintra.net
cap_add: cap_add:
- NET_ADMIN - NET_ADMIN

View File

@ -1,16 +1,26 @@
{ {
debug debug
auto_https disable_redirects
} }
# Entwicklungsumgebung - Localhost und Raspberry Pi Backend # Produktionsumgebung - Spezifischer Hostname für Mercedes-Benz Werk 040 Berlin
localhost, 127.0.0.1 { m040tbaraspi001.de040.corpintra.net {
# API Anfragen zum Raspberry Pi Backend weiterleiten # TLS mit selbstsignierten Zertifikaten für die Produktionsumgebung
tls internal {
protocols tls1.2 tls1.3
}
# API Anfragen zum Backend (Raspberry Pi) weiterleiten
@api { @api {
path /api/* /health path /api/* /health
} }
handle @api { handle @api {
uri strip_prefix /api uri strip_prefix /api
reverse_proxy 192.168.0.105:5000 { reverse_proxy raaspberry:443 {
transport http {
tls
tls_insecure_skip_verify
}
header_up Host {upstream_hostport} header_up Host {upstream_hostport}
header_up X-Real-IP {remote_host} header_up X-Real-IP {remote_host}
header_up X-Forwarded-For {remote_host} header_up X-Forwarded-For {remote_host}
@ -28,8 +38,54 @@ localhost, 127.0.0.1 {
} }
} }
# TLS für Entwicklung deaktiviert # OAuth Callbacks
tls off @oauth path /auth/login/callback*
handle @oauth {
header Cache-Control "no-cache"
reverse_proxy myp-rp-dev:3000
}
# Produktions-Header
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
X-Content-Type-Options "nosniff"
X-Frame-Options "SAMEORIGIN"
Referrer-Policy "strict-origin-when-cross-origin"
}
}
# Entwicklungsumgebung - Localhost und Raspberry Pi Backend (weiterhin für lokale Entwicklung verfügbar)
localhost, 127.0.0.1 {
# API Anfragen zum Raspberry Pi Backend weiterleiten
@api {
path /api/* /health
}
handle @api {
uri strip_prefix /api
reverse_proxy raaspberry:443 {
transport http {
tls
tls_insecure_skip_verify
}
header_up Host {upstream_hostport}
header_up X-Real-IP {remote_host}
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
}
}
# Alle anderen Anfragen zum Frontend weiterleiten
handle {
reverse_proxy myp-rp-dev:3000 {
header_up Host {upstream_hostport}
header_up X-Real-IP {remote_host}
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
}
}
# TLS für lokale Entwicklung
tls internal
# OAuth Callbacks für Entwicklung # OAuth Callbacks für Entwicklung
@oauth path /auth/login/callback* @oauth path /auth/login/callback*

73
setup_hosts.ps1 Normal file
View File

@ -0,0 +1,73 @@
# MYP - Einrichtung der Hostnamen für die SSL-Konfiguration (Windows PowerShell Version)
# Überprüfen, ob das Skript als Administrator ausgeführt wird
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Host "Dieses Skript muss mit Administrator-Rechten ausgeführt werden." -ForegroundColor Red
Write-Host "Bitte starten Sie PowerShell als Administrator und führen Sie das Skript erneut aus." -ForegroundColor Yellow
Exit 1
}
# Header anzeigen
Write-Host "=================================================" -ForegroundColor Blue
Write-Host " MYP - Hostnamen-Konfiguration für SSL" -ForegroundColor Blue
Write-Host "=================================================" -ForegroundColor Blue
Write-Host ""
# Lokale IP-Adresse ermitteln
$localIP = (Get-NetIPAddress | Where-Object { $_.AddressFamily -eq "IPv4" -and $_.PrefixOrigin -ne "WellKnown" } | Select-Object -First 1).IPAddress
if (-not $localIP) {
$localIP = "127.0.0.1"
Write-Host "Konnte lokale IP-Adresse nicht ermitteln, verwende $localIP" -ForegroundColor Yellow
} else {
Write-Host "Lokale IP-Adresse: $localIP" -ForegroundColor Green
}
# Pfad zur Hosts-Datei
$hostsFile = "$env:windir\System32\drivers\etc\hosts"
Write-Host "Hosts-Datei: $hostsFile" -ForegroundColor Cyan
# Prüfen, ob die Einträge bereits existieren
$frontendEntry = Select-String -Path $hostsFile -Pattern "m040tbaraspi001.de040.corpintra.net" -Quiet
$backendEntry = Select-String -Path $hostsFile -Pattern "raaspberry" -Quiet
# Einträge in die Hosts-Datei schreiben
Write-Host "Aktualisiere Hosts-Datei..." -ForegroundColor Blue
$hostsContent = Get-Content -Path $hostsFile
if (-not $frontendEntry) {
$hostsContent += ""
$hostsContent += "# MYP Frontend Host"
$hostsContent += "$localIP m040tbaraspi001.de040.corpintra.net m040tbaraspi001"
Write-Host "Frontend-Hostname hinzugefügt" -ForegroundColor Green
} else {
Write-Host "Frontend-Hostname ist bereits konfiguriert" -ForegroundColor Yellow
}
if (-not $backendEntry) {
$hostsContent += ""
$hostsContent += "# MYP Backend Host"
$hostsContent += "$localIP raaspberry"
Write-Host "Backend-Hostname hinzugefügt" -ForegroundColor Green
} else {
Write-Host "Backend-Hostname ist bereits konfiguriert" -ForegroundColor Yellow
}
# Speichern der aktualisierten Hosts-Datei
try {
$hostsContent | Set-Content -Path $hostsFile -Force
Write-Host ""
Write-Host "Konfiguration abgeschlossen!" -ForegroundColor Green
} catch {
Write-Host "Fehler beim Schreiben der Hosts-Datei: $_" -ForegroundColor Red
Exit 1
}
Write-Host "Folgende Hostnamen sind jetzt konfiguriert:" -ForegroundColor Blue
Write-Host " - Frontend: m040tbaraspi001.de040.corpintra.net" -ForegroundColor Yellow
Write-Host " - Backend: raaspberry" -ForegroundColor Yellow
Write-Host ""
Write-Host "Sie können nun die Anwendung mit folgendem Befehl starten:" -ForegroundColor Blue
Write-Host "docker-compose up -d" -ForegroundColor Yellow
Write-Host ""

70
setup_hosts.sh Normal file
View File

@ -0,0 +1,70 @@
#!/bin/bash
# MYP - Einrichtung der Hostnamen für die SSL-Konfiguration
# Farben für bessere Lesbarkeit
RESET='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
echo -e "${BLUE}=================================================${RESET}"
echo -e "${BLUE} MYP - Hostnamen-Konfiguration für SSL${RESET}"
echo -e "${BLUE}=================================================${RESET}"
echo ""
# Überprüfen, ob das Skript mit Admin-Rechten ausgeführt wird
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}Dieses Skript muss mit Administrator-Rechten ausgeführt werden.${RESET}"
echo -e "${YELLOW}Bitte führen Sie es erneut mit 'sudo' aus.${RESET}"
exit 1
fi
# Lokale IP-Adresse ermitteln
LOCAL_IP=$(hostname -I | awk '{print $1}')
if [ -z "$LOCAL_IP" ]; then
LOCAL_IP="127.0.0.1"
echo -e "${YELLOW}Konnte lokale IP-Adresse nicht ermitteln, verwende ${LOCAL_IP}${RESET}"
else
echo -e "${GREEN}Lokale IP-Adresse: ${LOCAL_IP}${RESET}"
fi
# Hosts-Datei Pfad je nach Betriebssystem
HOSTS_FILE="/etc/hosts"
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
HOSTS_FILE="/c/Windows/System32/drivers/etc/hosts"
echo -e "${YELLOW}Windows-System erkannt, verwende ${HOSTS_FILE}${RESET}"
fi
# Prüfen, ob die Einträge bereits existieren
FRONTEND_ENTRY=$(grep -c "m040tbaraspi001.de040.corpintra.net" ${HOSTS_FILE})
BACKEND_ENTRY=$(grep -c "raaspberry" ${HOSTS_FILE})
# Einträge in die Hosts-Datei schreiben
echo -e "${BLUE}Aktualisiere Hosts-Datei...${RESET}"
if [ $FRONTEND_ENTRY -eq 0 ]; then
echo -e "\n# MYP Frontend Host" >> ${HOSTS_FILE}
echo "${LOCAL_IP} m040tbaraspi001.de040.corpintra.net m040tbaraspi001" >> ${HOSTS_FILE}
echo -e "${GREEN}Frontend-Hostname hinzugefügt${RESET}"
else
echo -e "${YELLOW}Frontend-Hostname ist bereits konfiguriert${RESET}"
fi
if [ $BACKEND_ENTRY -eq 0 ]; then
echo -e "\n# MYP Backend Host" >> ${HOSTS_FILE}
echo "${LOCAL_IP} raaspberry" >> ${HOSTS_FILE}
echo -e "${GREEN}Backend-Hostname hinzugefügt${RESET}"
else
echo -e "${YELLOW}Backend-Hostname ist bereits konfiguriert${RESET}"
fi
echo ""
echo -e "${GREEN}Konfiguration abgeschlossen!${RESET}"
echo -e "${BLUE}Folgende Hostnamen sind jetzt konfiguriert:${RESET}"
echo -e " - Frontend: ${YELLOW}m040tbaraspi001.de040.corpintra.net${RESET}"
echo -e " - Backend: ${YELLOW}raaspberry${RESET}"
echo ""
echo -e "${BLUE}Sie können nun die Anwendung mit folgendem Befehl starten:${RESET}"
echo -e "${YELLOW}docker-compose up -d${RESET}"
echo ""