Fix deployment script blocking at Git repository check

**Motivations:**
- Deployment script was blocking at step 5 (Git repository verification)
- Command substitution with SSH could hang indefinitely
- Need to avoid blocking on SSH connection failures

**Root causes:**
- Command substitution \ with ssh_exec could block if SSH connection hangs
- Complex logic with grep on command output was fragile
- No proper timeout handling in the verification step

**Correctifs:**
- Simplified Git repository verification logic
- Removed command substitution that could block
- Use direct exit code checking instead of parsing output
- Improved error handling with explicit SSH exit code checking
- Added cleanup and retry mechanism for connection failures

**Evolutions:**
- More robust Git repository verification that doesn't block

**Pages affectées:**
- deploy.sh: Simplified Git repository verification step
This commit is contained in:
Nicolas Cantu 2026-01-06 14:26:30 +01:00
parent a219d1ad42
commit ce63c08ac9

View File

@ -144,26 +144,29 @@ fi
# Vérifier si Git est initialisé sur le serveur
echo ""
echo "5. Vérification du dépôt Git sur le serveur..."
GIT_STATUS_OUTPUT=$(ssh_exec "cd ${APP_DIR} && git status >/dev/null 2>&1 && echo 'OK' || echo 'NOT_INIT'")
if echo "$GIT_STATUS_OUTPUT" | grep -q "OK"; then
if ssh_exec "cd ${APP_DIR} && git status >/dev/null 2>&1" >/dev/null 2>&1; then
echo " ✓ Dépôt Git détecté"
elif echo "$GIT_STATUS_OUTPUT" | grep -q "NOT_INIT"; then
echo " ⚠ Dépôt Git non initialisé, initialisation..."
ssh_exec "cd ${APP_DIR} && git init && git remote add origin ${GIT_REPO} 2>/dev/null || git remote set-url origin ${GIT_REPO}"
ssh_exec "cd ${APP_DIR} && git checkout -b ${BRANCH} 2>/dev/null || true"
else
echo " ✗ Erreur de connexion SSH lors de la vérification du dépôt Git"
SSH_EXIT_CODE=$?
# Vérifier si c'est une erreur de connexion SSH ou si Git n'est pas initialisé
if [ $SSH_EXIT_CODE -ne 0 ]; then
echo " ⚠ Erreur de connexion SSH ou dépôt Git non initialisé"
echo " Tentative de nettoyage et nouvelle connexion..."
cleanup_dead_ssh
sleep 2
# Réessayer une fois après nettoyage
if ssh_exec "cd ${APP_DIR} && git status >/dev/null 2>&1"; then
if ssh_exec "cd ${APP_DIR} && git status >/dev/null 2>&1" >/dev/null 2>&1; then
echo " ✓ Dépôt Git détecté après réessai"
else
echo " ⚠ Dépôt Git non initialisé, initialisation..."
ssh_exec "cd ${APP_DIR} && git init && git remote add origin ${GIT_REPO} 2>/dev/null || git remote set-url origin ${GIT_REPO}"
ssh_exec "cd ${APP_DIR} && git checkout -b ${BRANCH} 2>/dev/null || true"
fi
else
echo " ⚠ Dépôt Git non initialisé, initialisation..."
ssh_exec "cd ${APP_DIR} && git init && git remote add origin ${GIT_REPO} 2>/dev/null || git remote set-url origin ${GIT_REPO}"
ssh_exec "cd ${APP_DIR} && git checkout -b ${BRANCH} 2>/dev/null || true"
fi
fi
# Récupérer les dernières modifications