Files
michaelschiemer/ansible/netcup-simple-deploy/deploy.sh

120 lines
3.2 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# PHP Projekt Deployment Script für Netcup (nutzt bestehende docker-compose.yml)
set -e
echo "🚀 Projekt Deployment zu Netcup (nutzt deine docker-compose.yml)"
echo ""
# Prüfe ob Konfiguration angepasst wurde
if grep -q "85.123.456.789" inventory/hosts.yml; then
echo "❌ Bitte erst die Konfiguration anpassen!"
echo ""
echo "1. vim inventory/hosts.yml"
echo " - Server IP ändern"
echo " - Domain ändern"
echo " - app_port prüfen (Port deiner App)"
echo ""
echo "2. Dann nochmal: ./deploy.sh"
exit 1
fi
LOCAL_APP_PATH=$(grep "local_app_path:" inventory/hosts.yml | awk '{print $2}' | tr -d '"')
# Prüfe Projektstruktur
echo "📁 Prüfe Projektstruktur..."
FULL_PATH="$LOCAL_APP_PATH"
if [ ! -d "$FULL_PATH" ]; then
echo "❌ Projekt-Verzeichnis nicht gefunden: $FULL_PATH"
exit 1
fi
echo "✅ Projektstruktur OK:"
echo " 📂 Projekt: $FULL_PATH"
# Prüfe docker-compose.yml
if [ -f "$FULL_PATH/docker-compose.yml" ]; then
echo " ✅ docker-compose.yml gefunden im Root"
elif [ -f "$FULL_PATH/docker/docker-compose.yml" ]; then
echo " ✅ docker-compose.yml gefunden in docker/"
else
echo " Keine docker-compose.yml gefunden - wird automatisch erstellt"
fi
# Zeige docker-compose.yml Inhalt falls vorhanden
if [ -f "$FULL_PATH/docker-compose.yml" ]; then
echo ""
echo "📋 Deine docker-compose.yml (erste 10 Zeilen):"
head -10 "$FULL_PATH/docker-compose.yml" | sed 's/^/ /'
elif [ -f "$FULL_PATH/docker/docker-compose.yml" ]; then
echo ""
echo "📋 Deine docker-compose.yml aus docker/ (erste 10 Zeilen):"
head -10 "$FULL_PATH/docker/docker-compose.yml" | sed 's/^/ /'
fi
# Ping test
echo ""
echo "🔍 Teste Verbindung zum Server..."
if ! ansible all -m ping; then
echo "❌ Server nicht erreichbar. Prüfe:"
echo " - IP-Adresse korrekt?"
echo " - SSH-Key installiert? (ssh-copy-id root@deine-ip)"
echo " - Server läuft?"
exit 1
fi
echo "✅ Server erreichbar!"
echo ""
# Wähle Deployment-Methode
echo "🔧 Deployment-Optionen:"
echo "1. Standard: Saubere Docker-Installation (empfohlen)"
echo "2. Fallback: Debian Standard-Pakete (falls Probleme auftreten)"
echo ""
read -p "Wähle Option (1/2): " -n 1 -r
echo
if [[ $REPLY == "2" ]]; then
PLAYBOOK="deploy-debian-fallback.yml"
echo "📦 Verwende Debian Standard-Pakete"
else
PLAYBOOK="deploy.yml"
echo "🐳 Verwende saubere Docker-Installation"
fi
# Deployment confirmation
read -p "🚀 Projekt deployen? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Deployment abgebrochen."
exit 0
fi
echo "🔧 Starte Deployment mit $PLAYBOOK..."
echo "💡 Das Deployment nutzt deine bestehende docker-compose.yml!"
echo ""
ansible-playbook "$PLAYBOOK"
echo ""
echo "🎉 Deployment abgeschlossen!"
echo ""
# Zeige Ergebnisse
DOMAIN=$(grep "domain:" inventory/hosts.yml | awk '{print $2}' | tr -d '"')
echo "🌐 Dein Projekt ist verfügbar unter:"
echo " https://$DOMAIN"
echo ""
echo "📊 Status prüfen:"
echo " curl -I https://$DOMAIN"
echo ""
echo "🔧 Container-Status anschauen:"
echo " make status"
echo ""
echo "🔧 Logs anschauen:"
echo " make logs"
echo ""
echo "🔄 Nach Änderungen:"
echo " make deploy"