直接使用Git部署网站到IIS上

Git可以直接部署网站到服务器上,想必已经是人尽皆知的事情了。主要是用到了Git hook技术,不过网上的资料大多都是Linux下的操作,仅有的Windows平台的文章也讲的是将Git Server安装到服务器上。其实当你用过了Azure的“网站”功能后就会觉得直接将Git中的文件部署到IIS上是多么爽的一件事,不过并不是所有的网站都可以部署到Azure的“网站”上。 下面就介绍一个来自Azure的开源项目,有了它你也可以实现直接通过Git发布你的项目了。 首先,项目的地址是 https://github.com/projectkudu/kudu 有几个坑需要注意:

  1. kudu只能用Visual Studio直接运行,如果放到IIS中运行会提示你不允许
  2. 必须把Git文件的文件夹放到C:\Program Files (x86)下,文件夹名称必须叫Git
  3. 下面官方文档中要求安装的那堆东西最好安上,免得出现稀奇古怪的错误

由于很简单,原文直接粘贴如下:

Deploying: Add Git support to your IIS server

Build n’ start!

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:

Kudu Dashboard

Create your first Git enabled site

In your Kudu dashboard:

  • Click the “Create application” link in the top menu.
  • Enter a preferred name for the IIS site (I.e. “jhovgaardnet”).
  • Click the blue “Create application” button.

Kudu is now creating a brand new IIS site directly on your IIS (!!) and showing you some geeky stuff:

Kudu website created

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:

Kudu sites in IIS

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:

Kudu IIS default site

Let’s push it!

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!

Conclusion

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!

  ——————————–另外还有一篇官方的文档———————————–

Manual Setup Instructions

  • Visual Studio 2012. Note that you need to run it as admin. Install/Update to the latest version of NuGet Package Manager (Tools -> Extensions and Updates).
  • IIS >= 7, configured to run ASP.NET 4.0. This can be installed using WebPI.
  • Install Git (http://git-scm.com/downloads) to the default location (we expect it in C:\Program Files (x86)\Git\bin).
  • Install Node. Node is used as part of the build process for sites.

Note: If you manually install IIS, here is what needs to be enabled: Windows Features

Additional prerequisites to run the functional tests

  • Install the XUnit.net runner for VS 2012, which you install from Tools / Extensions & Updates
  • Open your %WINDIR%\System32\inetsrv\config\applicationHost.config and look for<applicationPoolDefaults>. Under <processModel>, make sure you don’t havesetProfileEnvironment="false". If you do, set it to true (or remove the attribute if you are running the latest Windows 8.1).
  • Install the URL rewrite module for IIS.
  • Install IISNode
  • Install TypeScript Plugin (for VS2012)
  • Pretend to have the 32 bit version of Node to fool the version detection logic:
    • Copy your \Program Files\nodejs folder to \Program Files (x86)\nodejs.
    • Under \Program Files (x86)\nodejs, you need to have a folder named 0.8.2, and containing node.exe version 0.8.2. And then same deal for Node 0.10.5. Yes, this is kind of painful, and we need to make it easier!
  • The Web and WebApplications folders need to be present under \Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0. If you don’t have them, you may need to copy them from a machine that has VS 2010 installed. This is needed because some of the test apps target these. TODO: we need to make this easier!
  • Install Mercurial to the default location (we expect it in C:\Program Files (x86)\Mercurial)

Deploying your first application

  1. First clone the repository.
    git clone git://github.com/projectkudu/kudu.git
    
  2. Open Kudu.sln as Administrator and build it.
  3. Set Kudu.Web as the startup project and run!

After running Kudu.Web, you should be able to use the dashboard to manage your application. Below is a walk through on how to create and deploy your first application using git.

Step 1

Create an application. Step 1

Step 2

Give it a name. Step 2

Step 3

Copy the git url and push. Step 3

Step 4

You’re live! Step 4

Comments are Disabled