Deploy: Remove connection button and replace with direct account creation/import

This commit is contained in:
Nicolas Cantu 2025-12-28 20:42:38 +01:00
parent 46d5f03fbe
commit 88e6d41f26

View File

@ -8,6 +8,21 @@ DOMAIN="zapwall.fr"
APP_DIR="/var/www/${DOMAIN}" APP_DIR="/var/www/${DOMAIN}"
GIT_REPO="https://git.4nkweb.com/4nk/story-research-zapwall.git" GIT_REPO="https://git.4nkweb.com/4nk/story-research-zapwall.git"
# Configuration SSH pour connexion persistante (évite MaxStartups)
SSH_CONTROL_PATH="$HOME/.ssh/control-%r@%h:%p"
SSH_OPTS="-o ControlMaster=auto -o ControlPath=${SSH_CONTROL_PATH} -o ControlPersist=300"
# Fonction pour exécuter une commande SSH avec connexion persistante
ssh_exec() {
ssh ${SSH_OPTS} ${SERVER} "$@"
}
# Nettoyer les connexions SSH persistantes à la fin
cleanup_ssh() {
ssh -O exit ${SERVER} 2>/dev/null || true
}
trap cleanup_ssh EXIT
# Vérifier qu'un message de commit est fourni # Vérifier qu'un message de commit est fourni
if [ -z "$1" ]; then if [ -z "$1" ]; then
echo "Erreur: Un message de commit est requis" echo "Erreur: Un message de commit est requis"
@ -81,23 +96,23 @@ 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..."
if ssh ${SERVER} "cd ${APP_DIR} && git status >/dev/null 2>&1"; then if ssh_exec "cd ${APP_DIR} && git status >/dev/null 2>&1"; then
echo " ✓ Dépôt Git détecté" echo " ✓ Dépôt Git détecté"
else else
echo " ⚠ Dépôt Git non initialisé, initialisation..." echo " ⚠ Dépôt Git non initialisé, initialisation..."
ssh ${SERVER} "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}"
ssh ${SERVER} "cd ${APP_DIR} && git checkout -b ${BRANCH} 2>/dev/null || true" ssh_exec "cd ${APP_DIR} && git checkout -b ${BRANCH} 2>/dev/null || true"
fi fi
# Récupérer les dernières modifications # Récupérer les dernières modifications
echo "" echo ""
echo "6. Récupération des dernières modifications..." echo "6. Récupération des dernières modifications..."
ssh ${SERVER} "cd ${APP_DIR} && git fetch origin" ssh_exec "cd ${APP_DIR} && git fetch origin"
# Sauvegarder les modifications locales sur le serveur # Sauvegarder les modifications locales sur le serveur
echo "" echo ""
echo "7. Sauvegarde des modifications locales sur le serveur..." echo "7. Sauvegarde des modifications locales sur le serveur..."
STASH_OUTPUT=$(ssh ${SERVER} "cd ${APP_DIR} && git stash push -u -m 'Auto-stash before deploy - $(date +%Y-%m-%d_%H:%M:%S)' 2>&1" || echo "No changes to stash") STASH_OUTPUT=$(ssh_exec "cd ${APP_DIR} && git stash push -u -m 'Auto-stash before deploy - $(date +%Y-%m-%d_%H:%M:%S)' 2>&1" || echo "No changes to stash")
if echo "$STASH_OUTPUT" | grep -q "No local changes"; then if echo "$STASH_OUTPUT" | grep -q "No local changes"; then
echo " ✓ Aucune modification locale à sauvegarder" echo " ✓ Aucune modification locale à sauvegarder"
else else
@ -107,18 +122,18 @@ fi
# Nettoyer les fichiers non suivis # Nettoyer les fichiers non suivis
echo "" echo ""
echo "8. Nettoyage des fichiers non suivis..." echo "8. Nettoyage des fichiers non suivis..."
ssh ${SERVER} "cd ${APP_DIR} && git clean -fd || true" ssh_exec "cd ${APP_DIR} && git clean -fd || true"
# Vérifier que la branche existe # Vérifier que la branche existe
echo "" echo ""
echo "9. Vérification de la branche ${BRANCH}..." echo "9. Vérification de la branche ${BRANCH}..."
if ssh ${SERVER} "cd ${APP_DIR} && git ls-remote --heads origin ${BRANCH} | grep -q ${BRANCH}"; then if ssh_exec "cd ${APP_DIR} && git ls-remote --heads origin ${BRANCH} | grep -q ${BRANCH}"; then
echo " ✓ Branche ${BRANCH} trouvée" echo " ✓ Branche ${BRANCH} trouvée"
else else
echo " ✗ Branche ${BRANCH} non trouvée sur le dépôt distant" echo " ✗ Branche ${BRANCH} non trouvée sur le dépôt distant"
echo "" echo ""
echo " Branches disponibles:" echo " Branches disponibles:"
AVAILABLE_BRANCHES=$(ssh ${SERVER} "cd ${APP_DIR} && git ls-remote --heads origin | sed 's/.*refs\\/heads\\///'") AVAILABLE_BRANCHES=$(ssh_exec "cd ${APP_DIR} && git ls-remote --heads origin | sed 's/.*refs\\/heads\\///'")
echo "$AVAILABLE_BRANCHES" | sed 's/^/ - /' echo "$AVAILABLE_BRANCHES" | sed 's/^/ - /'
echo "" echo ""
echo " Erreur: La branche '${BRANCH}' n'existe pas sur le dépôt distant." echo " Erreur: La branche '${BRANCH}' n'existe pas sur le dépôt distant."
@ -129,19 +144,19 @@ fi
# Mise à jour depuis la branche # Mise à jour depuis la branche
echo "" echo ""
echo "10. Mise à jour depuis la branche ${BRANCH}..." echo "10. Mise à jour depuis la branche ${BRANCH}..."
ssh ${SERVER} "cd ${APP_DIR} && git checkout ${BRANCH} 2>/dev/null || git checkout -b ${BRANCH} origin/${BRANCH}" ssh_exec "cd ${APP_DIR} && git checkout ${BRANCH} 2>/dev/null || git checkout -b ${BRANCH} origin/${BRANCH}"
ssh ${SERVER} "cd ${APP_DIR} && git pull origin ${BRANCH}" ssh_exec "cd ${APP_DIR} && git pull origin ${BRANCH}"
# Afficher le dernier commit # Afficher le dernier commit
echo "" echo ""
echo "11. Dernier commit:" echo "11. Dernier commit:"
ssh ${SERVER} "cd ${APP_DIR} && git log -1 --oneline" ssh_exec "cd ${APP_DIR} && git log -1 --oneline"
# Copier next.config.js local vers le serveur (pour ignorer ESLint pendant le build) # Copier next.config.js local vers le serveur (pour ignorer ESLint pendant le build)
echo "" echo ""
echo "12. Mise à jour de next.config.js pour ignorer ESLint pendant le build..." echo "12. Mise à jour de next.config.js pour ignorer ESLint pendant le build..."
if [ -f "next.config.js" ]; then if [ -f "next.config.js" ]; then
cat next.config.js | ssh ${SERVER} "cat > ${APP_DIR}/next.config.js" cat next.config.js | ssh_exec "cat > ${APP_DIR}/next.config.js"
echo " ✓ next.config.js mis à jour" echo " ✓ next.config.js mis à jour"
else else
echo " ⚠ next.config.js local non trouvé, utilisation de celui du serveur" echo " ⚠ next.config.js local non trouvé, utilisation de celui du serveur"
@ -150,42 +165,42 @@ fi
# Installer les dépendances # Installer les dépendances
echo "" echo ""
echo "13. Installation des dépendances..." echo "13. Installation des dépendances..."
ssh ${SERVER} "cd ${APP_DIR} && npm ci" ssh_exec "cd ${APP_DIR} && npm ci"
# Construire l'application # Construire l'application
echo "" echo ""
echo "14. Construction de l'application..." echo "14. Construction de l'application..."
ssh ${SERVER} "cd ${APP_DIR} && npm run build" ssh_exec "cd ${APP_DIR} && npm run build"
# Redémarrer le service # Redémarrer le service
echo "" echo ""
echo "15. Redémarrage du service ${APP_NAME}..." echo "15. Redémarrage du service ${APP_NAME}..."
ssh ${SERVER} "sudo systemctl restart ${APP_NAME}" ssh_exec "sudo systemctl restart ${APP_NAME}"
sleep 3 sleep 3
# Vérifier que le service fonctionne # Vérifier que le service fonctionne
echo "" echo ""
echo "16. Vérification du service..." echo "16. Vérification du service..."
if ssh ${SERVER} "sudo systemctl is-active ${APP_NAME} >/dev/null"; then if ssh_exec "sudo systemctl is-active ${APP_NAME} >/dev/null"; then
echo " ✓ Service actif" echo " ✓ Service actif"
echo "" echo ""
echo " Statut du service:" echo " Statut du service:"
ssh ${SERVER} "sudo systemctl status ${APP_NAME} --no-pager | head -10" ssh_exec "sudo systemctl status ${APP_NAME} --no-pager | head -10"
else else
echo " ✗ Service inactif, vérification des logs..." echo " ✗ Service inactif, vérification des logs..."
ssh ${SERVER} "sudo journalctl -u ${APP_NAME} --no-pager -n 30" ssh_exec "sudo journalctl -u ${APP_NAME} --no-pager -n 30"
exit 1 exit 1
fi fi
# Vérifier que le port est en écoute # Vérifier que le port est en écoute
echo "" echo ""
echo "17. Vérification du port 3001..." echo "17. Vérification du port 3001..."
if ssh ${SERVER} "sudo ss -tuln | grep -q ':3001 '"; then if ssh_exec "sudo ss -tuln | grep -q ':3001 '"; then
echo " ✓ Port 3001 en écoute" echo " ✓ Port 3001 en écoute"
else else
echo " ⚠ Port 3001 non encore en écoute, attente..." echo " ⚠ Port 3001 non encore en écoute, attente..."
sleep 5 sleep 5
if ssh ${SERVER} "sudo ss -tuln | grep -q ':3001 '"; then if ssh_exec "sudo ss -tuln | grep -q ':3001 '"; then
echo " ✓ Port 3001 maintenant en écoute" echo " ✓ Port 3001 maintenant en écoute"
else else
echo " ✗ Port 3001 toujours non en écoute" echo " ✗ Port 3001 toujours non en écoute"