通过git@osc的push钩子实现自动部署
为了解决自动部署问题,查询了一些解决方案后,为了稳定最终决定使用Git@OSC来实现该需求。
deploy.php
<?php header("Content-type: text/html; charset=utf-8"); if (! isset($_REQUEST['hook'])) die ('非法请求'); $config = require('config.php'); //hook内容详见http://git.oschina.net/oschina/git-osc/wikis/HOOK%E9%92%A9%E5%AD%90 $hook = json_decode($_REQUEST["hook"], true); //$hook = json_decode(file_get_contents('request.json'), true); $project = $hook['push_data']['repository']['name']; //判断密码 if ($hook['password'] != $config['projects'][$project]['password']) die ("密码错误"); //判断branch if (trim(strrchr($hook['push_data']['ref'], '/'), '/') != $config['projects'][$project]['branch']) die ("非自动部署分支"); $shell = <<<EOF WEB_PATH='{$config['projects'][$hook['push_data']['repository']['name']]['web_path']}' WEB_USER='{$config['web_user']}' WEB_GROUP='{$config['web_group']}' echo "Start deployment" cd \$WEB_PATH echo "pulling source code..." git reset --hard origin/master git clean -f git pull git checkout master echo "changing permissions..." chown -R \$WEB_USER:\$WEB_GROUP \$WEB_PATH echo "Finished." EOF; file_put_contents('deploy.sh', $shell); $res = shell_exec("bash deploy.sh"); $log_file = "{$project}.log"; foreach ($hook['push_data']['commits'] as $commit) { file_put_contents($log_file, "※" . date('Y-m-d H:i:s') . "\t" . $hook['push_data']['repository']['name'] . "\t" . $commit['message'] . "\t" . $commit['author']['name'] . PHP_EOL, FILE_APPEND ); } file_put_contents($log_file, $res . PHP_EOL, FILE_APPEND);
登录后复制
config.php
<?php return [ 'web_user' => 'www', 'web_group' => 'www', 'projects' => [ 'project' => [ 'password' => 'password', 'web_path' => '/home/wwwroot/default/project', ], ] ];
登录后复制
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章
刺客信条阴影:贝壳谜语解决方案
3 周前
By DDD
Windows 11 KB5054979中的新功能以及如何解决更新问题
2 周前
By DDD
在哪里可以找到原子中的起重机控制钥匙卡
3 周前
By DDD
刺客信条阴影 - 如何找到铁匠,解锁武器和装甲定制
1 个月前
By DDD
<🎜>:死铁路 - 如何完成所有挑战
3 周前
By DDD

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)
