AZURE HEROES
  • Home-Updates
  • Blog
    • Azure Blog
    • Azure Heroes Events >
      • Azure Heroes Sessions #1
      • Azure Heroes Sessions #2
      • Azure Heroes Sessions #3
      • Azure Heroes Sessions #4
      • Azure Heroes Sessions #5
      • Azure Heroes Sessions #6
      • Azure Heroes Sessions #7
  • Who We Are!
  • eBooks
  • Azure All In One!
    • Azure Disk & Storage
    • Azure Network
    • Azure VPN
    • Azure VMs
  • Free Azure Support!
  • Contact Us
  • Events
    • Beginners Event
    • Developers Event
    • Special Event
    • Azure Workshop #4
    • Azure Workshop #5
    • Azure Workshop #6
    • Azure Workshop #7
    • Azure Workshop #8
    • Azure Heroes Sessions #9
    • Azure Heroes Sessions #10
    • Azure Heroes Sessions #11
    • Azure Heroes Sessions #12
    • Azure Heroes Sessions #13
    • Azure Heroes Sessions #14
    • Azure Heroes Sessions #15
    • Azure Heroes Sessions #16
    • Azure Heroes Sessions #17
    • Azure Heroes Sessions #18
  • Registration Form
  • Privacy Policy
  • Home-Updates
  • Blog
    • Azure Blog
    • Azure Heroes Events >
      • Azure Heroes Sessions #1
      • Azure Heroes Sessions #2
      • Azure Heroes Sessions #3
      • Azure Heroes Sessions #4
      • Azure Heroes Sessions #5
      • Azure Heroes Sessions #6
      • Azure Heroes Sessions #7
  • Who We Are!
  • eBooks
  • Azure All In One!
    • Azure Disk & Storage
    • Azure Network
    • Azure VPN
    • Azure VMs
  • Free Azure Support!
  • Contact Us
  • Events
    • Beginners Event
    • Developers Event
    • Special Event
    • Azure Workshop #4
    • Azure Workshop #5
    • Azure Workshop #6
    • Azure Workshop #7
    • Azure Workshop #8
    • Azure Heroes Sessions #9
    • Azure Heroes Sessions #10
    • Azure Heroes Sessions #11
    • Azure Heroes Sessions #12
    • Azure Heroes Sessions #13
    • Azure Heroes Sessions #14
    • Azure Heroes Sessions #15
    • Azure Heroes Sessions #16
    • Azure Heroes Sessions #17
    • Azure Heroes Sessions #18
  • Registration Form
  • Privacy Policy

Azure Pipelines to Build and Deploy a Python Web App to Azure App Service

7/30/2024

0 Comments

 
In modern DevOps practices, continuous integration and continuous deployment (CI/CD) play a crucial role in delivering high-quality applications efficiently. Azure Pipelines, a part of Azure DevOps, enables developers to automate the building, testing, and deployment of applications to Azure services, including Azure App Service.

Picture
In this blog post, we will walk through setting up an Azure Pipeline to build and deploy a Python web application to Azure App Service.Prerequisites
Before we begin, ensure you have the following:
  • An Azure DevOps account (Sign up here)
  • An Azure Subscription with an App Service created (Create one here)
  • A GitHub or Azure Repos repository with your Python web app code (sample code)
  • A Service Connection between Azure DevOps and your Azure subscription

Step 1: Create an Azure App Service
If you haven't already created an Azure App Service, follow these steps:
  1. Navigate to the Azure Portal.
  2. Click on Create a resource > App Service.
  3. Select Runtime Stack as Python (e.g., Python 3.10).
  4. Choose a Region and App Service Plan based on your needs.
  5. Click Review + Create and then Create.
  6. Note the App Service Name, as you will use it in the deployment process.
Step 2: Set Up Azure Pipelines1. Create a New Pipeline
  1. Go to your Azure DevOps project.
  2. Navigate to Pipelines > New Pipeline.
  3. Choose your repository source (GitHub, Azure Repos, etc.).
  4. Select Starter pipeline or configure with a YAML file.
2. Define Your azure-pipelines.ymlCreate a YAML file (azure-pipelines.yml) in the root of your repository with the following configuration:
trigger:
  - main  # Adjust this based on your branch

pool:
  vmImage: 'ubuntu-latest'

variables:
  pythonVersion: '3.11'

steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '$(pythonVersion)'

- script: |
    python -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
  displayName: 'Install dependencies'

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '.'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/app.zip'
    replaceExistingArchive: true

- upload: $(Build.ArtifactStagingDirectory)/app.zip
  artifact: drop

- task: AzureWebApp@1
  inputs:
    azureSubscription: '<Your Azure Service Connection>'
    appName: '<Your App Service Name>'
    package: '$(Build.ArtifactStagingDirectory)/app.zip'
3. Save and Run the Pipeline
  1. Commit the azure-pipelines.yml file to your repository.
  2. Navigate to Pipelines and run the pipeline.
  3. Azure Pipelines will build and deploy the app automatically.
Step 3: Verify the DeploymentOnce the pipeline runs successfully:
  1. Go to the Azure Portal.
  2. Navigate to your App Service.
  3. Click on Browse to open your deployed Python web application.
  4. Alternatively, visit https://<your-app-name>.azurewebsites.net in a browser.

Conclusion
With Azure Pipelines, you have successfully automated the build and deployment of your Python web application to Azure App Service. This approach ensures faster and more reliable deployments, enabling you to focus on development rather than manual deployments.
Next steps:
  • Add unit tests to your pipeline.
  • Integrate with monitoring tools like Application Insights.
  • Use staging slots for safe deployments.

0 Comments



Leave a Reply.

    Author

    Mohammad Al Rousan is a Microsoft MVP (Azure), Microsoft Certified Solution Expert (MCSE) in Cloud Platform & Azure DevOps & Infrastructure, An active community blogger and speaker. Al Rousan has over 11 years of professional experience in IT Infrastructure and very passionate about Microsoft technologies and products.

    Picture
    Picture
    Top 10 Microsoft Azure Blogs

    Archives

    January 2025
    December 2024
    November 2024
    October 2024
    September 2024
    July 2024
    June 2024
    May 2024
    April 2024
    February 2024
    September 2023
    August 2023
    May 2023
    November 2022
    October 2022
    July 2022
    June 2022
    May 2022
    April 2022
    March 2022
    February 2022
    January 2022
    December 2021
    November 2021
    May 2021
    February 2021
    December 2020
    November 2020
    October 2020
    September 2020
    August 2020
    June 2020
    April 2020
    January 2020
    July 2019
    June 2019
    May 2019
    February 2019
    January 2019

    Categories

    All
    AKS
    Azure
    Beginner
    CDN
    DevOps
    End Of Support
    Fundamentals
    Guide
    Hybrid
    License
    Migration
    Network
    Security
    SQL
    Storage
    Virtual Machines
    WAF

    RSS Feed

    Follow
    Free counters!
Powered by Create your own unique website with customizable templates.