title | layout | sidebar | permalink | folder |
---|---|---|---|---|
Deploy Python application to Azure App Service using Azure DevOps |
page |
vsts2 |
/labs/vstsextend/python/ |
/labs/vstsextend/python/ |
Last updated : {{ "now" | date: "%b %d, %Y" }}.
Python is a server-side scripting language and a powerful tool for making dynamic and interactive web pages.
This lab shows how to deploy a Python application to Azure App Service using Azure DevOps. We will be using Django{:target="_blank"} framework for deployment.
-
Refer the Getting Started page to know the prerequisites for this lab.
-
Click the Azure DevOps Demo Generator link and follow the instructions in Getting Started page to provision the project to your Azure DevOps.
Since the connections are not established during project provisioning, you will manually create the endpoints.
In Azure DevOps, navigate to Project settings, under Pipelines select Service connections, click on + New service connection and select Azure Resource Manager. Specify connection name, select your subscription from the drop down and click on OK. We use this endpoint to connect Azure DevOps with Azure.
You will be prompted to authorize this connection with Azure credentials.
{% include note.html content= "Disable pop-up blocker in your browser if you see a blank screen after clicking OK, and retry the step." %}
You will provision the resources on Azure using ARM template in the release definition.
-
Go to Releases under Pipelines tab, select release definition Python and click Edit pipeline
-
Go to Tasks and select Dev environment, under Azure Deployment task, update Azure subscription and Location.
-
Under Install Python Extension task, update Azure subscription and select Python 3.6.4 x86 in Install Extensions.
-
Under Azure App Service Deploy task, update Azure subscription and click on Save.
Python is an interpreted language, and hence compilation is not required. We will archive the files in the build and use the package in the release for deployment. Update the code to trigger CI-CD using Hosted build agent.
-
Go to Repos tab and navigate to the below path to edit the file.
{% include tip.html content= "python/app/templates/app/index.html" %}
-
Click on Edit and go to line number 32, modify Continuous Delivery to Continuous Delivery for Python and commit the code.
-
Go to Builds, under Pipelines tab to see the build in progress.
Let's explore the build definition while the build is in-progress. The tasks used are listed as shown.
Tasks Usage Archive files creates zip file for deployment Copy Files copies ARM template which is used to provision resources on azure Publish Build Artifacts publishes the build artifacts -
The build generates artifact which is used for deployment to Azure.
-
Once the build is complete, it triggers the CD pipeline. You can notice the linked release is in progress by navigating to Releases under Pipelines. The release will provision the Azure Web app and deploy the zip file generated by the associated build.
-
Once the Release is succeeded, login to Azure Portal{:target="_blank"} and go to the Resource Group with the name Python. You will see the resources App Service and App Service Plan.
-
Select the App Service and from the Overview tab, click on Browse to see the application deployed.
This lab shows how to create a continuous integration(CI) and continuous deployment (CD) pipeline for Python code with Azure DevOps on Azure.