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}"
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
if [ -z "$1" ]; then
echo "Erreur: Un message de commit est requis"
@ -81,23 +96,23 @@ fi
# Vérifier si Git est initialisé sur le serveur
echo ""
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é"
else
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 ${SERVER} "cd ${APP_DIR} && git checkout -b ${BRANCH} 2>/dev/null || true"
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
# Récupérer les dernières modifications
echo ""
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
echo ""
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
echo " ✓ Aucune modification locale à sauvegarder"
else
@ -107,18 +122,18 @@ fi
# Nettoyer les fichiers non suivis
echo ""
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
echo ""
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"
else
echo " ✗ Branche ${BRANCH} non trouvée sur le dépôt distant"
echo ""
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 ""
echo " Erreur: La branche '${BRANCH}' n'existe pas sur le dépôt distant."
@ -129,19 +144,19 @@ fi
# Mise à jour depuis la branche
echo ""
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 ${SERVER} "cd ${APP_DIR} && git pull origin ${BRANCH}"
ssh_exec "cd ${APP_DIR} && git checkout ${BRANCH} 2>/dev/null || git checkout -b ${BRANCH} origin/${BRANCH}"
ssh_exec "cd ${APP_DIR} && git pull origin ${BRANCH}"
# Afficher le dernier commit
echo ""
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)
echo ""
echo "12. Mise à jour de next.config.js pour ignorer ESLint pendant le build..."
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"
else
echo " ⚠ next.config.js local non trouvé, utilisation de celui du serveur"
@ -150,42 +165,42 @@ fi
# Installer les dépendances
echo ""
echo "13. Installation des dépendances..."
ssh ${SERVER} "cd ${APP_DIR} && npm ci"
ssh_exec "cd ${APP_DIR} && npm ci"
# Construire l'application
echo ""
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
echo ""
echo "15. Redémarrage du service ${APP_NAME}..."
ssh ${SERVER} "sudo systemctl restart ${APP_NAME}"
ssh_exec "sudo systemctl restart ${APP_NAME}"
sleep 3
# Vérifier que le service fonctionne
echo ""
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 ""
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
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
fi
# Vérifier que le port est en écoute
echo ""
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"
else
echo " ⚠ Port 3001 non encore en écoute, attente..."
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"
else
echo " ✗ Port 3001 toujours non en écoute"