基于Git的网站部署工作流程
在我的服务器上,我有两个用户,www-data
(由 nginx 使用)和 git
。 git
用户拥有一个包含我网站代码的存储库,而 www-data
用户拥有该存储库的克隆(用作 nginx 的 webroot)。我想设置一个工作流程,以便推送到 git
的存储库会导致 www-data
的存储库更新,从而更新我的网站。
为这些存储库设置挂钩的正确方法是什么(还考虑这两个用户的特权和权限)?
On my server, I have two users, www-data
(which is used by nginx) and git
. The git
user owns a repository that contains my website's code, and the www-data
user owns a clone of that repository (which serves as the webroot for nginx). I want to set up a workflow such that pushing to git
's repository causes www-data
's repository to update, thus updating my website.
What is the correct way to set up the hooks for these repositories (that also takes into consideration privileges and permissions of these two users)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除
www-data
拥有的存储库,并按照此网页<上的解决方案操作/a> 用于在git
拥有的存储库中设置接收后挂钩。Remove the repository owned by
www-data
and follow the solution on this webpage for setting up a post-receive hook in the repository owned bygit
.我最终将公共内容设为 git 用户所有,并且所有人都可读。然后,我执行了以下操作来设置挂钩:
假设存储库名为
mysite
:创建一个独立的工作树,它将充当 webroot(作为用户
git
)代码>)添加一个 post-receive 挂钩,该挂钩将更新网站并设置正确的权限为了它
接收后脚本:
<前><代码>#!/bin/sh
git checkout -f git checkout -f
chmod -R o+rX /var/www/mysite
参考:
http://www.deanoj.co.uk/programming/git/using-git-and-a-post-receive-hook-script-for-auto-deployment/
更新:这是一个更好的解决方案。
I ended up making the public content owned by the
git
user, and readable by all. Then, I did the following to set up the hooks:Assuming the repository is called
mysite
:Create a detached work tree that will act as the webroot (as the user
git
)Add a post-receive hook that will update the website and set correct permissions for it
The post-receive script:
Reference:
http://www.deanoj.co.uk/programming/git/using-git-and-a-post-receive-hook-script-for-auto-deployment/
Update: Here is a better solution.