Git website deployment workflow

On my server, I have two users, www-data (which is used by nginx) and git . The git user owns the repository containing the code for my site, and the www-data user owns a clone of this repository (which serves as the website for nginx). I want to configure the workflow in such a way that clicking on the git repository causes the www-data repository to update, thereby updating my website.

What is the correct way to configure sniffers for these repositories (which also takes into account the privileges and permissions of these two users)?

+7
source share
2 answers

Delete the repository owned by www-data and follow the solution on this web page to create the hook after getting to the repository owned by git .

+5
source

I created public content owned by the git user and readable by everyone. Then I did the following to set up the hooks:

Assuming the repository is called mysite :

  • Create a separate work tree that will act as a webroot (as a git user)

     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 
  • Add a post-receive hook that will update the website and set the correct permissions for it

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

    Post-Accept 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 the best solution .

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

+2
source

All Articles