Automated Deployment Using Git

I am wondering if anyone has a better strategy for this scenario.

I currently have my own remote git repository in the same field as the web server.

All git repositories are under the git user.

sudo -uwww-data -gwww-data git --git-dir=/var/www/website/.git --work-tree=/var/www/website pull 

I have a cron job running as root every minute that runs this command. The git repository in the web folder is cloned from the same field to git home dir, where it is stored instead of ssh.

So my question is: since git does not own web files, it cannot move the site using git hook. I would suggest that I don't want git to have sudo, and that doesn't work with git hook, right? Is there something that will deploy the site faster than every minute? I do not want the operation to be very expensive.

Can some root of the daemon run and listen to some kind of notification? How to view the file last modified time?

+4
source share
2 answers

Please note that this article (in French, translated through Google) reports that sudo works with your approach:

change sudo so that gitosis user uses this command as www-data .
To do this, run "visudo" and add the line:

 git ALL = (www-data) NOPASSWD: /usr/local/bin/pullhere 

Then in each repository, where necessary, add the following hook to the post-receive file:

 sudo -u www-data /usr/local/bin/pullhere /html/u/user/here 

e.g. in / home/git/repositories/projet1.git/hooks/post-receive

+1
source

This may be of interest to you if you are still looking at a way to automatically deploy after pressing git:

https://github.com/JamesBrooks/git-runner (with git-runner-deploy gem).

0
source

Source: https://habr.com/ru/post/1393702/


All Articles