jafarakhondali / laravel-hooker-gitlab
Laravel 的简单 GitHub 和 GitLab Webhook 部署器
Requires
This package is not auto-updated.
Last update: 2020-01-28 06:32:55 UTC
README
git-deploy-laravel 通过接收从您的仓库服务器推送的事件消息来自动拉取项目代码来协助部署。
它应该与 Laravel 5.x 一同使用 GitHub 和 GitLab 服务器提供的 Webhook 无缝工作。
这是一个内部工具,用于帮助我们常见的 workflow 模式,但请随意借用、修改和改进。
安装
步骤 1
将以下内容添加到您的 composer.json
文件中,然后像往常一样更新 composer
{
"require" : {
"jafarakhondali/git-deploy-laravel" : "dev-master"
}
}
或者运行
composer require jafarakhondali/git-deploy-laravel
步骤 2
将以下行添加到您的 config/app.php
文件中的 providers 部分
jafarakhondali\GitDeploy\GitDeployServiceProvider::class,
**Laravel 5.5 新特性 - 不需要以上更改即可自动检测服务提供者**
步骤 3
将 /git-deploy 路由添加到 CSRF 异常中,以便您的仓库主机可以发送消息到您的项目。
在 app/Http/Middleware/VerifyCsrfToken.php
文件中添加以下内容:
protected $except = [
'git-deploy',
];
使用方法
在 GitHub/GitLab 项目的 http://your.website.url/git-deploy 上添加一个 webhook,这个软件包将处理其余部分。webhook 应该在 push 事件上触发。
您的网站将自动接收来自仓库管理器的 POST 消息并执行 Git pull。
配置
在大多数情况下,软件包将找到正确的 Git 仓库和 Git 可执行文件,但我们仍建议发布我们的配置,因为这将允许您启用额外的安全选项和电子邮件通知。
要添加自定义配置,请运行
php artisan vendor:publish --provider="jafarakhondali\GitDeploy\GitDeployServiceProvider"
然后编辑 /config/gitdeploy.php
以满足您的需求。
<?php return [ /* |-------------------------------------------------------------------------- | Email recipients |-------------------------------------------------------------------------- | | The email address and name that notification emails will be sent to. | Leave the array empty to disable emails. | | [ | ['name' => 'Joe Bloggs', 'address' => 'email@example1.com'], | ['name' => 'Jane Doe', 'address' => 'email@example2.com'], | ... | ] | */ 'email_recipients' => [], /* |-------------------------------------------------------------------------- | Email sender |-------------------------------------------------------------------------- | | The email address and name that notification emails will be sent from. | This will default to the sender in config(mail.from) if left null. | */ 'email_sender' => ['address' => null, 'name' => null], /* |-------------------------------------------------------------------------- | Repository path |-------------------------------------------------------------------------- | | This the root path of the Git repository that will be pulled. If this | is left empty the script will try to determine the directory itself | but looking for the project's .env file it's nearby .git directory. | | No trailing slash | */ 'repo_path' => '', /* |-------------------------------------------------------------------------- | Allowed sources |-------------------------------------------------------------------------- | | A request will be ignored unless it comes from an IP listed in this | array. Leave the array empty to allow all sources. | | This is useful for a little extra security if you run your own Git | repo server. | | Relies on the REMOTE_ADDR of the connecting client matching a value | in the array below. So if using IPv6 on both the server and the | notifing git server, then make sure to add it to the array. If your git | server listens on IPv4 and IPv6 it would be safest to add both. | | e.g. | | 'allowed_sources' => ['192.160.0.1', '::1'], | */ 'allowed_sources' => [], /* |-------------------------------------------------------------------------- | Remote name |-------------------------------------------------------------------------- | | The name of the remote repository to pull the changes from | */ 'remote' => 'origin', /* |-------------------------------------------------------------------------- | Git binary path |-------------------------------------------------------------------------- | | The full path to the system git binary. e.g. /usr/bin/git | | Leave blank to let the system detect using the current PATH variable | */ 'git_path' => '', /* |-------------------------------------------------------------------------- | Maintenance mode |-------------------------------------------------------------------------- | | Allow the git hook to put the site into maintenance mode before doing | the pull from the remote server. | | After a successful pull the site will be switched back to normal | operations. This does leave a possibility of the site remaining in | maintenance mode should an error occur during the pull. | */ 'maintenance_mode' => true, /* |-------------------------------------------------------------------------- | Secret signature |-------------------------------------------------------------------------- | | Allow webhook requests to be signed with a secret signature. | | If 'secret' is set to true, Gitdeploy will deny requests where the | signature does not match. If set to false it will ignore any signature | headers it recieves. | | For Gitlab servers, you probably want the settings below: | | 'secret_type' => 'plain', | 'secret_header' => 'X-Gitlab-Token', | | For Github, use something like the below (untested): | | 'secret_type' => 'hmac', | 'secret_header' => 'X-Hub-Signature', */ 'secret' => false, /** * plain|hmac */ 'secret_type' => 'plain', /** * X-Gitlab-Token|X-Hub-Signature */ 'secret_header' => 'X-Gitlab-Token', /** * The key you specified in the pushing client */ 'secret_key' => '', ];
未来计划
- 在拉取时阻止的代码冲突的电子邮件报告
- 在部署后执行
composer install
- 在部署后使用
artisan queue:restart
重新启动 Laravel 队列 - 在成功拉取后运行自定义 artisan 命令