muxx/dplr
Composer 安装命令:
composer require muxx/dplr
包简介
Object oriented deployer based on GoSSHa
README 文档
README
Object oriented deployer based on GoSSHa which allows to execute tasks simultaneously and in parallel. Simple and fast.
Usage
Example of usage:
require 'vendor/autoload.php'; $dplr = new Dplr\Dplr('ssh-user', '/path/to/GoSSHa'); $dplr ->addServer('front1.site.ru', 'front') ->addServer('front2.site.ru', 'front') ->addServer('job1.site.ru', ['job', 'master']) ->addServer('job2.site.ru', 'job') ; const PATH = '/home/webmaster/product'; $dplr ->upload('/path/to/local_file1', '/path/to/remote_file1', 'front') ->command(PATH . '/app/console cache:clear') ; $dplr->run(function($step) { echo $step; }); if (!$dplr->isSuccessful()) { echo "Deploy completed with errors.\n"; foreach($dplr->getFailed() as $item) { echo "[ " . $item . " ]\n" . $item->getErrorOutput() . "\n"; } } else { echo "Deploy completed successfully.\n"; } $report = $dplr->getReport(); echo sprintf( "Tasks: %s total, %s successful, %s failed.\nTime of execution: %s\n", $report['total'], $report['successful'], $report['failed'], $report['timers']['execution'] );
Installation
Use composer to install dplr:
"require": {
"muxx/dplr": "~1.0"
}
Important: dplr requires GoSSHa.
Documentation
Initialization
Initialization of ssh authorization by key:
$dplr = new Dplr\Dplr('ssh-user', '/path/to/GoSSHa'); // or $dplr = new Dplr\Dplr('ssh-user', '/path/to/GoSSHa', '/path/to/public.key');
Register servers
Add multiply servers with adding in different group. Adding to groups allows you to execute tasks on servers of certain group.
$dplr->addServer('1.2.3.4'); // Add server IP 1.2.3.4 without adding to group $dplr->addServer('1.2.3.5', 'app'); // Add server IP 1.2.3.5 with adding to group 'app' $dplr->addServer('1.2.3.6', ['app', 'cache']); // Add server IP 1.2.3.6 with adding to groups 'app' and 'cache' $dplr->addServer('1.2.3.7:2222', ['cache']); // Add server IP 1.2.3.7 and ssh port 2222 with adding to group 'cache'
Register tasks
dplr allows to register two types of tasks:
- Command executing
- Upload local file to remote server
$local = __DIR__; $path = '/home/webmaster/project'; $dplr ->upload("$local/share/parameters.yml", "$path/app/config/parameters.yml") ->command("cd $path && ./app/console cache:clear --env=prod --no-debug", 'app', 15) ;
In example above file parameters.yml will be uploaded on all servers simultaneously and in parallel. Second task executes only on servers from group app (1.2.3.5 and 1.2.3.6) in parallel. For second task defined execution timeouts (15 seconds).
Sometimes you have to execute different tasks in parallel. For this case Dplr has multithread mode.
$dplr ->command('app build') ->multi() ->command('app init --mode=job', 'job') ->command('app init --mode=app', 'front') ->end() ->command('app run', 'front') ;
In example above command app build will be executed on all servers. After that commands app init --mode=job and app init --mode=app will be executed on the servers of groups job and front in parallel. At the end command app run will be executed on the servers of group front.
Running
Running is simple:
$dplr->run();
Define callback if you want to show steps of execution:
$dplr->run(function($step) { echo $step; }); /* Output -- CPY /home/webmaster/test/share/parameters.yml -> /home/webmaster/project/app/config/parameters.yml ..T. CMD cd /home/webmaster/project && ./app/console doctrine:migration:migrate --env=prod --no-debug .E */
Each dot at the end of task lines means executing of the one action (upload, command) on the certain server. Mark E is indicator of failed executing. Mark J is indicator of json parsing error. Mark T is indicator of executing timeout.
Result processing
You can get the execution review or detail information about each task execution.
Display report:
$report = $dplr->getReport(); echo sprintf( "Tasks: %s total, %s successful, %s failed.\nTime of execution: %s\n", $report['total'], $report['successful'], $report['failed'], $report['timers']['execution'] ); /* Output -- Tasks: 163 total, 163 successful, 0 failed. Time of execution: 08:25 */
Detail information about each task:
foreach($dplr->getReports() as $report) { echo sprintf( "%s\n Successful: %s\n", (string) $report, $report->isSuccessful() ? 'true' : 'false' ); } /* Output -- CPY /home/webmaster/test/share/parameters.yml -> /home/webmaster/project/app/config/parameters.yml | 54.194.27.92 Successful: false CMD cd /home/webmaster/project && ./app/console doctrine:migration:migrate --env=prod --no-debug | 54.194.27.92 Successful: true */
Each element in arrays returned by $dplr->getFailed() and $dplr->getReports() is instance of Dplr\TaskReport and has methods:
isSuccessful()- task executing is successfulgetHost()- server where task executedgetTask()- information about task (instance ofDplr\Task)getOutput()- output of taskgetErrorOutput()- output of error task
Tests
Execute the commands below to run the tests.
make sshkeygen docker-compose up -d make composer make check
muxx/dplr 适用场景与选型建议
muxx/dplr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.21k 次下载、GitHub Stars 达 47, 最近一次更新时间为 2014 年 02 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 muxx/dplr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 muxx/dplr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 5.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 47
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-02-11