00
#!/usr/bin/env bash
# Déploie le code committé (HEAD) de Dimdam's Docs sur server-003 :
# envoie les fichiers, installe, compile le site statique (out/), sans PM2 car servi directement par Nginx.
# bash scripts/deploy.sh (depuis Git Bash sur le PC)
set -euo pipefail
repo="$(cd "$(dirname "$0")/.." && pwd)"
cd "$repo"
if [ ! -f package.json ] || ! grep -q '"name": "dimdams-docs"' package.json; then
echo "Ce script doit rester dans le dépôt dimdams-docs (dossier actuel : $repo)." >&2
exit 1
fi
if [ -n "$(git status --porcelain)" ]; then
echo "Attention : des modifications ne sont pas committées, seul le dernier commit est envoyé." >&2
fi
server="${DEPLOY_SERVER:-root@192.168.1.131}"
app="/home/benladamm/dimdams-docs"
echo "Déploiement de $(git log --oneline -1) vers $server:$app"
git archive HEAD | ssh "$server" "set -e
mkdir -p $app
cd $app
tar -xf -
if [ ! -f .env ]; then
cp .env.example .env
fi
npm ci --no-audit --no-fund > /tmp/dd-npm.log 2>&1 || { tail -25 /tmp/dd-npm.log; exit 1; }
npm run build > /tmp/dd-build.log 2>&1 || { tail -25 /tmp/dd-build.log; exit 1; }
chown -R benladamm:benladamm $app
echo 'Compilation statique : OK (out/)'"
echo "Terminé : https://docs.dimdams.com"