1

I found this question which tells how to create a git hook to automatically pull updates to a folder Automatic git pull on server

Basically, it says to add a php file to the folder, then the hook will do an http request to execute the script.

My problem is that I am updating python scripts that are not in the /var/www folder, but rather in the /usr folder.

I don't want these files accessible via the web, so is there a way to execute a git pull request on a remote server for a folder outside /var/www?

Community
  • 1
  • 1
pekasus
  • 626
  • 2
  • 7
  • 20
  • The linked answer saying to install a PHP script is just implementing a cheap way to run `git pull` without explicitly logging in to the server, and specifically requires your project to be hosted on GitHub, and deployed on a web server with PHP. The hook part is specific to GitHub, not to `git` itself. – tripleee Mar 23 '16 at 08:36
  • Possible duplicate of [How can I automatically deploy my app after a git push ( GitHub and node.js)?](http://stackoverflow.com/questions/9132144/how-can-i-automatically-deploy-my-app-after-a-git-push-github-and-node-js) – tripleee Mar 23 '16 at 08:44
  • 1
    Probably a better duplicate: http://stackoverflow.com/questions/279169/deploy-a-project-using-git-push – tripleee Mar 23 '16 at 08:45
  • @tripleee that answer looks about right. I wasn't aware that you could use user@server:filename to execute a file from an http request. I am using gitlab, so I will try it and see. – pekasus Mar 23 '16 at 12:55

1 Answers1

1

You can put your bare repo (which includes your hook) anywhere you want.

Then the hook can execute a script again placed anywhere you want.

None of those two elements needs to be in /var/www.


The idea is:

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I have the hook in the folder, but I have to do an http request to access the php file that will execute the file. – pekasus Mar 23 '16 at 12:56
  • @pekasus why not have a local copy of that php file? – VonC Mar 23 '16 at 13:00
  • You mean in the folder on the remote server? Thats where I have it. Would it work if I put the php script in the www folder, then add the full path to the bash script? – pekasus Mar 23 '16 at 13:03
  • @pekasus I mean when the hook is trigger, it should execute a script which is on the same server as the hook. – VonC Mar 23 '16 at 13:05
  • I don't understand how that would work. I have to execute the git pull on the remote server. I am using gitlab if that changes anything. Could I place the script on gitlab and have that execute a git pull on the remote server? – pekasus Mar 23 '16 at 13:08
  • @pekasus on gitlab, you declare your project webhook (http://stackoverflow.com/a/18901502/6309) The script listening to the JSON payload is on your remote server, and it can execute the git pull. – VonC Mar 23 '16 at 13:29
  • Got it. I'll give that a shot. If you put that in the answer, I'll accept it. Thanks! – pekasus Mar 23 '16 at 13:42