通过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
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章
刺客信條陰影:貝殼謎語解決方案
1 個月前
By DDD
Windows 11 KB5054979中的新功能以及如何解決更新問題
3 週前
By DDD
在哪裡可以找到原子中的起重機控制鑰匙卡
1 個月前
By DDD
如何修復KB5055523無法在Windows 11中安裝?
2 週前
By DDD
Inzoi:如何申請學校和大學
3 週前
By DDD

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

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

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)