Snap on Azure

Yesterday I started experimenting with Haskell on Azure by putting up a Snap server. It doesn’t do much, it’s just the default starter application you get when you do “snap init,” but it’s up and running on Azure. Here’s how it works.

Start with the latest Haskell Platform. Then install the Snap packages with cabal. A record of the steps I had to perform on my system is here. Once you’ve got a working Snap install, the easiest way to accomplish the steps listed below is to just clone the snapazure github repository. After that you can skip to the “Packing and Deploying” section.

Start by adding the various configuration files that Azure needs to know how to package up the application.

The most important one is the .csdef file that tells Azure about the files that comprise your application. I’ll spare you the actual XML, please take a look at the repository. There’s an interesting trick in there for passing environment variables to the application so that it can listen on the correct host and port – credit for this is due to Steve Marx, who used it first in his pythonrole project.

The .config files are also XML files, they specify primarily the number of instances of your service that Azure should run when you upload them.

Once those files are in place, make a folder called WorkerRole, cd into it, and do “snap init” to create your Snap application. Build it using “cabal install –bindir=.” so that the executable will be placed in the WorkerRole folder.

Packing and Deploying

Next, “cd ..” and then run “cspack ServiceDefinition.csdef” – this will create the ServiceDefinition.csx file, which is the archive that you’ll upload to Azure. You’ll then go create a Cloud Service, and upload the ServiceDefinition.csx along with the ServiceConfiguration.Cloud.config file to either the staging or production site. It may take quite some time (my first upload took around 15 minutes), but in the end you’ll have a Snap application running in your Azure account.

Here’s mine: http://snapdemo.cloudapp.net

Github repo to get you started: http://github.com/xoltar/snapazure

No Comments