miniITCS/docs/DEPLOYMENT.md

6.0 KiB

Deployment Guide

Deployment-Optionen

1. Docker Deployment (Empfohlen)

Standard (SQLite)

# .env konfigurieren
cp .env.example .env
nano .env  # JWT_SECRET ändern

# Container starten
docker-compose up -d

# Logs anzeigen
docker-compose logs -f

# Status prüfen
docker-compose ps

Mit MariaDB

# .env konfigurieren
cp .env.example .env
nano .env  # Passwörter ändern

# Container mit MariaDB starten
docker-compose -f docker-compose.yml -f docker-compose.mariadb.yml up -d

2. Embedded Linux System (z.B. Raspberry Pi)

Voraussetzungen

  • Linux ARM/ARM64 System
  • Docker oder natives Go Runtime

Mit Docker

# Multi-arch Image bauen
docker buildx build --platform linux/arm64 -f docker/Dockerfile.backend -t admintemplate-backend .
docker buildx build --platform linux/arm64 -f docker/Dockerfile.frontend -t admintemplate-frontend .

# Starten
docker-compose up -d

Native Installation

# Backend kompilieren (auf Entwicklungsrechner)
cd backend
GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go build -o server cmd/server/main.go

# Auf Embedded System kopieren
scp server pi@raspberry:/opt/admintemplate/
scp -r frontend/dist/* pi@raspberry:/opt/admintemplate/frontend/

# Auf Embedded System
./server

3. Systemd Service (Linux)

Erstellen Sie /etc/systemd/system/admintemplate.service:

[Unit]
Description=AdminTemplate Backend
After=network.target

[Service]
Type=simple
User=admintemplate
WorkingDirectory=/opt/admintemplate
Environment="SERVER_PORT=8080"
Environment="DB_TYPE=sqlite"
Environment="SQLITE_PATH=/var/lib/admintemplate/db.sqlite"
Environment="JWT_SECRET=your-production-secret"
ExecStart=/opt/admintemplate/server
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
# Service aktivieren
sudo systemctl daemon-reload
sudo systemctl enable admintemplate
sudo systemctl start admintemplate

# Status prüfen
sudo systemctl status admintemplate

4. Reverse Proxy (Nginx/Traefik)

Nginx Konfiguration

server {
    listen 80;
    server_name example.com;

    # HTTPS Redirect (optional)
    # return 301 https://$server_name$request_uri;

    location / {
        proxy_pass http://localhost:80;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Mit SSL/TLS (Let's Encrypt)

# Certbot installieren
sudo apt install certbot python3-certbot-nginx

# Zertifikat erstellen
sudo certbot --nginx -d example.com

Produktions-Checkliste

Sicherheit

  • JWT_SECRET auf sicheren Zufallswert setzen
  • Standard-Benutzerpasswörter ändern
  • HTTPS aktivieren
  • Firewall konfigurieren (nur Port 80/443 öffnen)
  • Regelmäßige Updates planen

Datenbank

  • Backup-Strategie implementieren
  • Für SQLite: Regelmäßige Datenbank-Kopien
  • Für MariaDB: Automatische Backups einrichten
# SQLite Backup
sqlite3 /app/data/admintemplate.db ".backup /backups/db-$(date +%Y%m%d).sqlite"

# MariaDB Backup
docker exec admintemplate-mariadb mysqldump -u root -p admintemplate > backup-$(date +%Y%m%d).sql

Monitoring

  • Logs konfigurieren
  • Health-Check-Endpunkte überwachen
  • Ressourcenverbrauch überwachen
# Docker Logs
docker-compose logs -f --tail=100

# Health Check
curl http://localhost:8080/health

Performance

  • Frontend-Assets komprimieren (Gzip/Brotli)
  • Datenbankindizes optimieren
  • Caching aktivieren (Redis/Memory)
  • CDN für statische Assets (optional)

Umgebungsspezifische Konfigurationen

Windows Server

# Docker Desktop installieren
# WSL2 Backend aktivieren

# Container starten
docker-compose up -d

Linux Server

# Docker installieren
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

# Docker Compose installieren
sudo apt install docker-compose

# Container starten
docker-compose up -d

Embedded Linux (Yocto/BuildRoot)

  1. SQLite in Image integrieren
  2. Go Runtime oder statisches Binary verwenden
  3. Minimale Docker Installation oder natives Binary
# Statisches Binary bauen
CGO_ENABLED=1 go build -ldflags="-s -w" -a -installsuffix cgo -o server cmd/server/main.go

# Binary komprimieren (optional)
upx --best --lzma server

Skalierung

Horizontal Scaling

# docker-compose.scale.yml
services:
  backend:
    deploy:
      replicas: 3

  nginx:
    # Load Balancer Konfiguration

Datenbank-Skalierung

  • SQLite: Für kleine bis mittlere Anwendungen
  • MariaDB: Master-Slave Replikation für höhere Last

Troubleshooting

Container starten nicht

# Logs prüfen
docker-compose logs

# Container neu bauen
docker-compose down
docker-compose build --no-cache
docker-compose up -d

Datenbank-Verbindungsfehler

# Backend-Container Logs
docker-compose logs backend

# Datenbank-Container prüfen
docker-compose exec mariadb mysql -u root -p

Frontend zeigt Fehler

# Nginx-Konfiguration prüfen
docker-compose exec frontend nginx -t

# Nginx neu laden
docker-compose restart frontend

Migration zwischen Datenbanken

SQLite zu MariaDB

# 1. Daten aus SQLite exportieren
sqlite3 admintemplate.db .dump > dump.sql

# 2. MariaDB Container starten
docker-compose -f docker-compose.yml -f docker-compose.mariadb.yml up -d mariadb

# 3. Daten importieren (anpassen für MariaDB Syntax)
docker exec -i admintemplate-mariadb mysql -u root -p admintemplate < dump_converted.sql

# 4. Backend auf MariaDB umstellen
# DB_TYPE=mysql in .env setzen

Backup & Restore

Backup

# SQLite
docker cp admintemplate-backend:/app/data/admintemplate.db ./backup/

# MariaDB
docker exec admintemplate-mariadb mysqldump -u root -p admintemplate > backup.sql

Restore

# SQLite
docker cp ./backup/admintemplate.db admintemplate-backend:/app/data/

# MariaDB
docker exec -i admintemplate-mariadb mysql -u root -p admintemplate < backup.sql