git提交代码后,自动更新指定的部署目录
发布时间:2016-05-10 16:17:37 来源:51推一把
【摘要】原理:在部署站点目录下,写一个php可执行文件,待git提交时,通过设置中Web Hooks配置,来触发执行文件,达到自动同步发布的效果。
原理:在部署站点目录下,写一个php可执行文件,待git提交时,通过设置中Web Hooks配置,来触发执行文件,达到自动同步发布的效果。
Web hooks
http://10.10.10.10/hook_test.php
hook_test.php:
<?php
define("ROOT_PATH","/home/web/");
if (is_dir(ROOT_PATH.www.test.com))
{
system("rm -rf /home/web/www.test.com");
}
system("cd ".ROOT_PATH." && git clone git@code.xxxx.com:xxxxx/www.test.com.git");
system("cd /home/web/www.test.com && git checkout master"); //master分支
system("chmod -R 777 /home/web/www.test.com");
/**
define("ROOT_PATH",/home/web/www.test.com/);
if (!file_exists(ROOT_PATH))
{
system("cd ".ROOT_PATH." && git clone git@code.xxxx.com:xxxxx/www.test.com.git");
}
error_log("cd ".ROOT_PATH." && git pull\r\n",3,"/home/web/webhooks/post_error.log");
system("cd ".ROOT_PATH." && git pull");
*/
Web hooks
http://10.10.10.10/hook_test.php
hook_test.php:
<?php
define("ROOT_PATH","/home/web/");
if (is_dir(ROOT_PATH.www.test.com))
{
system("rm -rf /home/web/www.test.com");
}
system("cd ".ROOT_PATH." && git clone git@code.xxxx.com:xxxxx/www.test.com.git");
system("cd /home/web/www.test.com && git checkout master"); //master分支
system("chmod -R 777 /home/web/www.test.com");
/**
define("ROOT_PATH",/home/web/www.test.com/);
if (!file_exists(ROOT_PATH))
{
system("cd ".ROOT_PATH." && git clone git@code.xxxx.com:xxxxx/www.test.com.git");
}
error_log("cd ".ROOT_PATH." && git pull\r\n",3,"/home/web/webhooks/post_error.log");
system("cd ".ROOT_PATH." && git pull");
*/