|
| 1 | +--- |
| 2 | +title: Deploy an AI-enabled instance of Spring PetClinic on Azure Container Apps |
| 3 | +description: Use the azd automation tool to deploy a sample AI application to Azure Container Apps. |
| 4 | +services: container-apps |
| 5 | +author: KarlErickson |
| 6 | +ms.author: sonwan |
| 7 | +ms.service: azure-container-apps |
| 8 | +ms.topic: tutorial |
| 9 | +ms.date: 02/10/2025 |
| 10 | +ms.custom: |
| 11 | +#customer intent: As a developer, I want to see a simple example of an AI application deployed to Azure Container Apps. |
| 12 | +--- |
| 13 | + |
| 14 | +# Deploy an AI-enabled instance of Spring PetClinic on Azure Container Apps |
| 15 | + |
| 16 | +In this article, you learn how to use [Azure OpenAI Service](/azure/ai-services/openai/overview) and Azure Container Apps to create a natural language interface for the Spring PetClinic sample application. |
| 17 | + |
| 18 | +:::image type="content" source="media/first-java-ai-application/home-with-chatbot.png" alt-text="Screenshot of the home page of PetClinic." lightbox="media/first-java-ai-application/home-with-chatbot.png"::: |
| 19 | + |
| 20 | +For information on the architectural details of this application, see [Java PetClinic AI sample in Container Apps overview](./java-petclinic-ai-overview.md). |
| 21 | + |
| 22 | +## Considerations |
| 23 | + |
| 24 | +- **Deployment time**: The AI-enable application deployed in this article requires a series of connected services to operate. Deployment times can take upwards of 15 minutes to complete. Plan your time accordingly as you work through this tutorial. |
| 25 | + |
| 26 | +- **Model availability**: The sample application uses [Azure OpenAI Service](/azure/ai-services/openai/overview) deployment modules *gpt-4o* and *text-embedding-ada-002*, which might not be available in all Azure regions. |
| 27 | + |
| 28 | + For more information on availability, see [Azure OpenAI Service models](/azure/ai-services/openai/concepts/models?tabs=global-standard,standard-chat-completions) and select your desired deployment region. For best results, consider using one of the following regions: East US, East US 2, North Central US, South Central US, Sweden Central, West US, or West US 3. |
| 29 | + |
| 30 | +## Prerequisites |
| 31 | + |
| 32 | +Before you begin, ensure you have the following setup: |
| 33 | + |
| 34 | +- **Azure subscription**: You can [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) if you don't have an existing account. |
| 35 | + |
| 36 | +- **Security context**: To perform this quickstart, you need the `Contributor` and `User Access Administrator` roles, or the `Owner` role. |
| 37 | + |
| 38 | + For more information, see [Assign Azure roles using the Azure portal](../role-based-access-control/role-assignments-portal.yml?tabs=current). |
| 39 | + |
| 40 | +- **GitHub account**: Get one for [free](https://github.com/join). |
| 41 | + |
| 42 | +- **git**: Install the latest version of [git](https://git-scm.com/downloads). |
| 43 | + |
| 44 | +- **Microsoft Build of Open JDK**: Install [Microsoft Build of Open JDK](/java/openjdk/install). Use version 17 at a minimum. |
| 45 | + |
| 46 | +- **Azure Command-Line interface (CLI)**: Install [Azure CLI](/azure/developer/azure-developer-cli/install-azd) to manage your Azure resources via command line. |
| 47 | + |
| 48 | +- **Maven**: Install the latest version of [Maven](https://maven.apache.org/download.cgi). |
| 49 | + |
| 50 | +## Setup |
| 51 | + |
| 52 | +1. Clone the sample application to your machine. |
| 53 | + |
| 54 | + Open your terminal or command prompt to run the following command. |
| 55 | + |
| 56 | + ```bash |
| 57 | + git clone https://github.com/Azure-Samples/spring-petclinic-ai.git |
| 58 | + ``` |
| 59 | + |
| 60 | +1. Change into the *spring-petclinic-ai* folder. |
| 61 | + |
| 62 | + ```bash |
| 63 | + cd spring-petclinic-ai |
| 64 | + ``` |
| 65 | + |
| 66 | +1. If you don't already have it, install the Azure CLI. |
| 67 | +
|
| 68 | + ```bash |
| 69 | + az extension add --name containerapp --upgrade |
| 70 | + ``` |
| 71 | +
|
| 72 | +1. Log in to Azure. |
| 73 | +
|
| 74 | + Use the `auth` command to securely log in to your Azure account using the Azure CLI. |
| 75 | +
|
| 76 | + ```bash |
| 77 | + az auth login |
| 78 | + ``` |
| 79 | +
|
| 80 | + This command opens a web page where you can enter your Azure credentials to authenticate. |
| 81 | +
|
| 82 | +## Deploy |
| 83 | +
|
| 84 | +1. Automatically deploy the application by with the `azd up` command. |
| 85 | +
|
| 86 | + ```azurecli |
| 87 | + azd up |
| 88 | + ``` |
| 89 | +
|
| 90 | +1. When you're prompted you for a name, enter **my-first-ai** for the environment name. |
| 91 | + |
| 92 | + After that, enter values for `Azure Subscription` and `Azure location`, substituting your actual values for the `<..>` placeholders in the following prompts: |
| 93 | + |
| 94 | + ```bash |
| 95 | + ? Enter a new environment name: my-first-ai |
| 96 | + ? Select an Azure Subscription to use: <SUBSCRIPTION> |
| 97 | + ? Select an Azure location to use: <REGION> |
| 98 | + ``` |
| 99 | + |
| 100 | + Once you provide all the required values, you might need to wait upwards of 15 minutes for the application to deploy. |
| 101 | + |
| 102 | + When deployment is complete, you see output similar to the following to notify you of a successful deployment. |
| 103 | + |
| 104 | + ```output |
| 105 | + (✓) Done: Resource group: rg-my-first-ai (5.977s) |
| 106 | + (✓) Done: Virtual Network: vnet-my-first-ai (7.357s) |
| 107 | + (✓) Done: Container Registry: crb36onby7z5ooc (25.742s) |
| 108 | + (✓) Done: Azure OpenAI: openai-my-first-ai (25.324s) |
| 109 | + (✓) Done: Azure AI Services Model Deployment: openai-my-first-ai/text-embedding-ada-002 (42.909s) |
| 110 | + (✓) Done: Azure AI Services Model Deployment: openai-my-first-ai/gpt-4o (44.21s) |
| 111 | + (✓) Done: Container Apps Environment: aca-env-my-first-ai (3m1.361s) |
| 112 | + (✓) Done: Container App: petclinic-ai (22.701s) |
| 113 | + |
| 114 | + INFO: Deploy finish succeed! |
| 115 | + INFO: App url: petclinic-ai.<CLUSTER>.<REGION>.azurecontainerapps.io |
| 116 | + |
| 117 | + Packaging services (azd package) |
| 118 | + |
| 119 | + (✓) Done: Packaging service petclinic-ai |
| 120 | + |
| 121 | + Deploying services (azd deploy) |
| 122 | + |
| 123 | + (✓) Done: Deploying service petclinic-ai |
| 124 | + - Endpoint: https://petclinic-ai.<CLUSTER>.<REGION>.azurecontainerapps.io/ |
| 125 | + |
| 126 | + SUCCESS: Your up workflow to provision and deploy to Azure completed in 17 minutes 40 seconds. |
| 127 | + ``` |
| 128 | + |
| 129 | +1. Locate the application URL. |
| 130 | + |
| 131 | + Inspect the output and find the deployment success message and copy the URL to the clipboard. |
| 132 | + |
| 133 | + The success message resembles the following output: |
| 134 | + |
| 135 | + ```output |
| 136 | + INFO: Deploy finish succeed! |
| 137 | + INFO: App url: https://petclinic-ai.<CLUSTER>.<REGION>.azurecontainerapps.io |
| 138 | + ``` |
| 139 | + |
| 140 | +## Try your application |
| 141 | + |
| 142 | +1. Go to the application in a web browser using the URL you copied in the last step. |
| 143 | + |
| 144 | +1. You can interact with the chatbot by via prompts like: |
| 145 | + |
| 146 | + - List all registered pet owners. |
| 147 | + - Add a new pet owner named Steve. |
| 148 | + - Change Steve's name to Steven. |
| 149 | + - Add a pet named Spot. |
| 150 | + - List all vets in your system. |
| 151 | +
|
| 152 | + The following image shows the result of asking the application to add a new pet owner to the system. |
| 153 | +
|
| 154 | + :::image type="content" source="media/java-ai-application/add-new-item.png" alt-text="Screenshot of AI chat assistant adding a new owner, complete with address and other information, and information about a pet." lightbox="media/first-java-ai-application/add-new-item.png"::: |
| 155 | +
|
| 156 | +## Updates |
| 157 | +
|
| 158 | +As you experiment with the sample, if you want to deploy any changes to the application, you can run the following commands to publish your changes. |
| 159 | +
|
| 160 | +```azurecli |
| 161 | +azd package |
| 162 | +azd deploy |
| 163 | +``` |
| 164 | +
|
| 165 | +## Clean up resources |
| 166 | +
|
| 167 | +If you plan to continue working with subsequent tutorials, you might want to retain these resources. When you no longer need the resources, delete the resource group, which also deletes its resources. |
| 168 | +
|
| 169 | +### [Azure portal](#tab/azure-portal) |
| 170 | +
|
| 171 | +To delete the resources, use the Azure portal to find the resource group of this sample, and then delete it. |
| 172 | +
|
| 173 | +### [Azure CLI](#tab/azure-cli) |
| 174 | +
|
| 175 | +To delete the resource group, use the following command: |
| 176 | +
|
| 177 | +```azurecli |
| 178 | +az group delete --name rg-first-ai |
| 179 | +``` |
| 180 | +
|
| 181 | +--- |
| 182 | +
|
0 commit comments