Deploying Ruby (Java, Python, and Node.js) Applications to Windows Azure
One of the things that confused me when I first started working with Ruby on Windows Azure was how to deploy an application to Windows Azure. Visual Studio is for .NET stuff, and there wasn’t an IDE solution like PHP developers have with Eclipse + Windows Azure Tools for Eclipse. Luckily a few other people had already been down the path of deploying Ruby applications to Windows Azure and shared their experiences. Some of these approaches are also useful for other languages, such as Java, Python, and Node.js, so even if you’re not a Ruby developer you might find these useful.
Roll Your Own (Ruby Application + Visual Studio Project)
The first approach is to include your Ruby installation, application, gems, etc. as part of a Visual Studio project, and then deploy that to Windows Azure. I believe Simon Davies first blogged about this approach back in 2009 (http://blogs.msdn.com/b/simondavies/archive/2009/11/25/running-ruby-on-rails-on-windows-azure.aspx). He also maintains a sample of this project at http://archive.msdn.microsoft.com/railsonazure. There are other projects that accomplish this also, such as the http://rubyonrailsinazure.codeplex.com/ project maintained by Avkash Chauhan.
The downside to this solution is that it can result in a rather large deployment package, which increases upload time, and that it requires access to a Visual Studio and a Windows based environment.
For steps on using this type of solution, I’ll refer you to Avkash’s excellent instructions:
Smarx Role (Prebuilt Package + On the Fly Install + Reverse Proxy)
Steve Marx has created a project (http://smarxrole.codeplex.com/,) that will automatically configure a web role for running Ruby, Java, Python or Node.js applications. It’s available as a prebuilt package, so you don’t need Visual Studio or a Windows environment to use it.
On startup, this package will install Ruby (along with a bunch of other things like a Git client, Python, Node.js, etc.) into a Windows Azure Web role, and then it will install any gems mentioned in the Gemfile provided with your application. This deployment allows you to start multiple instances of your application on a host instance, so that you can have an instance of the application per core for example. Application Request Routing (an IIS thing that works in a web role even if you’re not using IIS to host your application,) is used to route requests between the multiple application instances running on the host instance.
There are a few limitations to this package however; it takes longer for the instance to start servicing incoming requests since part of the initial startup is downloading and installing various packages. Also it expects your application to be named app.ext, for example app.rb, app.js, etc.
Steve has an excellent presentation on the Smarx Role, which can be viewed online at https://channel9.msdn.com/events/MIX/MIX11/SVC04.
AzureRunMe (Prebuilt Package + On the Fly Install + Customized Scripts + Diagnostics)
Rob Blackwell maintains a project similar to Steve Marx’s, named AzureRunMe (https://github.com/RobBlackwell/AzureRunMe.) It also provides a similar deployment workflow experience, as it also provides a pre-built deployment package, a configuration you modify for your specific install, can be used with multiple development languages, and has the ability to install your application from Windows Azure storage.
It goes a bit beyond Steve’s solution however, in that it offers greater customization of the deployment via the configuration file. For example, you can provide custom scripts that run at startup and shutdown, pre and post update scripts, and tracing capabilities.
The readme for the AzureRunMe project is pretty comprehensive, and there's also a video demo of using it (for Java,) at https://vimeo.com/15258537.
You may have noticed in these solutions that you have to deploy a package to Windows Azure using the Windows Azure Portal. This should work in any browser that supports Silverlight, which is a requirement since the portal is written in Silverlight. This may be a non-starter for some, as Silverlight isn’t available on all platforms, and a lot of times you just want to run a quick command to deploy. Luckily there’s a solution there too.
Steve Marx created the waz-cmd (https://github.com/smarx/waz-cmd) command line tool that allows you to bypass using the web browser for deployments, so you can just download one of the pre-built packages mentioned above and then run the command line to deploy it. It does require you to access the Windows Azure Portal at least once in order to upload a certificate, which is used for subsequent administrative access by the waz command.
So Which One do I Use?
I tend to waffle back and forth over which to use for a specific project, which is good probably as I end up working with each. If you’re hosting your application on a Git repository, the Smarx Role is a no-brainer since it supports pulling the application down from Git. If you’re a .NET developer, building your own custom solution may work better for you, but if you’re looking for something that is pre-packaged and offers a lot of options, AzureRunMe may be the way to go.
I’ll call out in future posts which one I use and why if it’s important, otherwise just assume that whatever I’m talking about will work equally well with each approach.
Let me know if you have another solution for deploying Ruby applications to Windows Azure, or if there's something I've missed with the above solutions.