nassirian/laravel-github-deployer
Composer 安装命令:
composer require nassirian/laravel-github-deployer
包简介
A simple GitHub webhook-based deployer for Laravel applications.
README 文档
README
Simple and flexible Laravel package to automate deployments using GitHub Webhooks.
This package supports both:
- 🔁 Synchronous deployments (runs directly on the server)
- 🧵 Queue-based deployments (offloaded to dedicated queue workers — e.g., Docker container or remote worker)
✅ Features
- Git pull
- Composer install
- Docker container restart
- Laravel migrations, route/config caching
- Dedicated
deployqueue support - Secure signature verification from GitHub
📦 Installation
composer require nassirian/laravel-github-deployer
⚙️ Configuration (Optional)
Publish the config file to customize deployment behavior:
php artisan vendor:publish --tag=config
This creates: config/github-deployer.php
return [ // 'sync' will run directly on server, 'queue' will dispatch a job to deploy queue 'mode' => env('DEPLOY_MODE', 'queue'), // Deploy queue name for queue-based mode 'queue_name' => env('DEPLOY_QUEUE', 'deploy'), // Optional job middleware (e.g., throttle or queue isolation) 'middleware' => [ \Nassirian\GitHubDeployer\Middleware\EnsureDeployQueue::class, ], // Commands to run before deploy 'pre_deploy_commands' => [], // Main deploy commands 'deploy_commands' => [ 'git pull origin main', 'composer install --no-interaction --prefer-dist --optimize-autoloader', 'docker-compose pull', 'docker-compose up -d', ], // Post-deploy artisan commands 'post_deploy_commands' => [ 'php artisan migrate --force', 'php artisan config:cache', 'php artisan route:cache', ], // Optional throttle behavior for wrong queue workers 'deploy_release_throttle' => [ 'base_delay' => 5, 'max_attempts' => 5, ], ];
📡 GitHub Webhook Setup
- Expose your webhook route
Laravel will respond to:
POST /github/webhook
-
Add Webhook in GitHub:
- Go to Repo Settings → Webhooks → Add Webhook
- Payload URL:
https://your-domain.com/github/webhook - Content type:
application/json - Secret:
your-random-string - Events: ✅ Push event only
-
Set secret in
.env:
GITHUB_WEBHOOK_SECRET=your-random-string
⚙️ Sync vs Queue Mode
| Mode | Description |
|---|---|
sync |
Runs deployment commands immediately in the HTTP request (for small projects or simple VPS) |
queue |
Dispatches a background job to the deploy queue (best for Docker, Horizon, supervisors) |
Set this in your .env:
DEPLOY_MODE=queue DEPLOY_QUEUE=deploy
Then, in supervisord or Docker, run:
php artisan queue:work --queue=deploy
✅ How It Works
- GitHub sends a webhook →
/github/webhook - Laravel verifies the HMAC signature
- Based on config mode:
sync: Runs the deploy shell commands right awayqueue: Dispatches a background job to thedeployqueue
- Commands are run in 3 phases:
pre_deploy_commandsdeploy_commandspost_deploy_commands
📚 Tips & Extensions
- Need
npm run build? Add it todeploy_commands - Want zero-downtime? Use
php artisan down/upinpre/post - Using Horizon? Just isolate
deployworkers separately
🔐 Security
- Verifies GitHub
X-Hub-Signature-256 - Jobs can self-check queue name (
EnsureDeployQueue) - Workers on wrong queues will back off with throttling
📋 Requirements
- PHP 8.1+
- Laravel 9.x → 12.x
- GitHub webhook support
- Docker (optional)
- Supervisor or Horizon (for queue mode)
💼 License
This package is open-sourced under the MIT license.
✨ Deployment Flow Example
GitHub Push →
Webhook triggered →
Dispatch Job →
Run:
git pull
composer install
docker-compose pull
docker-compose up -d
php artisan migrate
php artisan config:cache
php artisan route:cache
Fully automated. No manual SSH. No downtime.
🔥 Your deployments are now modern and effortless.
nassirian/laravel-github-deployer 适用场景与选型建议
nassirian/laravel-github-deployer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 04 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nassirian/laravel-github-deployer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nassirian/laravel-github-deployer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-27