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 deploy this image to the Azure Container App that was created in the first exercise. 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 Container Apps.
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:
az acr build --registry {YOUR_ACR_NAME} --image chat-app:latest --platform linux/amd64 --file src/Dockerfile .
This operation may take several minutes to download all of the necessary resources and build the container image, tag it as chat-app:latest, and push to your container registry. Ensure that the build completes successfully.
02: Deploy to Azure Container Apps
Now that you have pushed the Docker image to Azure Container Registry, the next step is to deploy it to the Azure Container App that was created in the first exercise. The Bicep template deployed the Container App with a placeholder image, ingress on port 8000, and a system-assigned managed identity. You will now configure the Container App to pull from your Azure Container Registry and update it to use the image you just pushed. You will also grant the Container App access to Microsoft Foundry.
Expand this section to view the solution
First, configure the Container App to authenticate against your Azure Container Registry using its system-assigned managed identity. The initial deployment used a public placeholder image, so the registry configuration needs to be added now.
az containerapp registry set \
--name {YOUR_CONTAINER_APP_NAME} \
--resource-group {YOUR_RESOURCE_GROUP} \
--server {YOUR_REGISTRY_NAME}.azurecr.io \
--identity system
If you receive a permissions error, ensure that the Container App’s managed identity has the AcrPull role on your Azure Container Registry. The Bicep template should have configured this, but you can verify it in the Access control (IAM) blade of the Container Registry in the Azure portal.
Next, update the Container App to pull the image you pushed:
az containerapp update \
--name {YOUR_CONTAINER_APP_NAME} \
--resource-group {YOUR_RESOURCE_GROUP} \
--image {YOUR_REGISTRY_NAME}.azurecr.io/chat-app:latest
03: Set Container App environment variables
The Bicep template has already configured the Azure Container App with most environment variables automatically, including Cosmos DB endpoint, storage account name, Application Insights, model deployment names, API versions, and agent IDs.
After deploying your container updates in the previous key task, you need to set the four model-specific endpoint variables on the Container App. Run the following command, replacing the placeholder values with the endpoints you collected in your .env file:
az containerapp update \
--name {YOUR_CONTAINER_APP_NAME} \
--resource-group {YOUR_RESOURCE_GROUP} \
--set-env-vars \
FOUNDRY_ENDPOINT="{YOUR_FOUNDRY_ENDPOINT}" \
gpt_endpoint="{YOUR_GPT_ENDPOINT}" \
embedding_endpoint="{YOUR_EMBEDDING_ENDPOINT}" \
phi_4_endpoint="{YOUR_PHI4_ENDPOINT}"
Alternatively, you can set these in the Azure portal by navigating to your Container App, selecting Containers from the Application menu. In the container settings, select the Environment variables tab to add or update values.
It may take a minute for the Container App to pull the image and start the new revision. Once the container is running, you can navigate to the fully qualified domain name (FQDN) of your Container App to access the chat application. You can find the FQDN as Application Url in the Overview page of your Container App in the Azure portal.