1

Currently, my production website is hosted on Azure. I use git and push all my commits to GitHub. With the magic of git hooks Azure has the ability to pull from GitHub when someone pushes a certain branch to GitHub.

How can I replicate this with my own staging server hosted on-premise? In other words, how can I set a repo on GitHub, and when I push to it, through git hooks send a signal, request or what-have-you to perform an automatic pull on my on-premise server?

I know Git is not a deployment software, but if I have to write a mechanism on my on-prmise server to make this happen I would like to know where to start. If it's helpful, we use Microsoft technology, so we are running our staging server on Windows Server, while our production is on Azure.

I understand that I'll need to use callback url on my server to then perform whatever is needed.I would like to know what methods people use to accomplish this. e.g.: on my call back url, how would I call a script to run a pull/fetch/clone bash command. or other method.

If you need more information, feel free to ask.

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
RoLYroLLs
  • 3,113
  • 4
  • 38
  • 57
  • 1
    In the simplest of terms, you would need to define/create a callback url on your end, which github would hit via a `git hook`. This call will inform your server that a push has been made to a certain branch on github. Now your server should ideally start a task which does the pull/fetch/clone for you, and deploy it. – Anshul Goyal Feb 12 '15 at 18:44
  • @mu無 Thanks for the quick reply. Yes that's how I figured it works. I guess I should elaborate my question to include what types of ways can my server pull/fetch/clone, since this is what's I'm least familiar with. Can I write a script, with enough permissions, to run a command on `git bash`? Or are there other ways? Thanks! – RoLYroLLs Feb 12 '15 at 18:49

1 Answers1

2

Expanding upon my comment,

  1. You would need to define/create a callback url on your end, which will need to be publicly accessible.

  2. github would make a hit to this url via a git hook whenever a push is made to the branch in question.

  3. You can add authentication for the hit in the hook, if needed.

  4. This call will inform your server that a push has been made to the certain branch on github.

  5. Now your server should start a deployment task which does the pull/clone.

Regarding this deployment task, there are many ways to do this, and the finer details will vary depending on how you do it.

One way would be to introduce a Continuous Integration tool like Jenkins in your stack, which you could also use for regular and test builds in different environments.

Another way could be to execute a simple bash script which does cd $REPO_DIR && git pull origin branchname && service apache2 etc restart.

Community
  • 1
  • 1
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
  • Awesome! I have heard of Jenkins but before exploring that I was hoping for something simpler without too much installation of other software or service costs. I'm liking the simple bash script you mention! I'll have to look up how to get this going. – RoLYroLLs Feb 12 '15 at 18:56
  • I don't use `apache` but what's the purpose of the `service apache2 etc restart` for. Just curious. :) – RoLYroLLs Feb 12 '15 at 19:02
  • @RoLYroLLs In case this was a webapp, apache would have continued running with the older copy of the code without a restart (because the processes would have been forked from an older copy of the code). A build tool like Jenkins would (in linux env) 1. create a fresh checkout of the release 2. Run any other custom configuration commands 3. create a soft link to this release as current 4. restart the web server for you. – Anshul Goyal Feb 12 '15 at 19:05
  • Cool thanks! May eventually run into this one day. I'll keep it in mind. Thanks again – RoLYroLLs Feb 12 '15 at 19:07