使用Gitolite自动部署PHP脚本 [英] Auto deployment PHP script using Gitolite

查看:121
本文介绍了使用Gitolite自动部署PHP脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在本地设置自动部署脚本到我的测试服务器。

我在Ubuntu桌面11.04上使用gitolite。
i使用apt-get安装gitolite安装gitolite,所以它是创建用户gitolite和组gitolite。
现在我安装我的测试webserver使用apache有用户和组ivan:ivan,

,并在该用户名下执行git clone。

因此所有文件和文件夹都具有相同的文件所有者ivan:ivan。

我在/ var / lib / gitolite / repository / testrepo / hooks /下设置post-receive钩子,并且在里面有这个脚本:

 #!/ bin / bash 
#CONFIG
LIVE =/ home / ivan / public_html / testrepo

读取oldrev newrev refname
if [$ refname =refs / heads / master];然后
echo=====部署到测试站点=====
unset GIT_DIR
cd $ LIVE
git pull原点大师:
echo ===== DONE =====
fi

自收到后钩子由gitolite用户执行,它有访问正在使用用户ivan的测试服务器的权限问题。

我已将gitolite添加到ivan组,并使其成为组访问写入,但仍无法运行。

i知道这是一个权限问题,但我不知道解决方案。

如果您有相同的经验或有任何提示,我会非常感激。



感谢

Ivan

解决方案

I终于得到了我自己的解决方案,感谢VonC的指针。

我的解决方案可能并不美观,但仍然有效。



因此,以下是我解决方案中的步骤:


  1. 我创建了一个裸露的存储库,它将与Web应用程序具有相同的用户权限。在Gitolite Repositories文件夹(在Ubuntu:/ var / lib / gitolite / repositories)中,我创建了一个post-receive钩子,它将镜像存储库我刚刚创建的裸回购。代码是:

    #!/ bin / bash

    echo'==== DO MIRROR ===='

    git push --mirror user @ host:path / to / bare.git

    echo'==== DONE MIRROR ===='
    在我的web应用程序中,我将创建一个连接到裸露回购的远程设备。然后,我在镜像裸回购中创建一个post-receive钩子,它会要求Web应用程序从中取出。代码:

    #!/ bin / bash

    WORK_DIR =/ home / ivan / public_html / test / testing

    read oldrev newrev refname

    if [$ refname =refs / heads / master];然后

    echo=====部署到现场=====

    未设置GIT_DIR

    cd $ WORK_DIR

    git pull mirror-repo master

    echo===== DONE =====

    fi


  2. 不要忘记chmod + x都是post-receive。


正如我之前说过的那样,它可能并不美观,但至少对我目前的情况起作用。我之所以不把它从gitolite存储库中提取,是因为用户文件的权限。在Ubuntu中(从apt-get安装),gitolite持有用户和组,gitolite:gitolite。和我的Web应用程序在我的家庭文件夹(我使用suPHP)下有用户和组ivan:ivan。
因此,当我推送到gitolite存储库时,它将运行gitolite用户下的bash脚本,该用户无法访问我的主文件夹下的.git文件夹。



所以是的,对于那些有更好解决方案的人,我非常希望收到您的消息。

感谢希望我的解决方案可以帮助其他人。 br>
Ivan


i would like to setup auto deployment script to my testing server locally.
i'm using gitolite on ubuntu desktop 11.04. i install gitolite using apt-get install gitolite, so it is create user gitolite and group gitolite.
Now i setup my testing webserver using apache which has user and group ivan:ivan,
and do git clone under that username.
so all the files and folder have the same file owner ivan:ivan.

i setup post-receive hooks under /var/lib/gitolite/repository/testrepo/hooks/ and have this script inside:

#!/bin/bash
#CONFIG
LIVE="/home/ivan/public_html/testrepo"

read oldrev newrev refname
if [ $refname = "refs/heads/master" ]; then
  echo "===== DEPLOYING TO TEST SITE ====="
  unset GIT_DIR
  cd $LIVE
  git pull origin master:
  echo "===== DONE ====="
fi  

Since post-receive hooks is executed by gitolite user, it has permission problem to access to the test server which is using user ivan.

i already add gitolite to ivan group and make it group access write, but still it cannot run.
i know this is a permission problem, but i don't know the solution.
If you have same experience or got any tips, i would really appreciate it.

Thanks
Ivan

解决方案

I finally got the solution on my own, thanks for VonC for the pointers.
My solution may not beauty but yet work.

So here are the steps that work in my solution:

  1. I create a bare repositories which will have the same user permission with the web application.

  2. In Gitolite Repositories folder (in Ubuntu: /var/lib/gitolite/repositories), i create a post-receive hook which will mirror the the repository the bare repo that i just created. Code is:

    #!/bin/bash
    echo '==== DO MIRROR ===='
    git push --mirror user@host:path/to/bare.git
    echo '==== DONE MIRROR ===='

  3. And in my web application, i will create a remote that connect to that bare repo.

  4. Then i create a post-receive hook in the mirrored bare repo, that will ask the web application to pull from it. The code:

    #!/bin/bash
    WORK_DIR="/home/ivan/public_html/test/testing"
    read oldrev newrev refname
    if [ $refname = "refs/heads/master" ]; then
    echo "===== DEPLOYING TO LIVE SITE ====="
    unset GIT_DIR
    cd $WORK_DIR
    git pull mirror-repo master
    echo "===== DONE ====="
    fi

  5. Don't forget to chmod +x for both post-receive.

As i said before, it may not beautiful but yet work, at least for my current situation. The reason why i'm not just pull it from the gitolite repositories is because of user file permissions. In Ubuntu (install from apt-get), gitolite hold user and group, gitolite:gitolite. and my web application is under my home folder (i'm using suPHP) which have user and group ivan:ivan. So when i pushed to the gitolite repositories, it will run the bash script under gitolite user, which cannot access the .git folder under my home folder.

So yes, for those who have better solutions, i'm eager to hear from you.
Thanks hope my solution may help others.
Ivan

这篇关于使用Gitolite自动部署PHP脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆