基于Git的网站部署工作流程

发布于 2024-10-26 16:18:14 字数 290 浏览 4 评论 0原文

在我的服务器上,我有两个用户,www-data(由 nginx 使用)和 gitgit 用户拥有一个包含我网站代码的存储库,而 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南渊 2024-11-02 16:18:16

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 by git.

蓝戈者 2024-11-02 16:18:16

我最终将公共内容设为 git 用户所有,并且所有人都可读。然后,我执行了以下操作来设置挂钩:

假设存储库名为 mysite

  1. 创建一个独立的工作树,它将充当 webroot(作为用户 git)代码>)

    mkdir /var/www/mysite
    cd /path/to/repository/mysite.git
    git config core.worktree /var/www/mysite
    git config core.bare false
    git config receive.denycurrentbranch 忽略
    
  2. 添加一个 post-receive 挂钩,该挂钩将更新网站并设置正确的权限为了它

    触摸挂钩/接收后
    chmod +x 挂钩/接收后
    vim 挂钩/接收后
    

    接收后脚本:

    <前><代码>#!/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/


更新:这是一个更好的解决方案

注意:本指南的早期版本依赖于将 git 配置变量 core.worktree 设置为目标目录,将 core.bare 设置为 false,将 receive.denycurrentbranch 设置为忽略。但是,如果您使用 GIT_WORK_TREE(当我第一次编写指南时它不起作用),则不需要这些更改,并且远程存储库可以保持裸露状态。

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:

  1. Create a detached work tree that will act as the webroot (as the user git)

    mkdir /var/www/mysite
    cd /path/to/repository/mysite.git
    git config core.worktree /var/www/mysite
    git config core.bare false
    git config receive.denycurrentbranch ignore
    
  2. Add a post-receive hook that will update the website and set correct permissions for it

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

    The post-receive script:

    #!/bin/sh
    git checkout -f
    chmod -R o+rX /var/www/mysite
    

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.

Note: earlier versions of this howto depended on setting the git config variables core.worktree to the target directory, core.bare to false, and receive.denycurrentbranch to ignore. But these changes are not needed if you use GIT_WORK_TREE (which didn't work when I first wrote the howto), and the remote repository can remain bare.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文