One command deployments to IIS using Git

Necessity is the mother of invention. And Frank Zappa is the father.

One of our clients has a Windows web server at Rackspace behind a VPN as their test environment. Every time the client asked for an image to be moved 5px to the right, my designer would push to GitLab, and I would have to establish VPN, remote into the web server, and do a pull in the local repo in IIS. A time consuming, and given the number of client requests, maddening process.

So I thought, it would be great to just push to IIS from our local repositories. Here’s how to do it.

    1. Install Git and the bash tools for Windows
    2. Install the Bonobo prerequisites, if necessary. Note: Bonobo requires .NET 4.5
    3. Install Bonobo
    4. Allow the IIS user to modify your deployment folder in IIS, just like you did for the App_Data folder in the Bonobo install
    5. Create a new repo in Bonobo. I’ll call it “myrepo”.
    6. Navigate to the myrepo’s Details page and note the URL. It will likely be http://localhost/Bonobo.Git.Server/myrepo.git
    7. Set the remote in your local repo to the one you just created. You’ll want to switch out localhost for the IP of your server.
    8. Back on the web server, navigate to the hooks folder in your repo using Git Bash. Found at: C:\inetpub\wwwroot\Bonobo.Git.Server\App_Data\Repositories\myrepo\hooks
    9. In Git Bash, enter “touch post-receive” and then “chmod +x post-receive”
    10. Open post-receive and add the following text. I usually just do this in a text editor like Notepad++.
echo -e "[log] Received push request at $( date +%F)" >> $LOGFILE
 echo "[log] Starting Deploy..." >> $LOGFILE
 GIT_WORK_TREE="$DEPLOYDIR" git checkout -f
 echo "[log] Finished Deploy" >> $LOGFILE

11. The DEPLOYDIR variable should be the path (formatted like above) to your deployment folder from step 4. This script will also create a handy log file in your repository folder

12. Push some changes from your local repo, and you should you see them out on your site


2 thoughts on “One command deployments to IIS using Git”

  1. Great tutorial. Not used to setting these up on Windows so the permissions step was helpful for me. I know this is an old post, but what would be the best way to automate this so that creating a new repository would just create a hooked directory to deploy to with the same name as the repository? Be great if Bonobo had this built in..

    1. Thanks, glad the post helped you. Regarding automating the hooked directory, I think you’d probably have to write a script to accomplish that. You could use Powershell or install a scripting language like Python, and run it as a second step after creating the repo. Alternatively, you could modify the Bonobo code to generate the hook when the repo is created. You could probably do it right in this controller:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s