dummybot/deploy-runner.sh
javiservices 00fcbc9a7c
Some checks are pending
Deploy DummyBot / Build & Deploy to ${{ env.DEPLOY_HOST }} (push) Waiting to run
fix(deploy): excluir CSRF en /webhook/* + script self-contained
- bootstrap/app.php: validateCsrfTokens except webhook/*
- WebhookController: ejecuta deploy-runner.sh (vive en repo)
- deploy-runner.sh: hace git pull + composer + npm + migrate + cache
- docker-compose.yml: solo monta el repo (sin script externo)
2026-06-18 12:16:48 +02:00

60 lines
2.5 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# ─────────────────────────────────────────────────────────────
# DummyBot deploy runner (vive en el repo)
# Llamado por el webhook de Gitea. Hace git pull + composer +
# npm + migrate + cache clear + restart.
#
# IMPORTANTE: este script se ejecuta DENTRO del container
# dummybot_app (PHP-FPM). Por tanto:
# - git, composer, npm están disponibles (Dockerfile los instala)
# - artisan funciona con `php artisan`
# - `docker compose` se puede invocar contra el socket del host
# ─────────────────────────────────────────────────────────────
set -e
BRANCH="${BRANCH:-main}"
APP_DIR="${APP_DIR:-/var/www}"
cd "$APP_DIR"
echo "═══════════════════════════════════════════"
echo " DummyBot deploy — $(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo " Branch: $BRANCH"
echo " App dir: $APP_DIR"
echo "═══════════════════════════════════════════"
echo "→ git fetch + reset"
git fetch origin "$BRANCH" 2>&1 | tail -3
git reset --hard "origin/$BRANCH" 2>&1 | tail -3
NEW_COMMIT=$(git rev-parse --short HEAD)
echo "HEAD: $NEW_COMMIT"
echo "→ composer install"
composer install --no-dev --no-interaction --no-progress --optimize-autoloader 2>&1 | tail -3
echo "→ npm install + build"
if [ -f package-lock.json ]; then
npm ci --no-audit --no-fund 2>&1 | tail -3
else
npm install --no-audit --no-fund 2>&1 | tail -3
fi
npm run build 2>&1 | tail -3 || echo " (build skipped)"
echo "→ artisan migrate"
php artisan migrate --force 2>&1 | tail -5
echo "→ artisan cache:clear"
php artisan config:clear 2>&1 | tail -1
php artisan route:clear 2>&1 | tail -1
php artisan view:clear 2>&1 | tail -1
php artisan event:clear 2>&1 | tail -1
php artisan optimize 2>&1 | tail -3
echo "→ restart php-fpm (graceful)"
# Recargar el FPM para que coja el nuevo código
if command -v kill &> /dev/null; then
kill -USR2 1 2>&1 || true
fi
echo "═══════════════════════════════════════════"
echo " Deploy OK: $NEW_COMMIT"
echo "═══════════════════════════════════════════"