Freigeben über


How to build Python Application package for Windows Azure App Gallery

Windows Azure Application Gallery gives Web Site builders an easy way to discover , learn and install freely available Open source Web applications on Windows Azure websites .To have your application included in the Gallery, you must add a couple of configuration files to your existing distribution package. This article provides everything you need to prepare your Python application for the Windows Web App Gallery.

PACKAGING PROCESS

The following procedure is a summary of the most common process for preparing a working application for inclusion in the Windows Azure App Gallery. The steps are described in more detail in the sections that follow.

  1. Review the Windows Azure Application Gallery Principles. All applications in the Windows Azure Application Gallery must follow these principles.
  2. Create and test a Web Deploy application package
  3. Submit the package to the Gallery for testing using the submission form.
  4. Resolve any issues with the Application Gallery team.

 

CREATE A WEB DEPLOYABLE PACKAGE

To create your application package, you need to create the following files:

1. Manifest.xml: Manifest file says what’s in the application package file and how to install it . Here is a basic manifest file 

<MSDeploy.iisApp>

  <!-- iisapp will copy the contents of the application root folder , in this case it is ‘mypythonapp’ to the newly created site for the application -->

  <iisApp path="mypythonapp"/>

</MSDeploy.iisApp>

 

Some of the other things you can do with the manifest file

  • Set permissions for files or folder using setAcl provider  
  • Run any prerequisite SQL scripts required for your application using dbfullsql (SQL Server) and dbmysql (MySQL) provider
  • Copy files from the root of the ZIP folder to the site root folder when installing the ZIP package using alias provider

 For more details refer Packaging Guidelines Reference Guide

2. Parameters.xml :Parameters file has a list of parameters that accept user input received during installation 

<parameters>

<!--The application path needs to be set here . Leave the defaultValue as empty as this will be replaced with the path to site that will be created during deployment -->

<parameter name="AppPath" defaultValue="" tags="iisapp">

<parameterEntry type="ProviderPath" scope="iisapp" match="mypythonapp" />

</parameter>

</parameters> 

For more details refer Packaging Guidelines Reference Guide

 

3. Web.config : Create a web.config file that will be part of your application root folder that will configure your application to

  • route all requests to the specified WSGI handler
  • Set Environment variables using appSettings
  • If the framework should serve certain files served statically, or from another web framework such as Node.js or ASP.NET, they could match different URLs in the rewrite, or could have additional web.config files masking the rewrite. For more information on URL rewrite , refer this article

 

<configuration>

    <appSettings> 

        <!-- The appSettings keys will be set as Environment variables --> 

        <!—You need to set the Python Path for the application in web.config . For Azure websites, use ‘D: \home\site\wwwroot’ as this will point to the site root where the any frameworks needed by your application will reside --> 

        <add key="pythonpath" value="D:\home\site\wwwroot" />

        <!-- You need to set the WSGI_HANDLER for the application in web.config . It's a module/package name, followed by the attribute in the module to be used; for example mypackage.mymodule.handler. Add parentheses to indicate that the attribute should be called. -->

        <!-- Here is an example WSGI_HANDLER for a Django based application -->

        <add key="WSGI_HANDLER" value="django.core.handlers.wsgi.WSGIHandler()" /> 

<!—If your application requires any additional app settings , then include then in this setting . For example Django require “DJANGO_SETTINGS_MODULE’ app settings, and this should be added in this section as seen below -->

 <!-- <add key=" DJANGO_SETTINGS_MODULE" value="DjangoApplication.settings" /> -->

     </appSettings>

 <system.webServer>

  <handlers> 

<!-- Configure the handler mapping for your application using the path to the Python interpreter and the path to the wfastcgi.py script . This handler mapping will be the same for any Python Application. Make sure your application has an empty ‘handler.fcgi’ file as the requests are mapped to this file -->

        <add name="Python_FastCGI"

                path="handler.fcgi"

                verb="*"

                modules="FastCgiModule"

                scriptProcessor="D:\Python27\python.exe|D:\Python27\Scripts\wfastcgi.py"

                resourceType="Either"

                requireAccess="Script" />

        </handlers> 

<!-- Include this rewrite rule as seen below to rewrite requests and route them through handler.fcgi -->

        <rewrite>

            <rules>

                <rule name="Rewrite Rule" stopProcessing="true">

                    <match url="(.*)" ignoreCase="false" />

                    <conditions>

                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />

                    </conditions>

                    <action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="false" />

                </rule>

            </rules>

        </rewrite>

    </system.webServer>

</configuration>

 

4.handler.fcgi : Include an empty handler.fcgi is used as an empty handler file under the web site root to serve as the request target .

Refer this article on how to configure Python for Windows Azure

PACKAGE AN APPLICATION

Create a compressed file (Zip) package of the application. You can create the Zip file with Windows® Explorer, WinZip, or the Linux zip command. The Manifest.xml, Parameters.xml go in the root directory of the ZIP package. The rest of your application goes in a sub folder of the root as in the diagram below.

mypythonapp.zip
\
 +--Manifest.xml (required)
 +--Parameters.xml (required)
 +--mypythonapp root folder
    \
     +-- your application’s sub folders and files  

     +-- Python Framework modules, example ‘django’ framework folder will be placed here   
     |--web.config (required)
     |--handler.fcgi (required)

TEST APPLICATION PACKAGE

Install dependencies for testing the application : All you need is Web deploy v3.0

Setup a Windows Azure account if you don’t have one  

If you don’t already have an account for Windows Azure, you can setup a free trial account that is available for 90 days or you can sign up for an Azure subscription based on the plans available. If you already have a Windows Azure account you can use the existing account.

Create a Website for your application using the Azure Management Portal

Login to https://manage.windowsazure.com and create a new site or use an existing site. Click on the site to access its Dashboard. Now download the Publish Profile . Open the file in any text editor. Here is a sample:

<publishProfile profileName="myazuresite - Web Deploy" publishMethod="MSDeploy" publishUrl="waws-prod-001.publish.azurewebsites.windows.net:443" msdeploySite="myazuresite" userName="$myazuresite" userPWD="7nbQc4ngW" destinationAppUrl="https://myazuresite.azurewebsites.net" SQLServerDBConnectionString="" mySQLDBConnectionString=" " hostingProviderForumLink="" controlPanelLink="https://windows.azure.com">

 

Build a SetParameters File for deploying your application

You can name this file as you would name a filename, but for the sake of this article let’s say the file is called SetParameters.xml .

This is a sample of the SetParameters.xml file. You can see the parameters.xml file from the web deployable package here .

 <parameters> 
  <!--The name of the parameter matches the application path parameter in parameters.xml . Value for the parameter is azure site name  -->
      <setParameter name="AppPath" value="myazuresite" /> 
 </parameters>

 

Run Web Deploy Command Line

Open Command Prompt with elevated privileges and run msdeploy.exe to publish the application to Azure site you just created.

Usage:

Msdeploy.exe –verb:sync –source:package=<pathToLocalZip> -dest:auto,computername=”<publisherURLwithHttpsAndPortOr8172>/msdeploy.axd?site=<remoteSiteName>”,username=<publishingUserName>,password=<publisherPwd>,authtype=basic - setParamFile:<pathToLocalSetParamFile>

Example:

C:\Program Files\IIS\Microsoft Web Deploy V3>Msdeploy.exe -verb:sync -source:package="c:\packages\mypythonapp.zip" -dest:auto,computername='https://waws-prod-001.publish.azurewebsites.windows.net:443/msdeploy.axd?site=myazuresite',username='$myazuresite',password='7nbQc4ngW',authtype=basic -setParamFile:"c:\setparameters.xml"

Once your application package has been successfully deployed to Azure site. Browse the Site URL and to verify if your application runs successfully on Windows Azure .

REFERENCES

Tips for a successful submission to Windows Azure App Gallery

Packaging Guidelines Reference Guide

Windows Azure Python Developer center

Configuring Python with Windows Azure Web Sites