使用Git部署站点:更新后的挂钩工作第一次,然后再也不会 [英] Deploying site with Git: post-update hook works first time, then never again

查看:106
本文介绍了使用Git部署站点:更新后的挂钩工作第一次,然后再也不会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个奇怪的问题与git后更新钩子。我在我的服务器上创建了存储库( /var/www/vhosts/git/master.git ),在这个存储库中添加了一个包含以下代码的更新后挂接: p>

 #!/ bin / sh 

echo $ 1
echo* UPDATE *


*'refs / heads / master'*中的$ 1
GIT_WORK_TREE = / var / www / vhosts / website.com / sandbox.website.com git checkout - f
echo
echoMaster was updated!
echo
;;
esac


*'refs / heads / sandbox'*中的$ 1$)
GIT_WORK_TREE = / var / www / vhosts / website.com / sandbox .website.com git checkout -f
echo
echo沙盒已更新!
echo
;;
esac

我确保这个文件是可执行的。然后我在我的机器上创建了一个本地存储库:

  $ mkdir website&& cd网站
$ git init
$ echo'Testing。'> index.html
$ git add index.html
$ git commit -q -m初始提交
$ git remote add web ssh://username@website.com/var/www /vhosts/website.com/git/master.git
$ git push web + master:refs / heads / master

无论什么原因,第一次推送工作正常 - /var/www/vhosts/website.com/sandbox.website.com 更新为索引文件 - 但是以下任何一个都不起作用。我从更新后的钩子中获得响应,表示主人已更新!但是目录实际上没有被更新。



建议?

解决方案

你似乎有一个权限问题。请查看 / var / www / * 路径上的权限,并确保您的git用户有权读取/写入/删除文件。



我使用了很多更简单的技术(这里是一个详细的脚本),允许我将我的服务器用作gitite的git服务器,并在push上部署,而无需克隆 / var / www / myproject 路径。在 git 1.7.9 Ubuntu 12.04.1 LTS Apache /2.2.22


  1. 在服务器上创建您的rpository:

      mkdir myproject.git&& cd myproject.git 
    git init --bare


  2. 配置存储库: / p>

      git config core.worktree / var / www / myproject 
    git config core.bare false
    git config receive.denycurrentbranch忽略


  3. 编辑或创建接收并使其运行

     触摸挂钩/后接收
    chmod u + x钩子/后接收


这是文件内容:

 #!/ bin / sh 
git checkout -f

您已准备好进行推送并使其正常工作。



我的git用户被称为 git ,我的apache使用 ubuntu 用户。我必须在 /etc/apache2/conf.d/security (你可以在 / etc / apache2 / http)上编辑apache配置。 conf 还)包括:

 用户git 
组git

现在我的 / var / www / myproject 部署所有文件推送,使用 git:git user / group创建文件,我的apache使用相同的用户/组来运行。



现在你只需重新启动服务器,或者执行 service apache2 restart


Having a strange issue with a git post-update hook. I created repository on my server (/var/www/vhosts/git/master.git) and in this repository added a post-update hook with the following code:

#!/bin/sh

echo $1
echo "*UPDATE*"

case " $1 " in
*'refs/heads/master'*)
    GIT_WORK_TREE=/var/www/vhosts/website.com/sandbox.website.com git checkout -f
    echo
    echo "Master was updated!"
    echo
    ;;
esac

case " $1 " in
*'refs/heads/sandbox'*)
GIT_WORK_TREE=/var/www/vhosts/website.com/sandbox.website.com git checkout -f
    echo
    echo "Sandbox was updated!"
    echo
    ;;
esac

I made sure this file is executable. Then I created a local repository on my machine using:

$ mkdir website && cd website
$ git init
$ echo 'Testing.' > index.html
$ git add index.html
$ git commit -q -m "Initial commit"
$ git remote add web ssh://username@website.com/var/www/vhosts/website.com/git/master.git
$ git push web +master:refs/heads/master

For whatever reason that first push works just fine—/var/www/vhosts/website.com/sandbox.website.com gets updated with the index file—but then none of the following pushes work. I get the response back from the post-update hook that says "Master was updated!" but the directory doesn't actually get updated.

Suggestions?

解决方案

You seem to have have a permission issue. Take a look on the permissions on the/var/www/* path and ensure that your git user has permission to read/write/delete on the files.

I have used a much simpler technique (here is a detailed script) that allowed me to use my server as git server with gitolite and deploy on push without having to clone the repository on the /var/www/myproject path. It is working for me on git 1.7.9 and Ubuntu 12.04.1 LTS with Apache/2.2.22.

  1. Create your rpository on the server:

    mkdir myproject.git && cd myproject.git
    git init --bare
    

  2. Configure the repository:

    git config core.worktree /var/www/myproject
    git config core.bare false
    git config receive.denycurrentbranch ignore
    

  3. Edit or create the hooks/post-receive and make it runnable

    touch hooks/post-receive
    chmod u+x hooks/post-receive
    

Here is the file content:

#!/bin/sh
git checkout -f

You are ready to do a push and have it working.

My git user is called git and my apache used the ubuntu user. I had to edit the apache configuration on /etc/apache2/conf.d/security (you can do it on /etc/apache2/http.conf also) to include:

User git
Group git

Now my /var/www/myproject deploys all the files on push, creating the files with git:git user/group and my apache uses the same user/group to run.

Now you just have to restart your server or do a service apache2 restart

这篇关于使用Git部署站点:更新后的挂钩工作第一次,然后再也不会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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