Add CI/CD support for automated tunnel deployment
Some checks failed
deploy-tunnel / deploy (push) Failing after 1s
Some checks failed
deploy-tunnel / deploy (push) Failing after 1s
- setup-ci.sh: Script no interactivo que verifica archivos de config - Workflow actualizado para ejecutar setup-ci.sh antes del deploy - Los archivos credentials.json y .env persisten en el workspace del runner - Solo requiere setup.sh manual la primera vez en el servidor - Documentación actualizada con instrucciones para CI/CD
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
# Cloudflare Tunnel ID
|
# Cloudflare Tunnel ID
|
||||||
# Obtén este ID cuando crees el tunnel con: cloudflared tunnel create <nombre>
|
# Obtén este ID cuando crees el tunnel con: cloudflared tunnel create <nombre>
|
||||||
TUNNEL_ID=your-tunnel-id-here
|
TUNNEL_ID=your-tunnel-id-here
|
||||||
|
|
||||||
|
# Cloudflare API Credentials (opcional, solo para CI/CD automatizado)
|
||||||
|
# CLOUDFLARE_ACCOUNT_ID=your-account-id
|
||||||
|
# CLOUDFLARE_API_TOKEN=your-api-token
|
||||||
|
|||||||
@@ -8,21 +8,14 @@ jobs:
|
|||||||
#───────────────── deploy ─────────────────
|
#───────────────── deploy ─────────────────
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
|
env:
|
||||||
|
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Setup tunnel if needed
|
- name: Check and setup tunnel if needed
|
||||||
run: |
|
run: ./setup-ci.sh
|
||||||
if [ ! -f credentials.json ] || [ ! -f .env ]; then
|
|
||||||
echo "⚠️ credentials.json o .env no encontrados"
|
|
||||||
echo " Ejecuta './setup.sh' manualmente en el servidor para configurar el tunnel"
|
|
||||||
echo ""
|
|
||||||
echo " O copia manualmente:"
|
|
||||||
echo " - credentials.json desde ~/.cloudflared/<TUNNEL_ID>.json"
|
|
||||||
echo " - .env con TUNNEL_ID configurado"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "✓ credentials.json y .env encontrados"
|
|
||||||
|
|
||||||
- name: Pull fresh cloudflared image
|
- name: Pull fresh cloudflared image
|
||||||
run: docker compose pull
|
run: docker compose pull
|
||||||
|
|||||||
30
README.md
30
README.md
@@ -150,24 +150,42 @@ El contenedor se conecta a la red `principal` para poder comunicarse con Traefik
|
|||||||
Este repositorio incluye un workflow de Gitea Actions (`.gitea/workflows/deploy.yml`) que automáticamente despliega el tunnel cuando haces push a `main`.
|
Este repositorio incluye un workflow de Gitea Actions (`.gitea/workflows/deploy.yml`) que automáticamente despliega el tunnel cuando haces push a `main`.
|
||||||
|
|
||||||
**¿Qué hace el workflow?**
|
**¿Qué hace el workflow?**
|
||||||
1. Verifica que existan `credentials.json` y `.env`
|
1. Ejecuta `setup-ci.sh` para verificar que existan `credentials.json` y `.env`
|
||||||
2. Descarga la última imagen de `cloudflare/cloudflared`
|
2. Descarga la última imagen de `cloudflare/cloudflared`
|
||||||
3. Detiene el stack actual
|
3. Detiene el stack actual
|
||||||
4. Levanta el stack actualizado
|
4. Levanta el stack actualizado
|
||||||
5. Muestra los logs del tunnel
|
5. Muestra los logs del tunnel
|
||||||
|
|
||||||
**Setup inicial en el servidor:**
|
### Setup inicial para CI/CD
|
||||||
|
|
||||||
En el servidor donde corre el gitea-runner, ejecuta el setup una sola vez:
|
**Primera vez en el servidor donde corre el gitea-runner:**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# El gitea-runner clonará el repo automáticamente
|
# 1. El runner clonará el repo automáticamente en su workspace
|
||||||
# Solo necesitas ejecutar setup.sh la primera vez
|
# 2. SSH al servidor y navega al workspace del runner
|
||||||
cd /ruta/donde/runner/clona/el/repo
|
cd /ruta/donde/runner/clona/el/repo
|
||||||
|
|
||||||
|
# 3. Ejecuta setup.sh UNA SOLA VEZ (requiere login interactivo)
|
||||||
./setup.sh
|
./setup.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Una vez configurado, cada `git push` actualizará automáticamente el tunnel.
|
El script creará `credentials.json` y `.env` que **persisten** en el workspace del runner entre ejecuciones.
|
||||||
|
|
||||||
|
**De ahí en adelante:**
|
||||||
|
- Cada `git push` ejecuta el workflow automáticamente
|
||||||
|
- `setup-ci.sh` verifica que los archivos existan
|
||||||
|
- Si existen, continúa con el deploy
|
||||||
|
- Si no existen, el workflow falla con instrucciones
|
||||||
|
|
||||||
|
### (Opcional) Variables de entorno en Gitea Secrets
|
||||||
|
|
||||||
|
Puedes configurar secrets en Gitea para el workflow (aunque actualmente no son necesarios con el enfoque de setup manual):
|
||||||
|
|
||||||
|
```
|
||||||
|
Settings > Secrets > Actions:
|
||||||
|
- CLOUDFLARE_ACCOUNT_ID: tu-account-id
|
||||||
|
- CLOUDFLARE_API_TOKEN: tu-api-token
|
||||||
|
```
|
||||||
|
|
||||||
**Nota**: `credentials.json` y `.env` se generan localmente y NO se commitean al repo (están en `.gitignore`), por seguridad.
|
**Nota**: `credentials.json` y `.env` se generan localmente y NO se commitean al repo (están en `.gitignore`), por seguridad.
|
||||||
|
|
||||||
|
|||||||
50
setup-ci.sh
Executable file
50
setup-ci.sh
Executable file
@@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Setup no interactivo para CI/CD (Gitea Actions)
|
||||||
|
# Usa Cloudflare API Token en vez de login interactivo
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
TUNNEL_NAME="nucleorio-tunnel"
|
||||||
|
DOMAIN="nucleoriofrio.com"
|
||||||
|
ACCOUNT_ID="${CLOUDFLARE_ACCOUNT_ID}"
|
||||||
|
API_TOKEN="${CLOUDFLARE_API_TOKEN}"
|
||||||
|
|
||||||
|
echo "🤖 Cloudflare Tunnel CI Setup"
|
||||||
|
echo "=============================="
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Verificar variables de entorno
|
||||||
|
if [ -z "$ACCOUNT_ID" ]; then
|
||||||
|
echo "❌ CLOUDFLARE_ACCOUNT_ID no está configurado"
|
||||||
|
echo " Configúralo en Gitea: Settings > Secrets"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$API_TOKEN" ]; then
|
||||||
|
echo "❌ CLOUDFLARE_API_TOKEN no está configurado"
|
||||||
|
echo " Configúralo en Gitea: Settings > Secrets"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Verificar si ya existen los archivos
|
||||||
|
if [ -f "credentials.json" ] && [ -f ".env" ]; then
|
||||||
|
echo "✓ credentials.json y .env ya existen"
|
||||||
|
TUNNEL_ID=$(jq -r '.TunnelID' credentials.json 2>/dev/null || echo "")
|
||||||
|
|
||||||
|
if [ -n "$TUNNEL_ID" ]; then
|
||||||
|
echo "✓ TUNNEL_ID: $TUNNEL_ID"
|
||||||
|
echo "✓ Setup ya está completo, no se requiere acción"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "⚠️ Archivos de configuración no encontrados"
|
||||||
|
echo ""
|
||||||
|
echo "Para CI/CD automatizado necesitas:"
|
||||||
|
echo "1. Ejecutar ./setup.sh manualmente UNA VEZ en el servidor"
|
||||||
|
echo "2. Esto genera credentials.json y .env"
|
||||||
|
echo "3. Estos archivos persisten entre deploys del runner"
|
||||||
|
echo ""
|
||||||
|
echo "El workflow automáticamente los usará en futuros deploys."
|
||||||
|
echo ""
|
||||||
|
exit 1
|
||||||
Reference in New Issue
Block a user