Skip to content

Latest commit

 

History

History
 
 

python

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
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" }}.

Overview

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.

Prerequisites for the lab

  1. Refer the Getting Started page to know the prerequisites for this lab.

  2. Click the Azure DevOps Demo Generator link and follow the instructions in Getting Started page to provision the project to your Azure DevOps.

Exercise 1: Endpoint Creation

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.

service_endpoint1

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." %}

service_endpoint2

Exercise 2: Configure Release

You will provision the resources on Azure using ARM template in the release definition.

  1. Go to Releases under Pipelines tab, select release definition Python and click Edit pipeline

    releaseedit

  2. Go to Tasks and select Dev environment, under Azure Deployment task, update Azure subscription and Location.

    azure_sub

  3. Under Install Python Extension task, update Azure subscription and select Python 3.6.4 x86 in Install Extensions.

    python_sub

  4. Under Azure App Service Deploy task, update Azure subscription and click on Save.

    deploy_app

    Tasks Usage
    Azure Resource Group Deployment This task will create a resource group with the name Python and provision an App service and App Service Plan
    Install Python Extension Installs the specific version of Python into Azure App Service
    Azure App Service Deploy The task is used to update Azure App Service to deploy Web Apps to azure.

Exercise 3: Trigger CI-CD with code change

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.

  1. Go to Repos tab and navigate to the below path to edit the file.

    {% include tip.html content= "python/app/templates/app/index.html" %}

    code_tab

  2. Click on Edit and go to line number 32, modify Continuous Delivery to Continuous Delivery for Python and commit the code.

    commit_code

  3. Go to Builds, under Pipelines tab to see the build in progress.

    in_progress_build

    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
  4. The build generates artifact which is used for deployment to Azure.

    build_result

  5. 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.

    release_in_progress

    release_succesful

  6. 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.

    azure_portal

  7. Select the App Service and from the Overview tab, click on Browse to see the application deployed.

    pythonapp

Summary

This lab shows how to create a continuous integration(CI) and continuous deployment (CD) pipeline for Python code with Azure DevOps on Azure.