Skip to content

Latest commit

 

History

History
84 lines (50 loc) · 6.05 KB

File metadata and controls

84 lines (50 loc) · 6.05 KB
title Overview of how to deploy a Python web app in Azure Container Apps
description Overview of how to create a container from a Python web app and deploy it to Azure Container Apps, a serverless platform for hosting containerized applications.
ms.topic conceptual
ms.date 08/29/2022
ms.custom devx-track-python
ms.prod azure-python
author jessmjohnson
ms.author jejohn

Overview: Deploy a Python web app on Azure Container Apps

This tutorial shows you how to containerize a Python web app and deploy it to Azure Container Apps. The provided sample web app can be containerized and the container image stored in Azure Container Registry. Azure Container Apps is initially configured to pull the container image from Container Registry. The sample app connects to a Azure Database for PostgreSQL to show communicating between Container Apps and other Azure resources.

There are many options to build and deploy cloud native and containerized Python web apps on Azure. If you're starting off with containers, deploying your web app as a container to either Azure Web App Service or Azure Container Apps is a good first step. This tutorial covers Azure Container Apps. Deploying a Python web app as a container to Azure App Service is covered in the tutorial Containerized Python web app on Azure. Other options such as Azure Container Instance and Azure Kubernetes Service are covered in the article Comparing Container Apps with other Azure container options.

In this tutorial you will:

  • Build a Docker container image directly in Azure.
  • Configure an Azure Container App to host the container image.
  • Optionally configure a GitHub action that updates the container image triggered by checkin to GitHub.

Following this tutorial, you'll have the basis for Continuous Integration (CI) and Continuous Deployment (CD) of a Python web app to Azure.

Service Overview

The service diagram supporting this tutorial shows how your local environment, GitHub repositories, and different Azure services are used in the tutorial.

:::image type="content" source="./media/tutorial-container-apps/service-diagram-overview-for-tutorial-deploy-python-azure-container-apps.png" alt-text="A screenshot of the services using in the Tutorial - Containerized Python App on Azure." lightbox="./media/tutorial-container-apps/service-diagram-overview-for-tutorial-deploy-python-azure-container-apps.png":::

[Diagram]

The components supporting this tutorial and shown in the diagram above are:

  • Azure Container Apps

    • Azure Container Apps enables you to run microservices and containerized applications on a serverless platform. A serverless platform means that you enjoy the benefits of running containers with minimal configuration. With Azure Container Apps, your applications can dynamically scale based on characteristics such as HTTP traffic, event-driven processing, or CPU or memory load.
    • Container Apps pulls image from Azure Container Registry. Revisions to container images trigger an update to the deployed container. You can also configure changes to GitHub to trigger the update.
  • Azure Container Registry

    • Azure Container Registry enables you to work with Docker images and its components in Azure. It provides a registry that's close to your deployments in Azure and that gives you control over access, making it possible to use your Azure Active Directory groups and permissions.
    • In this tutorial, the registry source is Azure Container Registry, but you can also use Docker Hub or a private registry with minor modifications.
  • Azure Service Connector

  • Azure Database of PostgreSQL

  • GitHub

Revisions and CI/CD

To make code changes and push them to the container, you create a new container image with the change. Then, you push the image to Container Registry, and create a new revision of the container app. To automate this process, an optional step in the tutorial shows you how to build a continuous integration and continuous delivery (CI/CD) pipeline with GitHub actions. The pipeline automatically builds and deploys your code to the Container App.

Authentication and security

In this tutorial, you'll build a Docker container image directly in Azure and deploy it to Azure Container Apps. Container Apps run in the context of an environment, which is supported by a virtual network (VNET). Azure Virtual Networks (VNet) are fundamental building block for your private network in Azure. Container Apps allows you to expose your container app to the public web by enabling ingress.

When you initially configure a container in Container Apps, you configure which container image to use from Azure Container Registry. You can create new revisions that use different versions of that image or a new image. Revisions are useful, for example, when you're making code changes or doing A/B testing.

To set up continuous integration and continuous delivery (CI/CD), you connect to a GitHub account, repository, and branch. In addition, you create an Azure Active Directory service principal (or using an existing) context with role-based access control.

The tutorial sample web app uses PostgreSQL to store data. The sample code connects to PostgreSQL via a connection string. The connection string is stored securely using an Azure Service Connector, which helps you connect Azure compute services to other backing services. During the configuration of the Container App, the tutorial walks you through the service connector.

Prerequisites

To complete this tutorial, you'll need:

  • An Azure account where you can create:

    • Azure Container Registry
    • Azure Container App environment
    • Azure Database for PostgreSQL
  • Visual Studio Code or Azure CLI, depending on what tool you'll use.

    • For Visual Studio Code, you'll need the Azure Container Apps extension.
  • Python packages:

    • LIBRARY for connecting to Postgres
    • Flask or Django as a web framework.