feat: hosting NGINX + webhook Gitea para deploy automático
This commit is contained in:
+49
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* deploy.php — Webhook de deploy automático para ksaldis-dt
|
||||
*
|
||||
* Gitea envía POST a esta URL al hacer push.
|
||||
* Ejecuta deploy_ksaldis.sh para actualizar el contenido.
|
||||
*
|
||||
* Configuración en Gitea:
|
||||
* Settings → Webhooks → Add webhook (Gitea)
|
||||
* URL: https://rmonla.duckdns.org/ksaldis-dt/deploy.php
|
||||
* Content type: application/json
|
||||
* Secret: ksaldis2026deploy
|
||||
* Events: Push events
|
||||
*/
|
||||
|
||||
define('WEBHOOK_SECRET', 'ksaldis2026deploy');
|
||||
|
||||
// Solo POST
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
die('Method not allowed');
|
||||
}
|
||||
|
||||
// Verificar firma de Gitea (X-Gitea-Signature usa HMAC SHA256)
|
||||
$payload = file_get_contents('php://input');
|
||||
$signature = $_SERVER['HTTP_X_GITEA_SIGNATURE'] ?? '';
|
||||
|
||||
if ($signature) {
|
||||
$expected = hash_hmac('sha256', $payload, WEBHOOK_SECRET);
|
||||
if (!hash_equals($expected, $signature)) {
|
||||
http_response_code(403);
|
||||
die('Invalid signature');
|
||||
}
|
||||
}
|
||||
|
||||
// Ejecutar deploy
|
||||
$scriptPath = __DIR__ . '/deploy_ksaldis.sh';
|
||||
$output = [];
|
||||
$returnCode = 0;
|
||||
|
||||
exec("bash $scriptPath 2>&1", $output, $returnCode);
|
||||
|
||||
// Respuesta
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode([
|
||||
'ok' => $returnCode === 0,
|
||||
'output' => implode("\n", $output),
|
||||
'time' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
# deploy_ksaldis.sh — Script de deploy automático
|
||||
# Llamado por el webhook de Gitea al hacer push
|
||||
#
|
||||
# Clona/actualiza el repo y copia LIBRO_DE_ESTUDIO.html como index.html
|
||||
|
||||
set -e
|
||||
|
||||
REPO_DIR="/var/www/ksaldis-dt/.repo"
|
||||
WEB_DIR="/var/www/ksaldis-dt"
|
||||
REPO_URL="http://10.0.10.205:3000/rmonla/rm-KSALDIS-DT.git"
|
||||
LOG="$WEB_DIR/deploy.log"
|
||||
|
||||
log() {
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') | $1" >> "$LOG"
|
||||
}
|
||||
|
||||
log "Deploy iniciado"
|
||||
|
||||
# Clonar o actualizar repo
|
||||
if [ -d "$REPO_DIR/.git" ]; then
|
||||
cd "$REPO_DIR"
|
||||
git fetch origin 2>&1
|
||||
git reset --hard origin/main 2>&1
|
||||
log "git pull OK"
|
||||
else
|
||||
git clone "$REPO_URL" "$REPO_DIR" 2>&1
|
||||
log "git clone OK"
|
||||
fi
|
||||
|
||||
# Copiar el libro como index.html
|
||||
SRC="$REPO_DIR/descargar-curso/descargas/LIBRO_DE_ESTUDIO.html"
|
||||
if [ -f "$SRC" ]; then
|
||||
cp "$SRC" "$WEB_DIR/index.html"
|
||||
log "index.html actualizado ($(wc -c < "$WEB_DIR/index.html") bytes)"
|
||||
else
|
||||
log "ERROR: LIBRO_DE_ESTUDIO.html no encontrado en el repo"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "Deploy completado"
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,60 @@
|
||||
# HOSTING — Despliegue en Servidor NGINX Privado
|
||||
|
||||
> Última actualización: 2026-05-03
|
||||
|
||||
## Servidor
|
||||
|
||||
| Parámetro | Valor |
|
||||
|---|---|
|
||||
| **IP** | `10.0.10.117` |
|
||||
| **Acceso SSH** | `ssh rmonla@10.0.10.117` |
|
||||
| **Dominio público** | `rmonla.duckdns.org` (SSL Let's Encrypt) |
|
||||
| **Web Server** | NGINX |
|
||||
|
||||
## URL de Acceso
|
||||
|
||||
| Entorno | URL |
|
||||
|---|---|
|
||||
| **Red local** | `http://10.0.10.117/ksaldis-dt` |
|
||||
| **Público** | `https://rmonla.duckdns.org/ksaldis-dt` |
|
||||
|
||||
## Qué se Sirve
|
||||
|
||||
Un único archivo `index.html` con el **Libro de Estudio completo** del Curso de Entrenador Nacional de Vóley. Es contenido estático puro, autónomo, sin dependencias externas.
|
||||
|
||||
```
|
||||
/var/www/ksaldis-dt/
|
||||
└── index.html ← LIBRO_DE_ESTUDIO.html renombrado
|
||||
```
|
||||
|
||||
## Configuración NGINX
|
||||
|
||||
Archivo: `/etc/nginx/sites-available/default`
|
||||
|
||||
Bloque dentro del `server {}` principal:
|
||||
|
||||
```nginx
|
||||
# Ruta /ksaldis-dt — Material de estudio de Voley
|
||||
location /ksaldis-dt {
|
||||
alias /var/www/ksaldis-dt;
|
||||
index index.html;
|
||||
try_files $uri $uri/ =404;
|
||||
autoindex on;
|
||||
}
|
||||
```
|
||||
|
||||
## Deploy / Actualización
|
||||
|
||||
Cuando se regenera el libro con `node generar_dashboard.mjs`, subir la nueva versión:
|
||||
|
||||
```bash
|
||||
scp descargar-curso/descargas/LIBRO_DE_ESTUDIO.html rmonla@10.0.10.117:/var/www/ksaldis-dt/index.html
|
||||
```
|
||||
|
||||
## Otros Sitios en el Mismo Servidor
|
||||
|
||||
| Ruta | Directorio | Tipo |
|
||||
|---|---|---|
|
||||
| `/` | `/var/www/html` | Estática |
|
||||
| `/vcby` | `/var/www/vcby` | PHP (ViaCrucis) |
|
||||
| `/ksaldis-dt` | `/var/www/ksaldis-dt` | Estática |
|
||||
Reference in New Issue
Block a user