¿Cómo funciona?
Section titled “¿Cómo funciona?”Cuando haces git push a la rama main, ocurren dos procesos automaticos
en paralelo:
git push origin main │ ├──[1]──→ GitHub Actions (validate) │ │ │ ├── Cloudflare Pages │ │ │ │ │ └── Build & Deploy → ai-lab.labrazahome.com │ │ (Blog Publico) │ │ │ └── Self-Hosted Runner (192.168.1.30) │ │ │ ├── git checkout │ ├── npm ci │ ├── npm run build │ └── systemctl restart ailab-docs.service │ │ │ └── blog-ai-lab.labrazahome.com │ (Blog Privado) │ └──[2]──→ El runner ejecuta el workflow deploy.yml[1] Blog Publico (Cloudflare Pages)
Section titled “[1] Blog Publico (Cloudflare Pages)”- GitHub notifica a Cloudflare Pages del nuevo commit
- Cloudflare Pages clona el repo y ejecuta
npm run build - Publica el resultado en
ai-lab.labrazahome.com - Tiempo total: ~1-2 minutos
- Sin intervencion manual
[2] Blog Privado (Self-Hosted Runner)
Section titled “[2] Blog Privado (Self-Hosted Runner)”- GitHub Actions ejecuta el job
deploy-localen el runner local - El runner (maquina 192.168.1.30) hace checkout del codigo
- Ejecuta
npm cipara instalar dependencias - Ejecuta
npm run buildpara compilar Astro - Ejecuta
sudo systemctl restart ailab-docs.service - El servicio
ailab-docs.service(Astro preview en :4322) sirve la nueva version - Tiempo total: ~20-30 segundos
- Sin intervencion manual
Componentes del Sistema
Section titled “Componentes del Sistema”Workflow: .github/workflows/deploy.yml
Section titled “Workflow: .github/workflows/deploy.yml”on: push: branches: [main] paths: ['apps/ialab-docs/**', '.github/workflows/**']
concurrency: group: ialab-docs-deploy cancel-in-progress: true
jobs: validate: runs-on: ubuntu-latest steps: - name: Check Python syntax run: python3 -m py_compile runtime/gateway/openai_gateway.py || true
deploy-local: needs: validate runs-on: self-hosted steps: - uses: actions/checkout@v4 - name: Install dependencies run: npm ci working-directory: apps/ialab-docs - name: Build Astro run: npm run build working-directory: apps/ialab-docs - name: Restart docs service run: sudo systemctl restart ailab-docs.serviceSelf-Hosted Runner: ailab-runner.service
Section titled “Self-Hosted Runner: ailab-runner.service”[Unit]Description=GitHub Actions Runner (AI-LAB)After=network-online.target
[Service]Type=simpleUser=albertWorkingDirectory=/opt/ai-lab/actions-runnerExecStart=/opt/ai-lab/actions-runner/run.shRestart=alwaysRestartSec=10
[Install]WantedBy=multi-user.targetSudoers: acceso restringido
Section titled “Sudoers: acceso restringido”albert ALL=(root) NOPASSWD: /bin/systemctl restart ailab-docs.serviceEl runner solo puede ejecutar systemctl restart ailab-docs.service como root,
nada mas. La contrasena no queda almacenada en ningun lado.
¿Que trigger actualiza cada blog?
Section titled “¿Que trigger actualiza cada blog?”| Cambio | Blog Publico | Blog Privado |
|---|---|---|
Push a main con cambios en apps/ialab-docs/ | ✅ Automatico (Cloudflare Pages) | ✅ Automatico (Runner local) |
Push a main sin cambios en docs | ❌ No se activa | ❌ No se activa |
| Workflow manual (GitHub Actions UI) | ❌ No se activa | ✅ Manual, solo para remediation |
Archivos del proyecto
Section titled “Archivos del proyecto”| Archivo | Proposito |
|---|---|
.github/workflows/deploy.yml | Workflow de CI/CD |
/etc/systemd/system/ailab-runner.service | Servicio del runner |
/etc/sudoers.d/ailab-docs | Permiso sudo limitado |
/opt/ai-lab/actions-runner/ | Directorio del runner |
.gitignore | Excluye actions-runner/ |
Comandos de gestion
Section titled “Comandos de gestion”# Ver estado del runnersystemctl status ailab-runner.service
# Ver logs del runnerjournalctl -u ailab-runner.service -n 50 --no-pager
# Ver logs del buildjournalctl -u ailab-runner.service | grep -E 'Job|Running|Finish'
# Reiniciar runnersystemctl restart ailab-runner.service
# Ver ultimo build en el blog privadocurl -s http://localhost:4322/ | head -1Verificacion de funcionamiento
Section titled “Verificacion de funcionamiento”Para validar que todo funciona correctamente:
# 1. Hacer un cambio en un documentoecho "test" >> apps/ialab-docs/src/content/docs/almacenamiento-ai-lab.md
# 2. Commit y pushgit add -A && git commit -m "test: verificacion CI/CD" && git push origin main
# 3. Verificar en GitHub Actions que el job se ejecuta# https://github.com/albertgracia/ai-lab/actions
# 4. Esperar y verificar ambos blogs# Blog publico: curl -s https://ai-lab.labrazahome.com/ | head -1# Blog privado: curl -s http://localhost:4322/ | head -1