Git可以直接部署网站到服务器上，想必已经是人尽皆知的事情了。主要是用到了Git hook技术，不过网上的资料大多都是Linux下的操作，仅有的Windows平台的文章也讲的是将Git Server安装到服务器上。其实当你用过了Azure的“网站”功能后就会觉得直接将Git中的文件部署到IIS上是多么爽的一件事，不过并不是所有的网站都可以部署到Azure的“网站”上。 下面就介绍一个来自Azure的开源项目，有了它你也可以实现直接通过Git发布你的项目了。 首先，项目的地址是 https://github.com/projectkudu/kudu 有几个坑需要注意：
Below I’ll assume that you have IIS 7.x installed on your local machine. If you want to go live with Kudu, simply deploy the Kudu.Web project to a site on your production/online IIS as usual.
Now open up the Kudu.sln in Visual Studio. Mark the Kudu.Web project as active (makes it bold) and hit CTRL+F5.
If everything went well you should now see the Kudu dashboard, looking like this:
In your Kudu dashboard:
Kudu is now creating a brand new IIS site directly on your IIS (!!) and showing you some geeky stuff:
It tells the URL to the Git remote we can push apps to, the URL to the site itself and the service URL which actually is the Git remote from before.
Let’s take a quick look in IIS to see what happend:
So Kudu is creating 2 sites with a kudu_ prefix. The first is the main site, the one hosting your application. The second is the “git remote site”/service site. Both sites is running on the same application pool.
If we go to the application URL we see a default screen:
Alright, let’s assume that you want to push a FunnelWeb blog like mine to the newly created site. First clone your fork of FunnelWeb (or whatever application you like) to your disk. Next open up a git shell (if you’re using Github for Windows, go to the repository, select tools then open a shell here). We now need to add a new remote, using the Git URL we got from Kudu. In my case I typed this:
git remote add kudu http://localhost:63185/jhovgaardnet.git
Git now knows about the repository located on our local IIS, making us able to do a simple push of our master like this:
git push kudu master
Awesome! If you didn’t mess it up, this is what you should see (not necessary the dependency installations of course):
Now updating the application URL shows my fully deployed blog, just as expected. Yes, it’s freaking awesome!
The next thing for you will be to deploy Kudu on your production IIS, setting up sites as Kudu sites, setting correct bindings, etc.
I really think Kudu is swell and I hope to see some interesting forks of Kudu that moves it closer to a continuous integration system with Github hooks, unit testing abilities, etc. TeamCity is cool, but it’s expensive and heavy. We need a slick open source .NET alternative and I hope Kudu is the beginning!
What do you think? Can you see the possibilities? Are you going to use Kudu?
Thanks for reading guys!