Repository Public
1#!/bin/zsh2# =============================================================================3# SP BOUCHER | INFRASTRUCTURE & AUTOMATION4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : MacLustr SMS Gateway8# File : deployment/update.sh9# Module : deployment10# Repository : https://git.spboucher.ai/maclustr-sms11# Project Website : https://sms.spboucher.ai12# Created : 2026-11-3013# Last Modified : 2026-11-3014#15# Author : Simon-Pierre Boucher16# Position : Professor of Finance17# Institution : Université du Québec en Outaouais (UQO)18# Organization : SP Boucher19# Website : https://spboucher.ai20# Git : https://git.spboucher.ai21#22# Preferred Contact: admin@spboucher.ai23# Technical Contact: dev@spboucher.ai24# Security/Admin : admin@spboucher.ai25#26# Copyright (c) 202627# Simon-Pierre Boucher28# All rights reserved where applicable. This file is governed by the29# applicable project license, copyright notices and relevant law.30# Existing third-party rights and notices remain unaffected.31#32# License : None specified (no license file in this repository)33#34# Do not embed credentials, private keys, access tokens,35# certificates or confidential personal information.36#37# =============================================================================38# END OF SP BOUCHER SOURCE HEADER39# =============================================================================4041# Mise à jour de la production, à lancer SUR LE NŒUD dans ~/apps/maclustr-sms (dépôt git, origin = dépôt privé spbgit).42# ssh -A M2U64 'cd ~/apps/maclustr-sms && zsh deployment/update.sh'43# Récupère main, reconstruit, redémarre, vérifie la santé. En cas d'échec de santé : retour au commit précédent.44set -euo pipefail45export PATH="/opt/homebrew/bin:/opt/homebrew/opt/postgresql@17/bin:/usr/bin:/bin:/usr/sbin:/sbin"46cd "$(dirname "$0")/.."47[ -z "$(git status --porcelain)" ] || { echo "modifications non commitées sur le nœud : les commiter ou les écarter d'abord"; git status --short; exit 1; }48PREV=$(git rev-parse HEAD)49build() { pnpm install --frozen-lockfile --silent && node scripts/build.mjs >/dev/null && node_modules/.bin/vite build >/dev/null && zsh scripts/node-setup.sh >/dev/null; }50healthy() { for i in {1..20}; do curl -fsS -m 3 http://127.0.0.1:8750/api/health/ready >/dev/null 2>&1 && return 0; sleep 0.5; done; return 1; }51git pull -q --ff-only origin main52NEW=$(git rev-parse HEAD)53[ "$PREV" = "$NEW" ] && [ "${1:-}" != "--force" ] && { echo "déjà à jour ($NEW)"; exit 0; }54# Sauvegarde avant migration éventuelle du schéma.55zsh scripts/backup.sh | tail -156build57pm2 restart maclustr-sms --update-env >/dev/null58if healthy; then echo "mis à jour : ${PREV:0:7} → ${NEW:0:7}, santé ok"; exit 0; fi59echo "SANTÉ EN ÉCHEC après ${NEW:0:7} : retour à ${PREV:0:7} (les migrations déjà appliquées ne sont pas défaites : voir docs/DEPLOYMENT.md § Rollback)"60git reset -q --hard "$PREV"; build; pm2 restart maclustr-sms --update-env >/dev/null61healthy && echo "retour arrière effectué, santé ok" || echo "SANTÉ TOUJOURS EN ÉCHEC : intervention manuelle requise (pm2 logs maclustr-sms)"62exit 163