0

I have a project that I push to a GitHub repository from my local machine. I deploy this project on a DigitalOcean droplet that I currently have to ssh into and do a git pull, then redeploy manually. Is there an easy way to have it auto pull, and then auto build and redploy itself? I have looked into git hooks but couldn't find any clear answers on what I am trying to do. I set up a post-update git hook on my remote machine which just echos a line but I don't know where to check if the line got echoed or not successfully.

1 Answers1

4

The place you'd need to run the Git hooks is on the server side, in the post-receive or post-update hook. However, GitHub doesn't allow you to run arbitrary hooks by default, since that would be a security risk. Instead, you can use GitHub's webhooks to trigger your droplet to perform some action by making a POST request to it.

You could also have some sort of continuous integration set up that would trigger and deploy a build to your droplet automatically. This is usually how this type of task is managed.

Finally, you can set up a remote name (say, foo) that has multiple remote.foo.url entries, one of which is GitHub, and one of which is your droplet. You can then push to both at the same time by using that remote, in which case your post-receive or post-update hook will trigger on the droplet (since it received the push). If there's a checkout, you can use receive.denyCurrentBranch=updateInstead, which will let you push to the same branch that's already checked out. See git-config(1) for more details.

bk2204
  • 64,793
  • 6
  • 84
  • 100