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