Task 03 - Deploy to Azure
Introduction
Zava has a multi-agent architecture in place. They would like to deploy this architecture to Azure so that they can test it in a production-like environment.
Description
In this task, you will deploy the chat application to Azure. You will build a Docker image and push it to Azure Container Registry. You will then make use of the Azure App Service that you created in the first exercise to host this application. You will then verify that the application is functioning as expected.
Success Criteria
- You have built a Docker image and pushed it to Azure Container Registry.
- You have deployed the application to Azure App Service.
Learning Resources
Key Tasks
01: Build a Docker container image and push to Azure Container Registry
The first step in this task is to create a Docker container image for the chat application. This image will include all the necessary dependencies and configurations to run the application in Azure. There is a Dockerfile in the src directory that you can use as-is for deployment. Review the Dockerfile to ensure that you understand the steps it will take.
Expand this section to view the solution
Before building the image, ensure that you are logged into your Azure account using the Azure CLI. You can do this by running the following command in your terminal:
az login
If you have multiple subscriptions and receive “Authentication failed against tenant {…}” errors, you may wish to use the command az login --tenant-id <your_tenant_id> to specify the tenant ID associated with your subscription.
Navigate to the src folder below your root directory if you are not already there in your terminal. Build the Docker image by running the following command in your terminal:
docker build -t chat-app .
This operation may take several minutes to download all of the necessary resources and build the container image. Ensure that the build completes successfully.
Then, log in to Azure Container Registry using the Azure CLI:
az acr login --name {YOUR_REGISTRY_NAME}.azurecr.io
Tag the Docker image with the Azure Container Registry login server name:
docker tag chat-app {YOUR_REGISTRY_NAME}.azurecr.io/chat-app:latest
Then, push the Docker image to Azure Container Registry:
docker push {YOUR_REGISTRY_NAME}.azurecr.io/chat-app:latest
02: Configure the Azure App Service
Now that you have pushed the Docker image to Azure Container Registry, the next step is to configure the Azure App Service to use this image. You will need to update the App Service settings to point to the Docker image in your Azure Container Registry.
Expand this section to view the solution
Navigate to the Azure portal and open the App Service that you created in the first exercise. From the Deployment menu, select the Deployment center option. Ensure that the following settings are in place.
| Setting | Value |
|---|---|
| Source | Container Registry |
| Container type | Single Container |
| Registry source | Azure Container Registry |
| Subscription ID | Your Azure subscription |
| Authentication | Managed Identity |
| Identity type | System assigned |
| Registry | The name of your Azure Container Registry |
| Image | chat-app |
| Tag | latest |
| Startup file or command | uvicorn chat_app:app --host 0.0.0.0 --port 8000 |
| Continuous deployment | On |
Then, select the Save button to save these settings.
Navigate to the Environment variables section under the Settings menu. In the App settings tab, select + Add to add a new environment variable. Name the setting WEBSITES_PORT and set the value to 8000. Then, select Apply to save the setting. Finally, select Save at the top of the page to apply this setting.
After that, return to your resource group and choose the Microsoft Foundry associated with this training. Navigate to Access control (IAM) from the left-hand menu. Select the + Add button and then choose the Add role assignment option. In the Role dropdown, select the Azure AI User role. In the Assign access to dropdown, select Managed identity and then select + Select members. In the Managed identity drop-down, select App Service from the list and then choose your App Service managed identity. After that, select the Select button at the bottom of the pane. Finally, select Review + assign twice to grant the Azure AI User role to your App Service.
It may take several minutes for the App Service to instantiate the container and apply these settings. Once the container is running, you can navigate to the URL of your App Service to access the chat application.