aerni / sync
一个类似于git的artisan命令,轻松在环境之间同步文件和文件夹
v1.5.0
2024-03-30 21:38 UTC
Requires
- php: ^8.2
- illuminate/support: ^11.0
- laravel/prompts: ^0.1.17
Requires (Dev)
- nunomaduro/collision: ^8.1
- orchestra/testbench: ^9.0
- phpunit/phpunit: ^10.0
README
Laravel Sync
此包提供了一种类似于git的artisan命令,可以轻松地在环境之间同步文件和文件夹。这对于资产、文档以及其他在您的git仓库中未跟踪的文件非常有用。
Laravel Sync是部署脚本的完美伴侣,无需手动跟踪环境中的文件和文件夹的日子已经过去了。为了自己好,试试看吧!
需求
rsync
在源和目标机器上- 在源和目标机器之间设置一个工作的
SSH
安装
使用Composer安装此包。
composer require aerni/sync
发布包的配置。
php artisan vendor:publish --provider="Aerni\Sync\SyncServiceProvider"
以下配置将发布到 config/sync.php
。
<?php return [ /* |-------------------------------------------------------------------------- | Remotes |-------------------------------------------------------------------------- | | Define on or more remotes you want to sync with. | Each remote is an array with 'user', 'host', 'root', and optional 'port'. | */ 'remotes' => [ // 'production' => [ // 'user' => 'forge', // 'host' => '104.26.3.113', // 'port' => 1431, // 'root' => '/home/forge/statamic.com', // 'read_only' => false, // ], ], /* |-------------------------------------------------------------------------- | Recipes |-------------------------------------------------------------------------- | | Define one or more recipes with the paths you want to sync. | Each recipe is an array of paths relative to your project's root. | */ 'recipes' => [ // 'assets' => ['storage/app/assets/', 'storage/app/img/'], ], /* |-------------------------------------------------------------------------- | Options |-------------------------------------------------------------------------- | | An array of default rsync options. | You can override these options when executing the command. | */ 'options' => [ '--archive', ], ];
配置
要使用此包,您必须定义至少一个远程和配方。
远程
每个远程包括一个 用户
、主机
和 根目录
。可选地,您还可以定义SSH 端口
并将远程设置为 只读
。
'remotes' => [ 'production' => [ 'user' => 'forge', 'host' => '104.26.3.113', 'port' => 1431, 'root' => '/home/forge/statamic.com', 'read_only' => env('SYNC_PRODUCTION', true), ], ],
如果想要防止从某个环境推送到一个远程,例如从本地环境推送到一个 生产
环境,只读
选项就很有用。
配方
添加任何数量的配方,包括您想要同步的路径。每个配方都是相对于项目根目录的路径数组。
'recipes' => [ 'assets' => ['storage/app/assets/', 'storage/app/img/'], 'env' => ['.env'], ],
选项
配置在执行同步时使用的默认rsync选项。您可以在执行命令时覆盖这些选项。
'options' => [ '--archive', ],
命令
如果您了解git,您会对这个命令的语法感到很熟悉
php artisan [command] [operation] [remote] [recipe] [options]
命令结构
命令的结构如下所示
可用命令
您有三个命令可以使用
可用选项
您可以使用以下选项
使用示例
从预发布远程拉取资产配方
php artisan sync pull staging assets
使用一些自定义rsync选项将资产配方推送到生产远程
php artisan sync push production assets --option=-avh --option=--delete
执行测试运行
php artisan sync pull staging assets --dry
在您的终端中实时输出同步输出
php artisan sync pull staging assets --verbose
以表格形式列出原始、目标、选项和端口
php artisan sync:list pull staging assets
列出所有rsync命令
php artisan sync:commands pull staging assets