在git post-receive之后改变所有权

use*_*868 3 git ownership githooks

我有以下设置:

两个用户:example和git

在里面,/home/git/repositories/project.git/hooks/post-receive我有一个结账/home/example/public_html/dev

因此,每次git推送,项目文件都会发布到http://dev.example.com

问题是,结帐是从git用户执行的,因此dev目录中的所有文件都归git:git所有,权限为600.

因此,访问http://dev.example.com将不会显示该页面.因为用户apache无法访问它.

有人建议在post-receive钩子里面做一个chown.那么,用户git需要是sudo.所以我添加了用户git作为sudoer.接下来的问题是" 对不起,你必须有一个tty来运行sudo "所以我评论#Default requiretty,但遇到下一个问题.

让用户git成为一个sudoer并不是我想要的(不安全)所以我把所有东西都改回了正常状态.

还有其他更安全的选择吗?

可能让post-receive hook触发dev文件夹里面的php文件,这个php文件会进行结账吗?

或者我可以通过apache kan在浏览器中显示它们的方式将dev文件夹符号链接到/ home/git中的文件夹吗?

use*_*868 6

解决了.

我的post-receive挂钩如下:

#!/bin/sh
echo "Deploying to http://dev.example.com"
GIT_WORK_TREE=/home/example/domains/example.com/public_html/dev git checkout -f
cd /home/example/domains/example.com/public_html/dev
find -type f -group 'git' -exec chmod 644 -R {} \;
find -type d -group 'git' -exec chmod 755 -R {} \;
Run Code Online (Sandbox Code Playgroud)

只要不存在可写目录,这将起作用.否则我必须将它们作为额外的chmod行添加到钩子脚本中