Quellcode durchsuchen

CI: dist precompilado en GitHub Actions (release dist-latest por sha)

update.sh descarga el build exacto de su commit; fallback a build local.
El CT (512MB, ZFS sin swapfile posible) ya no compila el frontend.
gnacho vor 4 Monaten
Ursprung
Commit
b6ac83a9a8
3 geänderte Dateien mit 72 neuen und 11 gelöschten Zeilen
  1. 48 0
      .github/workflows/dist.yml
  2. 21 11
      deploy/update.sh
  3. 3 0
      server/src/updater.js

+ 48 - 0
.github/workflows/dist.yml

@@ -0,0 +1,48 @@
+name: dist
+
+# Compila app/dist en CI y lo publica como asset de la prerelease "dist-latest"
+# (el CT 226 tiene 512MB y no puede compilar; el updater descarga el build
+# exacto de su commit: app-dist-<sha>.tar.gz).
+
+on:
+  push:
+    branches: [main]
+    paths:
+      - 'app/**'
+      - '.github/workflows/dist.yml'
+  workflow_dispatch:
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v4
+
+      - uses: actions/setup-node@v4
+        with:
+          node-version: 22
+          cache: npm
+          cache-dependency-path: app/package-lock.json
+
+      - name: Build frontend
+        working-directory: app
+        run: npm ci --no-audit --no-fund && npm run build
+
+      - name: Empaqueta dist
+        run: tar czf app-dist-${{ github.sha }}.tar.gz -C app/dist .
+
+      - name: Publica en prerelease dist-latest
+        uses: softprops/action-gh-release@v2
+        with:
+          tag_name: dist-latest
+          name: dist-latest
+          prerelease: true
+          files: app-dist-${{ github.sha }}.tar.gz
+
+      - name: Limpia assets antiguos (conserva los 5 últimos)
+        env:
+          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        run: |
+          gh release view dist-latest --json assets --jq '.assets[].name' \
+            | sort -r | tail -n +6 \
+            | while read -r a; do gh release delete-asset dist-latest "$a" -y; done

+ 21 - 11
deploy/update.sh

@@ -15,18 +15,28 @@ if git diff --name-only 'HEAD@{1}' HEAD 2>/dev/null | grep -q 'server/package-lo
 fi
 
 echo "STEP:frontend-build"
-cd /opt/netpulse/app
-# npm ci SOLO si cambió el lockfile (656 paquetes: OOM seguro en el CT de 512MB)
-if git diff --name-only 'HEAD@{1}' HEAD 2>/dev/null | grep -q 'app/package-lock.json'; then
-  npm ci --no-audit --no-fund
+cd /opt/netpulse
+SHA=$(git rev-parse HEAD)
+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)
+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
+  echo "sin dist en CI para $SHA; 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
-# Build atómico: si falla (p.ej. RAM justa), el dist anterior queda intacto
-rm -rf dist.new
-npm run build -- --outDir dist.new
-rm -rf dist.old
-[ -d dist ] && mv dist dist.old
-mv dist.new dist
-rm -rf dist.old
+# 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

+ 3 - 0
server/src/updater.js

@@ -103,8 +103,10 @@ export function createUpdater({ repoRoot, repo, token }) {
     child.on('close', (code) => {
       if (code === 0) {
         state.updating = { step: 'done', log: state.updating.log }
+        state.lastLog = state.updating.log
         state.updateAvailable = false
       } else {
+        state.lastLog = state.updating?.log ?? null
         state.updating = false
         state.error = `update_exit_${code}`
       }
@@ -127,6 +129,7 @@ export function createUpdater({ repoRoot, repo, token }) {
       return {
         ...state,
         updating: state.updating ? { step: state.updating.step } : false,
+        lastLog: state.updating?.log?.slice(-800) ?? state.lastLog ?? null,
         repo,
         hasToken: Boolean(token),
       }