Prepare VPS handover: bootstrap, doctor, DB backup, systemd unit, backend deploy, operations guide; commit docs sources previously ignored

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
denis
2026-10-16 23:15:14 +02:00
parent fb3c539eee
commit a4df92a7c6
43 changed files with 2369 additions and 8 deletions
+28 -2
View File
@@ -5,16 +5,23 @@
#
# DEPLOY_HOST=utilisateur@vps.example.org ./scripts/deploy.sh [--dry-run]
# DEPLOY_HOST=utilisateur@vps.example.org ./scripts/deploy.sh --rollback
# DEPLOY_HOST=utilisateur@vps.example.org ./scripts/deploy.sh --backend [--no-restart]
#
# --backend : envoie le code du backend Django (dossier backend/) dans DEPLOY_BACKEND_PATH puis redémarre le service
# (« sudo -n systemctl restart pyquest » : voir deploy/remote_setup.sh qui autorise cette seule commande). Au
# redémarrage, systemd applique les migrations et collecte les fichiers statiques.
#
# Variables : DEPLOY_HOST (obligatoire), DEPLOY_PATH (défaut /var/www/pyquest), DEPLOY_KEEP (défaut 3),
# DEPLOY_SSH (défaut « ssh -o BatchMode=yes »).
# DEPLOY_BACKEND_PATH (défaut /opt/pyquest/backend), DEPLOY_SSH (défaut « ssh -o BatchMode=yes »).
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
HOST="${DEPLOY_HOST:-}"
REMOTE_PATH="${DEPLOY_PATH:-/var/www/pyquest}"
KEEP="${DEPLOY_KEEP:-3}"
BACKEND_PATH="${DEPLOY_BACKEND_PATH:-/opt/pyquest/backend}"
SSH="${DEPLOY_SSH:-ssh -o BatchMode=yes}"
RESTART=1
MODE="deploy"
DRY_RUN=0
@@ -22,7 +29,9 @@ for arg in "$@"; do
case "${arg}" in
--dry-run) DRY_RUN=1 ;;
--rollback) MODE="rollback" ;;
-h|--help) sed -n '2,11p' "${BASH_SOURCE[0]}"; exit 0 ;;
--backend) MODE="backend" ;;
--no-restart) RESTART=0 ;;
-h|--help) sed -n '2,16p' "${BASH_SOURCE[0]}"; exit 0 ;;
*) echo "Option inconnue : ${arg}" >&2; exit 2 ;;
esac
done
@@ -30,6 +39,7 @@ done
# Ces valeurs sont insérées dans des commandes distantes : on n'accepte que des caractères sûrs.
[[ "${HOST}" =~ ^[A-Za-z0-9_.@:-]+$ ]] || { echo "DEPLOY_HOST manquant ou invalide (ex. utilisateur@vps.example.org)" >&2; exit 2; }
[[ "${REMOTE_PATH}" =~ ^/[A-Za-z0-9_./-]{3,}$ ]] || { echo "DEPLOY_PATH doit être un chemin absolu simple (ex. /var/www/pyquest)" >&2; exit 2; }
[[ "${BACKEND_PATH}" =~ ^/[A-Za-z0-9_./-]{3,}$ ]] || { echo "DEPLOY_BACKEND_PATH doit être un chemin absolu simple" >&2; exit 2; }
[[ "${KEEP}" =~ ^[1-9][0-9]*$ ]] || { echo "DEPLOY_KEEP doit être un entier >= 1" >&2; exit 2; }
remote() {
@@ -50,6 +60,22 @@ ln -sfn \"releases/\$previous\" current.tmp && mv -Tf current.tmp current; echo
exit 0
fi
if [[ "${MODE}" == "backend" ]]; then
[[ -f "${ROOT}/backend/manage.py" ]] || { echo "backend/manage.py introuvable." >&2; exit 1; }
echo "Envoi du backend vers ${HOST}:${BACKEND_PATH}"
remote "mkdir -p '${BACKEND_PATH}'"
BACK=(rsync -az --delete --chmod=D755,F644 -e "${SSH}"
--exclude='__pycache__/' --exclude='*.pyc' --exclude='db.sqlite3' --exclude='staticfiles/' --exclude='.venv/' --exclude='venv/' --exclude='*.mo')
[[ "${DRY_RUN}" == 1 ]] && BACK+=(--dry-run --itemize-changes)
"${BACK[@]}" "${ROOT}/backend/" "${HOST}:${BACKEND_PATH}/"
if [[ "${RESTART}" == 1 ]]; then
# Une seule commande sudo autorisée sans mot de passe (voir deploy/remote_setup.sh) ; sinon on le dit.
remote "sudo -n systemctl restart pyquest" || echo "Redémarrage impossible sans mot de passe : lance « sudo systemctl restart pyquest » sur le VPS." >&2
fi
echo "Backend envoyé. Migrations et statiques sont appliqués au démarrage du service."
exit 0
fi
[[ -f "${ROOT}/dist/index.html" ]] || { echo "dist/ est absent : lance d'abord « make build »." >&2; exit 1; }
[[ -f "${ROOT}/dist/vendor/pyodide/pyodide.asm.wasm" ]] || { echo "Pyodide manque dans dist/ : « make vendor-pyodide » puis « make build »." >&2; exit 1; }