Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create IIS Website with Rake

I am using rake and albacore to build my .net ASP MVC project, however one part I have not been able to automate so far is deploying the built project to IIS. Currently on developer machines I get the developers to manually create the websites and link them to a released output folder generated by the build.

However now that we have our CI box setup (Teamcity) I am needing to automate the setup of the website to IIS, so are there any rake tasks which can create a website on IIS? I remember seeing one a while back but cannot find it.

I can install the IIS 6 meta scripting stuff (cant remember its exact name) and any other iis plugins, the box currently runs IIS 7.5.

== Edit ==

The one I remember seeing a while back was InetMgr (https://github.com/typesafe/inetmgr), which seems a little unstable and doesn't work for me but doesn't seem to be supported any further.

like image 869
Grofit Avatar asked Jul 14 '12 08:07

Grofit


2 Answers

Not the best of answers, but as I couldn't find anything simpler than the proposed method below I just wrote something myself using appcmd:

def create_web_site(site_name, site_location, site_port)
  delete_command = "#{$file["appcmd"]} delete site #{site_name}"
  result = system delete_command
  puts "Failed to delete site on IIS: #{$?}" unless result

  add_command = "#{$file["appcmd"]} add site /name:#{site_name} /bindings:http/*:#{site_port}: /physicalPath:#{site_location}"
  result = system add_command
  raise "Failed to add site on IIS: #{$?}" unless result

  set_app_pool_command = "#{$file["appcmd"]} set app #{site_name}/ /applicationPool:\"ASP.NET v4.0\""
  result = system set_app_pool_command
  raise "Failed to bind site to .net 4 app pool on IIS: #{$?}" unless result

  start_site_command = "#{$file["appcmd"]} start site #{site_name}"
  result = system start_site_command
  raise "Failed to start site on IIS: #{$?}" unless result
end

$file["appcmd"] in the above is a global file lookup for my build scripts, this is c:/windows/system32/inetsrv.

I would love to find a nicer solution so if anyone comes across a nicer way of doing this add the answer and I will change the correct answer if it is any better. The only 2 libraries for doing this I found were dolphin deploy and 7 digital's iis rake script, neither of which seemed well documented on how to use unfortunately.

like image 133
Grofit Avatar answered Oct 18 '22 02:10

Grofit


I suggest you check out Capistrano. Capistrano is deployment "framework" for ruby/rails/... applications. Check out getting started part of documentation and then look at this "tutorial" on how to deploy to Windows Server with Capistrano.

like image 35
Oto Brglez Avatar answered Oct 18 '22 02:10

Oto Brglez