setup für remote development

This commit is contained in:
rxf
2025-09-22 17:04:25 +02:00
parent a255543da6
commit b52a9abc02
2 changed files with 563 additions and 0 deletions

287
REMOTE_DEVELOPMENT.md Normal file
View File

@@ -0,0 +1,287 @@
# Remote Development Setup - Mac → Linux Server
## 🔄 Entwicklungsworkflow: Mac Entwicklung → Linux Testing
Optimaler Workflow für Entwicklung auf Mac mit Testing auf Linux-Server, der der späteren Produktionsumgebung entspricht.
## 🚀 Quick Start
### **Auf dem Linux-Server (via SSH):**
```bash
# 1. Repository klonen (falls nicht geschehen)
git clone https://github.com/your-repo/rezepte-klaus.git
cd rezepte-klaus
# 2. Development-Umgebung einrichten
./setup-development.sh
# 3. Entwicklungsumgebung starten
./start-development.sh
```
### **Von deinem Mac aus zugreifen:**
```bash
# Option 1: Direkter Zugriff (wenn Server öffentlich)
http://SERVER_IP:3000
# Option 2: SSH-Tunnel (sicherer)
ssh -L 3000:localhost:3000 -L 3001:localhost:3001 -L 8080:localhost:8080 user@server
# Dann: http://localhost:3000
```
## 🏗️ Architektur-Übersicht
### **Development-Pipeline:**
```
┌─────────────┐ ┌─────────────────┐ ┌──────────────────┐
│ Mac │ │ Linux Server │ │ Production │
│ │ │ (Development) │ │ │
│ VS Code │───▶│ Docker Compose │───▶│ Traefik + SSL │
│ Git │ │ Direct Ports │ │ Registry Images │
│ Testing │ │ Hot Reload │ │ External MySQL │
└─────────────┘ └─────────────────┘ └──────────────────┘
Local Dev Linux Testing Production Deploy
```
## 🛠️ Development-Umgebung Features
### **Was wird automatisch eingerichtet:**
-**Linux-spezifische Konfiguration** (IP-Erkennung, Netzwerk)
-**Development Docker Compose** (direkte Ports, Hot Reload)
-**Eigene MySQL-Instanz** (unabhängig von Production)
-**CORS für Remote-Zugriff** konfiguriert
-**phpMyAdmin** für Datenbank-Management
### **Port-Mapping (alle Interfaces 0.0.0.0):**
- **Frontend**: `3000:80`
- **Backend**: `3001:3001`
- **phpMyAdmin**: `8080:80`
- **MySQL**: `3307:3306`
## 🔧 Entwicklungsworkflows
### **1. Code-Sync-Strategien:**
#### **A) Git-basiert (empfohlen):**
```bash
# Auf Mac: Code ändern und committen
git add .
git commit -m "Feature XYZ"
git push
# Auf Server: Pullen und neu builden
git pull
docker-compose -f docker-compose.development.yml build frontend
docker-compose -f docker-compose.development.yml restart frontend
```
#### **B) VS Code Remote-SSH:**
```bash
# VS Code Extension installieren: "Remote - SSH"
# Direkt auf Server entwickeln
code --remote ssh-remote+user@server /path/to/rezepte-klaus
```
#### **C) rsync-Sync:**
```bash
# Automatischer Sync von Mac zu Server
rsync -avz --exclude 'node_modules' ./ user@server:/path/to/rezepte-klaus/
```
### **2. Container-Rebuild-Workflows:**
#### **Frontend-Änderungen:**
```bash
# Auf Server
docker-compose -f docker-compose.development.yml build frontend
docker-compose -f docker-compose.development.yml restart frontend
```
#### **Backend-Änderungen:**
```bash
# Auf Server
docker-compose -f docker-compose.development.yml build backend
docker-compose -f docker-compose.development.yml restart backend
```
#### **Full Rebuild:**
```bash
# Auf Server
docker-compose -f docker-compose.development.yml down
docker-compose -f docker-compose.development.yml up -d --build
```
## 🔒 Sichere Zugriffsmethoden
### **1. SSH-Tunnel (empfohlen für öffentliche Server):**
```bash
# Alle Development-Ports tunneln
ssh -L 3000:localhost:3000 \
-L 3001:localhost:3001 \
-L 8080:localhost:8080 \
-L 3307:localhost:3307 \
user@your-server.com
# Dann lokal zugreifen:
# Frontend: http://localhost:3000
# API: http://localhost:3001/api
# phpMyAdmin: http://localhost:8080
```
### **2. VPN-Zugriff:**
```bash
# Wenn Server im VPN/privaten Netzwerk
http://PRIVATE_SERVER_IP:3000
```
### **3. Firewall-Konfiguration:**
```bash
# Auf Server: Ports nur für Development freigeben
sudo ufw allow from YOUR_MAC_IP to any port 3000
sudo ufw allow from YOUR_MAC_IP to any port 3001
sudo ufw allow from YOUR_MAC_IP to any port 8080
```
## 🔄 Kontinuierliche Integration
### **Development → Testing → Production Pipeline:**
#### **1. Development (Linux Server):**
```bash
# Feature entwickeln und testen
./start-development.sh
# Test: http://server:3000
```
#### **2. Registry-Build (für Staging):**
```bash
# Images für Registry builden
./build-and-push.sh
```
#### **3. Production-Deployment:**
```bash
# Mit fertigen Registry-Images
./deploy-external-db.sh # Oder ./deploy-traefik.sh
```
## 📊 Monitoring & Debugging
### **Live-Logs verfolgen:**
```bash
# Alle Services
docker-compose -f docker-compose.development.yml logs -f
# Nur Backend
docker-compose -f docker-compose.development.yml logs -f backend
# Nur Frontend
docker-compose -f docker-compose.development.yml logs -f frontend
```
### **Container-Status prüfen:**
```bash
docker-compose -f docker-compose.development.yml ps
docker-compose -f docker-compose.development.yml top
```
### **Performance-Monitoring:**
```bash
# Resource-Verbrauch
docker stats
# Container-Details
docker inspect rezepte-backend-dev
```
## 🛠️ Troubleshooting
### **Container starten nicht:**
```bash
# Logs prüfen
docker-compose -f docker-compose.development.yml logs
# Clean restart
docker-compose -f docker-compose.development.yml down -v
docker-compose -f docker-compose.development.yml up -d --build
```
### **Netzwerk-Verbindung fehlschlägt:**
```bash
# Server-IP prüfen
ip addr show
hostname -I
# Firewall-Status
sudo ufw status
# Port-Binding prüfen
netstat -tlnp | grep :3000
```
### **MySQL-Verbindung fehlschlägt:**
```bash
# MySQL-Logs
docker-compose -f docker-compose.development.yml logs mysql
# Direkter MySQL-Zugriff
docker exec -it rezepte-mysql-dev mysql -uroot -p
```
## 💡 Pro-Tips
### **1. Auto-Rebuild bei Änderungen:**
```bash
# File-Watcher für automatischen Rebuild
sudo apt install inotify-tools
# Watch-Script erstellen
#!/bin/bash
inotifywait -m -r --format '%w %e %f' -e modify ./nodejs-version/ | while read dir event file; do
echo "File changed: $dir$file"
if [[ "$dir" == *"frontend"* ]]; then
docker-compose -f docker-compose.development.yml build frontend
docker-compose -f docker-compose.development.yml restart frontend
elif [[ "$dir" == *"backend"* ]]; then
docker-compose -f docker-compose.development.yml build backend
docker-compose -f docker-compose.development.yml restart backend
fi
done
```
### **2. Development-Database Reset:**
```bash
# Datenbank zurücksetzen
docker-compose -f docker-compose.development.yml down -v
docker-compose -f docker-compose.development.yml up -d
```
### **3. Resource-Limits für Development:**
```yaml
# In docker-compose.development.yml
services:
backend:
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 256M
```
## 🎯 Zusammenfassung
### **Vorteile dieses Setups:**
-**Linux-Kompatibilität** testen vor Production
-**Isolierte Development-DB** (keine Konflikte)
-**Flexible Zugriffsmethoden** (direkt/SSH-Tunnel)
-**Hot Reload** für schnelle Entwicklung
-**Production-ähnliche Umgebung**
### **Workflow-Empfehlung:**
1. **Lokal entwickeln** (Mac mit VS Code)
2. **Code synchronisieren** (Git/rsync/Remote-SSH)
3. **Auf Linux testen** (Docker Development)
4. **Registry deployen** (Staging/Production)
**🚀 Perfect für professionelle Cross-Platform-Entwicklung!**

276
setup-development.sh Executable file
View File

@@ -0,0 +1,276 @@
#!/bin/bash
set -e
echo "🐧 Setting up Rezepte Klaus for Remote Development on Linux"
echo "=========================================================="
# Check if we're on a Linux system
if [[ "$OSTYPE" != "linux-gnu"* ]]; then
echo "⚠️ Warning: This script is optimized for Linux servers"
fi
# Check if Docker is installed
if ! command -v docker &> /dev/null; then
echo "❌ Docker is not installed. Please install Docker first:"
echo " curl -fsSL https://get.docker.com -o get-docker.sh"
echo " sudo sh get-docker.sh"
exit 1
fi
# Check if Docker Compose is installed
if ! command -v docker-compose &> /dev/null; then
echo "❌ Docker Compose is not installed. Please install Docker Compose first:"
echo " sudo curl -L \"https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-\$(uname -s)-\$(uname -m)\" -o /usr/local/bin/docker-compose"
echo " sudo chmod +x /usr/local/bin/docker-compose"
exit 1
fi
# Detect Linux distribution for IP detection
if command -v ip &> /dev/null; then
HOST_IP=$(ip route get 1.1.1.1 | grep -oP 'src \K\S+' 2>/dev/null || echo "")
elif command -v hostname &> /dev/null; then
HOST_IP=$(hostname -I | awk '{print $1}' 2>/dev/null || echo "")
else
echo "⚠️ Could not detect IP automatically. Please check manually:"
echo " ip addr show"
HOST_IP="YOUR_SERVER_IP"
fi
if [ -z "$HOST_IP" ] || [ "$HOST_IP" = "YOUR_SERVER_IP" ]; then
echo "❌ Could not detect server IP. Please find your server IP:"
echo " ip addr show | grep 'inet '"
echo " hostname -I"
exit 1
fi
echo "🔍 Detected Server IP: $HOST_IP"
# Create development environment file
echo "📝 Creating development environment configuration..."
cat > .env.development << EOF
# Development Environment - Linux Server
# Generated on $(date)
# Server Configuration
HOST_IP=$HOST_IP
DEVELOPMENT_MODE=true
# Database Configuration (local development DB)
MYSQL_PASSWORD=dev_password_123
MYSQL_ROOT_PASSWORD=dev_root_password_123
# CORS Configuration for remote access
CORS_ORIGIN=*
# Development URLs:
# - Frontend: http://$HOST_IP:3000
# - Backend API: http://$HOST_IP:3001/api
# - phpMyAdmin: http://$HOST_IP:8080
# - MySQL: $HOST_IP:3307
# Registry Configuration (for image pulls)
DOCKER_REGISTRY=docker.citysensor.de
# DOCKER_USERNAME=your_username
# DOCKER_PASSWORD=your_password
# Development Notes:
# - Use this for testing Linux-specific behavior
# - Access from Mac via: http://$HOST_IP:3000
# - SSH tunnel for secure access: ssh -L 3000:$HOST_IP:3000 user@server
EOF
echo "✅ Created .env.development with server IP: $HOST_IP"
# Create development-specific docker-compose
echo "📝 Creating development docker-compose configuration..."
cat > docker-compose.development.yml << 'EOF'
services:
mysql:
image: mysql:8.0
container_name: rezepte-mysql-dev
restart: unless-stopped
environment:
- MYSQL_DATABASE=rezepte_klaus
- MYSQL_USER=rezepte
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
ports:
- "0.0.0.0:3307:3306"
volumes:
- mysql_dev_data:/var/lib/mysql
# Initialize with data
- ./Rezepte.sql:/docker-entrypoint-initdb.d/01-Rezepte.sql
- ./ingredients.sql:/docker-entrypoint-initdb.d/02-ingredients.sql
- ./Zubereitung.sql:/docker-entrypoint-initdb.d/03-Zubereitung.sql
- ./rezepte_bilder.sql:/docker-entrypoint-initdb.d/04-rezepte_bilder.sql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD}"]
interval: 30s
timeout: 10s
retries: 5
networks:
- rezepte-network
backend:
build:
context: ./nodejs-version/backend
dockerfile: Dockerfile
container_name: rezepte-backend-dev
restart: unless-stopped
environment:
- NODE_ENV=development
- DATABASE_URL=mysql://rezepte:${MYSQL_PASSWORD}@mysql:3306/rezepte_klaus
- CORS_ORIGIN=${CORS_ORIGIN:-*}
- PORT=3001
ports:
- "0.0.0.0:3001:3001"
volumes:
- uploads_dev_data:/app/uploads
# Development: Mount source code for hot reload
- ./nodejs-version/backend/src:/app/src:ro
- ./nodejs-version/backend/prisma:/app/prisma:ro
depends_on:
mysql:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3001/api/health"]
interval: 30s
timeout: 10s
retries: 3
networks:
- rezepte-network
frontend:
build:
context: ./nodejs-version/frontend
dockerfile: Dockerfile
container_name: rezepte-frontend-dev
restart: unless-stopped
ports:
- "0.0.0.0:3000:80"
depends_on:
- backend
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/"]
interval: 30s
timeout: 10s
retries: 3
networks:
- rezepte-network
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
container_name: rezepte-phpmyadmin-dev
restart: unless-stopped
environment:
- PMA_HOST=mysql
- PMA_PORT=3306
- PMA_USER=root
- PMA_PASSWORD=${MYSQL_ROOT_PASSWORD}
- UPLOAD_LIMIT=2G
- MEMORY_LIMIT=2G
ports:
- "0.0.0.0:8080:80"
depends_on:
mysql:
condition: service_healthy
networks:
- rezepte-network
volumes:
mysql_dev_data:
driver: local
uploads_dev_data:
driver: local
networks:
rezepte-network:
driver: bridge
EOF
echo "✅ Created docker-compose.development.yml"
# Create development startup script
echo "📝 Creating development startup script..."
cat > start-development.sh << 'EOF'
#!/bin/bash
set -e
echo "🚀 Starting Rezepte Klaus Development Environment on Linux"
echo "========================================================="
# Load environment variables
if [ -f .env.development ]; then
export $(cat .env.development | grep -v '^#' | xargs)
else
echo "❌ Error: .env.development file not found!"
echo "Please run setup-development.sh first."
exit 1
fi
echo "🔍 Server IP: $HOST_IP"
# Stop any existing containers
echo "🛑 Stopping existing containers..."
docker-compose -f docker-compose.development.yml down
# Build and start services
echo "🏗️ Building and starting services..."
docker-compose -f docker-compose.development.yml up -d --build
# Wait for services
echo "⏳ Waiting for services to start..."
sleep 30
# Check service health
echo "🔍 Checking service health..."
HEALTHY_SERVICES=$(docker-compose -f docker-compose.development.yml ps --filter "status=running" | grep -c "Up" || true)
if [ "$HEALTHY_SERVICES" -ge 4 ]; then
echo "✅ Development environment started successfully!"
echo ""
echo "🌐 Access URLs:"
echo " Frontend: http://$HOST_IP:3000"
echo " Backend API: http://$HOST_IP:3001/api"
echo " phpMyAdmin: http://$HOST_IP:8080"
echo ""
echo "🔒 SSH Tunnel (for secure access from Mac):"
echo " ssh -L 3000:localhost:3000 -L 3001:localhost:3001 -L 8080:localhost:8080 user@$HOST_IP"
echo " Then access: http://localhost:3000"
echo ""
echo "📊 Service Status:"
docker-compose -f docker-compose.development.yml ps
else
echo "❌ Some services failed to start. Check logs:"
docker-compose -f docker-compose.development.yml logs --tail=20
fi
echo ""
echo "📋 Development Commands:"
echo " View logs: docker-compose -f docker-compose.development.yml logs -f"
echo " Rebuild frontend: docker-compose -f docker-compose.development.yml build frontend && docker-compose -f docker-compose.development.yml restart frontend"
echo " Rebuild backend: docker-compose -f docker-compose.development.yml build backend && docker-compose -f docker-compose.development.yml restart backend"
echo " Stop: docker-compose -f docker-compose.development.yml down"
EOF
chmod +x start-development.sh
echo "✅ Created executable start-development.sh"
echo ""
echo "🎯 Setup completed! Next steps:"
echo ""
echo "1. 📝 Review configuration:"
echo " cat .env.development"
echo ""
echo "2. 🚀 Start development environment:"
echo " ./start-development.sh"
echo ""
echo "3. 🌐 Access from your Mac:"
echo " Direct: http://$HOST_IP:3000"
echo " SSH Tunnel: ssh -L 3000:localhost:3000 user@$HOST_IP"
echo ""
echo "4. 🔄 For code changes:"
echo " - Edit files locally on Mac"
echo " - Sync to server (git, rsync, or VS Code Remote)"
echo " - Rebuild containers as needed"
EOF