|
|
@@ -1,10 +1,10 @@
|
|
|
#!/bin/bash
|
|
|
# NetPulse — script de actualización (lo lanza el updater del backend, corre
|
|
|
-# como netpulse). Flujo dual según el backend instalado:
|
|
|
-# - Go (/opt/netpulse/server-go/netpulse existe): git pull → binario
|
|
|
-# precompilado de CI (go-latest) → swap atómico → reinicio diferido.
|
|
|
-# - Node (legacy): git pull → deps → dist precompilado (dist-latest) →
|
|
|
-# swap atómico del dist → reinicio diferido.
|
|
|
+# como netpulse). Único flujo soportado: Go.
|
|
|
+# - Go (/opt/netpulse/server-go/netpulse): git pull → binario precompilado
|
|
|
+# de CI (go-latest) → swap atómico → reinicio diferido.
|
|
|
+# El backend Node (legacy/server-node/) se conserva solo como histórico; NO se
|
|
|
+# despliega ni actualiza (decisión 5-Ago-2026).
|
|
|
set -e
|
|
|
cd /opt/netpulse
|
|
|
|
|
|
@@ -49,55 +49,11 @@ if [ -f /opt/netpulse/server-go/netpulse ]; then
|
|
|
echo "STEP:restart"
|
|
|
# Reinicio vía unidad systemd.path del CT (netpulse-go-restart.path vigila
|
|
|
# este flag y ejecuta systemctl restart netpulse-go.service como root).
|
|
|
- # El dir puede no existir (DATA_DIR real vive en /opt/netpulse/server/data):
|
|
|
+ # El dir puede no existir (DATA_DIR real vive en /opt/netpulse/server-go/data):
|
|
|
# crearlo antes de tocar el flag (bug visto 1-Ago-2026: touch fallaba y el
|
|
|
# binario nuevo quedaba instalado sin reiniciar).
|
|
|
mkdir -p /opt/netpulse/server-go/data
|
|
|
touch /opt/netpulse/server-go/data/.restart-me
|
|
|
-else
|
|
|
- # ---------------- Flujo Node (legacy) ----------------
|
|
|
- echo "STEP:server-deps"
|
|
|
- if git diff --name-only 'HEAD@{1}' HEAD 2>/dev/null | grep -q 'server/package-lock.json'; then
|
|
|
- cd /opt/netpulse/server
|
|
|
- npm ci --omit=dev --no-audit --no-fund
|
|
|
- fi
|
|
|
-
|
|
|
- echo "STEP:frontend-build"
|
|
|
- cd /opt/netpulse
|
|
|
- URL="https://github.com/gnacho/netpulse/releases/download/dist-latest/app-dist-$SHA.tar.gz"
|
|
|
- rm -rf /opt/netpulse/app/dist.new
|
|
|
- mkdir -p /opt/netpulse/app/dist.new
|
|
|
- # Vía preferida: dist precompilado por CI (el CT no tiene RAM para compilar).
|
|
|
- # 1) asset exacto del commit; 2) si no existe (commit sin cambios en app/),
|
|
|
- # el asset más reciente disponible (el dist no ha cambiado entonces).
|
|
|
- if curl -fsSL -m 300 "$URL" -o /tmp/app-dist.tgz && tar xzf /tmp/app-dist.tgz -C /opt/netpulse/app/dist.new; then
|
|
|
- echo "dist precompilado descargado de CI ($SHA)"
|
|
|
- else
|
|
|
- ASSET=$(curl -fsSL -m 30 https://api.github.com/repos/gnacho/netpulse/releases/tags/dist-latest \
|
|
|
- | grep -oP '"name":\s*"\Kapp-dist-[0-9a-f]+\.tar\.gz' | head -1)
|
|
|
- if [ -n "$ASSET" ] && curl -fsSL -m 300 "https://github.com/gnacho/netpulse/releases/download/dist-latest/$ASSET" -o /tmp/app-dist.tgz \
|
|
|
- && tar xzf /tmp/app-dist.tgz -C /opt/netpulse/app/dist.new; then
|
|
|
- echo "dist de CI más reciente disponible ($ASSET)"
|
|
|
- else
|
|
|
- echo "sin dist en CI; build local (riesgo OOM en 512MB)"
|
|
|
- cd /opt/netpulse/app
|
|
|
- # npm ci SOLO si cambió el lockfile (656 paquetes: OOM seguro en el CT)
|
|
|
- if git diff --name-only 'HEAD@{1}' HEAD 2>/dev/null | grep -q 'app/package-lock.json'; then
|
|
|
- npm ci --no-audit --no-fund
|
|
|
- fi
|
|
|
- npm run build -- --outDir dist.new
|
|
|
- fi
|
|
|
- fi
|
|
|
- # Swap atómico: si algo falló antes, el dist anterior queda intacto
|
|
|
- rm -rf /opt/netpulse/app/dist.old
|
|
|
- [ -d /opt/netpulse/app/dist ] && mv /opt/netpulse/app/dist /opt/netpulse/app/dist.old
|
|
|
- mv /opt/netpulse/app/dist.new /opt/netpulse/app/dist
|
|
|
- rm -rf /opt/netpulse/app/dist.old /tmp/app-dist.tgz
|
|
|
-
|
|
|
- echo "STEP:restart"
|
|
|
- # Reinicio vía unidad systemd.path del CT (netpulse-restart.path vigila este
|
|
|
- # flag y ejecuta systemctl restart netpulse.service como root)
|
|
|
- touch /opt/netpulse/server/data/.restart-me
|
|
|
fi
|
|
|
|
|
|
echo "STEP:done"
|