muv / laravel-deployment
Automatische Deployments mit GitHub
Requires
- php: ^8.3
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-laravel: ^2.3
README
Mit diesem Package kann in einem PHP-Projekt automatisch ein Update bei Push-Events im GitHub Repository durchgeführt werden.
Installation
Einbindung mit Composer
composer require muv/laravel-deployment
Danach das Deploy-Script publizieren:
./vendor/bin/publish-deploy
Dies erstellt eine deploy.php Datei im public Verzeichnis.
Konfiguration
Erforderliche Umgebungsvariablen:
DEPLOYMENT_BRANCH=deployment GITHUB_WEBHOOK_CONTENT_TYPE=application/json GITHUB_WEBHOOK_SECRET=
GitHub Webhook einrichten:
- Repository Settings → Webhooks → Add webhook
- Payload URL:
https://yourdomain.com/deploy.php - Secret: Wert aus
GITHUB_WEBHOOK_SECRET - Content type:
application/json - Events: Push events
Funktionsweise
Bei jedem Push zum konfigurierten Branch läuft das Deployment im Hintergrund:
- Lädt
deploy_pre.sh(falls vorhanden) - Lädt
deploy_pre.php(falls vorhanden, kann Standard-Befehle überschreiben) - Führt die Standard-Deployment-Befehle aus:
git reset --hard git pull php artisan down composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader --no-progress npm ci --ignore-scripts npm run build php artisan optimize php artisan migrate --force php artisan up
- Lädt
deploy_post.sh(falls vorhanden) - Lädt
deploy_post.php(falls vorhanden)
Der Webhook antwortet sofort mit 200 OK; das Deployment läuft asynchron im Hintergrund. Alle Aktivitäten werden in
deployment.log protokolliert.
Hooks anpassen
Erstelle optional folgende Dateien im Root-Verzeichnis:
deploy_pre.sh: Shell-Script vor dem Deployment:
#!/usr/bin/env bash tar -czf backup/$(date +%Y%m%d_%H%M%S).tar.gz .
deploy_pre.php: PHP-Script vor dem Deployment (überschreibt Standard-Befehle):
<?php return [ 'git reset --hard', 'git pull', 'composer install --no-interaction', 'npm ci', 'php artisan down', 'php artisan migrate --force', 'npm run build', 'php artisan up', ];
deploy_post.sh: Shell-Script nach dem Deployment:
#!/usr/bin/env bash curl -X POST https://monitoring.example.com/alert -d "status=deployed"
deploy_post.php: PHP-Script nach dem Deployment:
<?php file_put_contents('deployment-log.txt', "Deployment erfolgreich\n", FILE_APPEND);
Manuelles Triggern
Deployment per Code auslösen (ohne Webhook-Validierung):
MUV\LaravelDeployment\Deployer::triggerAsync();
Kontakt
Bei Fragen oder Anregungen: muv.com/kontakt
Tests
composer test
Lizenz
Das Package ist unter der MIT-Lizenz erhältlich.