Windows Azure deployment

Jun 14, 2012 at 12:05 PM

Hi,

I am intrigued by the feature that creates an Azure Web Role from a python application. I have seen that it created a statup task that runs an EXE shipped with PTVS. I am curious about what that EXE does?

Does it work if my manage.py uses a different server than the Django server, for instance the gevent wsgi server (http://www.gevent.org/gevent.pywsgi.html)? Also, does it set up a reverse proxy (like IIS ARR) or does it serve directly?

Thanks

Flavien

Coordinator
Jun 14, 2012 at 4:52 PM

You can see the source code to AzureSetup here: http://pytools.codeplex.com/SourceControl/changeset/view/b0bdbb23cec4#Release%2fProduct%2fPython%2fAzureSetup%2fAzureSetup.cs

 

Basically what it does is make sure IIS is setup w/ FastCGI and then installs a FastCGI handler which is the Python interpreter running our wfastcgi.py script [http://pytools.codeplex.com/downloads/get/384925].  It also parses an AzureSetup.cfg file and uses that to install the Python interpreter and Django (from a WebPI feed), and get some paths. 

There's not a lot that's Django specific in there but there are a few bits and pieces.  There's the fact that we set the DJANGO_SETTINGS_MODULE env var and the wfastcgi.py script defaults to Django's WSGI handler - but this can be overridden with the WSGI_HANDLER env var. 

So the support another wsgi server should be as simple as abstracting away the setting of the DJANGO_SETTINGS_MODULE variable and enable setting the WSGI_HANDLER env var - so in general adding some support to AzureSetup so you can specify specific env vars with some parameterization.  That just needs to be something written out to AzureSetup.cfg which gets generated by our Microsoft.PythonTools.Django.targets file today (http://pytools.codeplex.com/SourceControl/changeset/view/b0bdbb23cec4#Release%2fProduct%2fPython%2fDjango%2fMicrosoft.PythonTools.Django.targets).  We'd welcome a contribution back which does this - also you could test it out in the Azure emulator before testing it out in Azure for real, we'll go through the same basic steps either way.

The requests then all get served via IIS via the FastCGI gateway talking to the Python interpreter running the wfastcgi.py script.

Jun 15, 2012 at 2:31 PM

Thanks for the details. My app uses gevent, which required that the server processes the HTTP requests on greenlets rather than theads. That's why gevent provides a custom http server, that runs an event loop and serves requests on greenlets. I suppose it means that won't work if I run with IIS FastCGI, because IIS provisions the threads, and doesn't know anything about greenlets. Is that correct, or is there a way to make it work somehow? (maybe modifying wfastcgi.py?)

 

Coordinator
Jun 15, 2012 at 3:10 PM

Yes, I think you're right that using IIS probably won't work here.  I think this is probably best positioned for using the new VM roles rather than the cloud services (the "web role" with IIS). 

In a VM you can easily run anything you want - including your custom HTTP server.  You then just need to configure the VM to have a mapping between the internal end point (port number) to an external end point - which can just be map port 80 to port 80. 

This video http://www.youtube.com/watch?v=f0qkYzUn4hA is a walkthrough of how to do this with a Linux VM from a Mac but it's basically the same if you want a Windows VM or if you're doing it from Windows.