Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy Flask+ Python application on Windows Azure?

I recently developed an App in Flask + Python with PostgreSQL as database.

How can I upload my app on Windwos Azure? Does Windows Azure support Flask? Is it worth installing Flask app on Windows Azure virtual machine?

A lot of tutorials instruct to use Visual Studio and IPython with Django but that's not my choice.

Is there any guide or tutorial to get started?

like image 536
Man8Blue Avatar asked Mar 10 '13 02:03

Man8Blue


People also ask

Can we deploy jar file in Azure App Service?

You can deploy your WAR, JAR, or EAR package to App Service to run your Java web app using the Azure CLI, PowerShell, or the Kudu publish API.

How do you deploy a Flask on a Windows server?

Inside FlaskApp folder, create the Flask Application file “app.py”. Now, copy the “wfastcgi.py” file from “C:\Python\Lib\site-packages\” directory and paste it to “C:\inetpub\wwwroot\FlaskApp\” directory. Now, as the permissions are added, we are ready to deploy our Flask application in the IIS server.


2 Answers

As of July 2013 there's a Flask template on Azure.

enter image description here

Start with that. Clone it to your computer. There's some IIS stuff at the root, and a hello world Flask in the folder FlaskApplication. You can test the Flask app on your computer python __init__.py. I don't know how to test the IIS site locally.

I don't know how dependencies work either. There's a Pip requirements.txt in the template, and also the source trees of Flask and a couple of other libraries.

I copied an app of mine from Heroku to Azure. Got it working eventually. The biggest difficulty was finding and reading logs (you need to turn on all the logging in the IIS manager, then browse to an FTP site, then the logs are deep in some weird named xml file), which made the two minor problems take longer than they should to solve

  1. Working directory is different to Heroku (at the IIS site root, rather than the Flask site root)
  2. The template has a dodgy web.config that silently deletes query strings from get requests

This was the problem

 <action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="false" />
like image 128
Colonel Panic Avatar answered Sep 18 '22 00:09

Colonel Panic


Assuming you want to create a cloud service, the easiest way to start would be using Windows Azure PowerShell and the new template feature - this allows you to create custom scaffolding for your own roles. You would place the necessary role setup for installing Python and Flask runtimes in the template folder, and then use Publish-AzureServiceProject to publish to Azure.

There is built-in support for Django web roles, so you might actually start from there and make the modifications necessary to support Flask.

The other option would be to use a Linux VM, which you could set up yourself via SSH. PowerShell or the cross-platform CLI would be a big help here, see: http://www.windowsazure.com/en-us/develop/nodejs/tutorials/linux-virtual-machine/ for a walk through on virtual machines.

like image 30
Mark Cowlishaw - MSFT Avatar answered Sep 20 '22 00:09

Mark Cowlishaw - MSFT