为了解决自动部署问题,查询了一些解决方案后,为了稳定最终决定使用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
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章
刺客信條陰影:貝殼謎語解決方案
4 週前ByDDD
Windows 11 KB5054979中的新功能以及如何解決更新問題
3 週前ByDDD
在哪裡可以找到原子中的起重機控制鑰匙卡
4 週前ByDDD
<🎜>:死鐵路 - 如何完成所有挑戰
1 個月前ByDDD
Atomfall指南:項目位置,任務指南和技巧
1 個月前ByDDD

熱工具

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

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

SublimeText3 Linux新版
SublimeText3 Linux最新版

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。