Files
michaelschiemer/deploy.sh
Michael Schiemer e30753ba0e fix: resolve RedisCache array offset error and improve discovery diagnostics
- Fix RedisCache driver to handle MGET failures gracefully with fallback
- Add comprehensive discovery context comparison debug tools
- Identify root cause: WEB context discovery missing 166 items vs CLI
- WEB context missing RequestFactory class entirely (52 vs 69 commands)
- Improved exception handling with detailed binding diagnostics
2025-09-12 20:05:18 +02:00

116 lines
4.3 KiB
Bash
Executable File

#!/bin/bash
# Konfiguration
SERVER_USER="deploy"
SERVER_IP="94.16.110.151"
REMOTE_PATH="/home/deploy/michaelschiemer"
LOCAL_PATH="."
EXCLUDES="--exclude=.git --exclude=node_modules --exclude=vendor --exclude=.env"
SSH_OPTS="-i ~/.ssh/production -o StrictHostKeyChecking=no"
# Farben für Ausgabe
GREEN="\e[32m"
YELLOW="\e[33m"
RED="\e[31m"
RESET="\e[0m"
echo -e "${YELLOW}Deployment auf ${SERVER_IP} starten...${RESET}"
# 1. Temporäres Verzeichnis erstellen
TMP_DIR=$(mktemp -d)
echo -e "${YELLOW}Temporäres Verzeichnis erstellt: ${TMP_DIR}${RESET}"
# 2. Dateien in temporäres Verzeichnis kopieren (ohne Ausschlüsse)
echo -e "${YELLOW}Kopiere Projektdateien...${RESET}"
rsync -a $EXCLUDES "$LOCAL_PATH/" "$TMP_DIR/"
# 3. Archiv erstellen
echo -e "${YELLOW}Erstelle Archiv...${RESET}"
TMP_ARCHIVE="/tmp/project-$(date +%Y%m%d-%H%M%S).tar.gz"
tar -czf "$TMP_ARCHIVE" -C "$TMP_DIR" .
# 4. Verzeichnisse auf dem Server erstellen
echo -e "${YELLOW}Erstelle Verzeichnisse auf dem Server...${RESET}"
ssh $SSH_OPTS "$SERVER_USER@$SERVER_IP" "mkdir -p $REMOTE_PATH"
# 5. Archiv auf den Server übertragen
echo -e "${YELLOW}Übertrage Dateien auf den Server...${RESET}"
scp -i ~/.ssh/production "$TMP_ARCHIVE" "$SERVER_USER@$SERVER_IP:/tmp/project.tar.gz"
# 6. Archiv auf dem Server entpacken
echo -e "${YELLOW}Entpacke Dateien auf dem Server...${RESET}"
ssh $SSH_OPTS "$SERVER_USER@$SERVER_IP" "tar -xzf /tmp/project.tar.gz -C $REMOTE_PATH"
# 7. Production Umgebungsdatei kopieren
echo -e "${YELLOW}Kopiere Production-Umgebungsdatei...${RESET}"
ssh $SSH_OPTS "$SERVER_USER@$SERVER_IP" "cp $REMOTE_PATH/.env.production $REMOTE_PATH/.env"
# 8. Berechtigungen setzen
echo -e "${YELLOW}Setze Berechtigungen...${RESET}"
ssh $SSH_OPTS "$SERVER_USER@$SERVER_IP" "chmod -R 775 $REMOTE_PATH/storage $REMOTE_PATH/cache"
# 9. Abhängigkeiten installieren und Build ausführen
echo -e "${YELLOW}Installiere Abhängigkeiten und baue Assets...${RESET}"
ssh $SSH_OPTS "$SERVER_USER@$SERVER_IP" "cd $REMOTE_PATH && composer install --no-dev && npm ci && npm run build"
# 10. SSL-Zertifikate prüfen und ggf. einrichten
echo -e "${YELLOW}Prüfe SSL-Zertifikate...${RESET}"
ssh $SSH_OPTS "$SERVER_USER@$SERVER_IP" "
cd $REMOTE_PATH
if [ ! -f ssl/fullchain.pem ] || [ ! -f ssl/privkey.pem ]; then
echo 'SSL-Zertifikate fehlen - bitte setup-production-ssl.sh ausführen'
echo 'Starte ohne SSL für erste Einrichtung...'
mkdir -p ssl
# Temporäre selbst-signierte Zertifikate für ersten Start
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout ssl/privkey.pem \
-out ssl/fullchain.pem \
-subj '/CN=michaelschiemer.de'
chmod 644 ssl/fullchain.pem ssl/privkey.pem
fi
"
# 11. Docker Container neu starten
echo -e "${YELLOW}Starte Docker Container neu...${RESET}"
ssh $SSH_OPTS "$SERVER_USER@$SERVER_IP" "cd $REMOTE_PATH && docker compose up -d"
# 12. Validate production configuration
echo -e "${YELLOW}Validiere Production-Konfiguration...${RESET}"
ssh $SSH_OPTS "$SERVER_USER@$SERVER_IP" "cd $REMOTE_PATH && \
# Check environment configuration
APP_ENV=\$(grep '^APP_ENV=' .env | cut -d'=' -f2 | tr -d '\"')
APP_DEBUG=\$(grep '^APP_DEBUG=' .env | cut -d'=' -f2 | tr -d '\"')
echo 'Environment: \$APP_ENV'
echo 'Debug mode: \$APP_DEBUG'
if [ '\$APP_ENV' = 'production' ] && [ '\$APP_DEBUG' = 'false' ]; then
echo '✓ Production environment correctly configured'
else
echo '✗ WARNING: Environment not configured for production!'
exit 1
fi
# Test security endpoints (wait for containers to be ready)
sleep 10
# Test blocked route - should return 404 in production
debug_response=\$(curl -s -o /dev/null -w '%{http_code}' -H 'User-Agent: Mozilla/5.0' https://localhost/debug 2>/dev/null || echo 'connection_failed')
if [ '\$debug_response' = '404' ]; then
echo '✓ Debug routes properly blocked'
else
echo '✗ WARNING: Debug routes not properly blocked (got: \$debug_response)'
fi
"
# 13. Aufräumen
echo -e "${YELLOW}Räume auf...${RESET}"
rm -rf "$TMP_DIR" "$TMP_ARCHIVE"
ssh $SSH_OPTS "$SERVER_USER@$SERVER_IP" "rm /tmp/project.tar.gz"
echo -e "${GREEN}Deployment abgeschlossen!${RESET}"
echo -e "${YELLOW}Docker Container Status:${RESET}"
ssh $SSH_OPTS "$SERVER_USER@$SERVER_IP" "cd $REMOTE_PATH && docker compose ps"
exit 0