muv/laravel-deployment

Automatische Deployments mit GitHub

Maintainers

Package info

github.com/MeinsUndVogel/laravel-deployment

pkg:composer/muv/laravel-deployment

Statistics

Installs: 301

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.1.1 2026-03-12 08:35 UTC

This package is auto-updated.

Last update: 2026-04-18 00:55:36 UTC


README

Latest Stable Version Latest Unstable Version License

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:

  1. Repository SettingsWebhooksAdd webhook
  2. Payload URL: https://yourdomain.com/deploy.php
  3. Secret: Wert aus GITHUB_WEBHOOK_SECRET
  4. Content type: application/json
  5. Events: Push events

Funktionsweise

Bei jedem Push zum konfigurierten Branch läuft das Deployment im Hintergrund:

  1. Lädt deploy_pre.sh (falls vorhanden)
  2. Lädt deploy_pre.php (falls vorhanden, kann Standard-Befehle überschreiben)
  3. 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
  4. Lädt deploy_post.sh (falls vorhanden)
  5. 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.