简体   繁体   English

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

[英]Git-based website deployment workflow

On my server, I have two users, www-data (which is used by nginx) and git . 在我的服务器上,我有两个用户, www-data (由nginx使用)和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). git用户拥有一个包含我网站代码的存储库,而www-data用户拥有该存储库的克隆(用作nginx的webroot)。 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. 我想建立一个工作流程,以便推送到git的存储库导致www-data的存储库更新,从而更新我的网站。

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)? 为这些存储库设置挂钩的正确方法是什么(这也考虑了这两个用户的权限和权限)?

删除www-data拥有的存储库,并按照此网页上的解决方案在git拥有的存储库中设置post-receive挂钩。

I ended up making the public content owned by the git user, and readable by all. 我最终制作了git用户拥有的公共内容,并且所有人都可读。 Then, I did the following to set up the hooks: 然后,我做了以下设置钩子:

Assuming the repository is called mysite : 假设存储库名为mysite

  1. Create a detached work tree that will act as the webroot (as the user git ) 创建一个分离的工作树,作为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 ignore 
  2. Add a post-receive hook that will update the website and set correct permissions for it 添加一个post-receive钩子,它将更新网站并为其设置正确的权限

     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/ 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. 注意:此howto的早期版本取决于将git配置变量core.worktree设置为目标目录,core.bare设置为false,并将receive.denycurrentbranch设置为忽略。 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. 但是,如果您使用GIT_WORK_TREE(在我第一次编写howto时无效),则不需要进行这些更改,并且远程存储库可以保持不变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM