From ce63c08ac96367a01022e5bae1ddb0158b2f3403 Mon Sep 17 00:00:00 2001 From: Nicolas Cantu Date: Tue, 6 Jan 2026 14:26:30 +0100 Subject: [PATCH] Fix deployment script blocking at Git repository check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **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 --- deploy.sh | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/deploy.sh b/deploy.sh index adfa5b7..c05dbf9 100644 --- a/deploy.sh +++ b/deploy.sh @@ -144,21 +144,24 @@ 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" - 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 - echo " ✓ Dépôt Git détecté après réessai" + 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" >/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}"