This project shows how to deploy the Spring Petclinic Microservices application with OpenAI to Azure Container Apps and integrate it with additional Azure services, also some samples for Azure Container Apps features.
Features • Gettting Started • Guidance
This template, the application code and configuration it contains, has been built to showcase Microsoft Azure specific services and tools. We strongly advise our customers not to make this code part of their production environments without implementing or enabling additional security features.
For a more comprehensive list of best practices and security recommendations for Intelligent Applications, visit Azure security best practices and patterns, Azure security baseline for Intelligent Recommendations
The following technologies are part of the project:
- Java 17
- Maven
- Azure CLI
- Azure Developer CLI (azd)
This project provides the following features:
- A Spring Petclinic Microservices deployment on Azure Container Apps with AI chat agent.
- Azure Container Apps java components (eureka server /config server / spring boot admin) support.
- Bicep files for provisioning Azure resources, including Azure OpenAI, Azure Container Apps, Azure Database for MySQL - Flexible Server, Azure Container Registry, Azure Log Analytics, Azure Application Insights and RBAC roles. See Deploy to Azure automatically.
- Best practices to build more secure, more reliable and more flexible java apps on Azure Container Apps.
- AI chat agent to take advantage of large-scale, generative AI models with deep understandings of language and code to enable new reasoning and comprehension capabilities. See Integrate with Azure OpenAI
You have a few options for getting started with this template.
All the steps of this lab have been tested in the GitHub CodeSpace. This is the preferred option for running this lab!
- Prepare the environment following the steps in Using a GitHub codespace
- Continue with deploying steps
- Prepare the environment following the steps in Using Visual Studio Code with remote containers
- Continue with deploying steps
- Prepare the environment following the steps in Install all the tools on your local machine
- Continue with deploying steps
Once you've opened the project in Codespaces, in Dev Containers, or locally, you can deploy it to Azure.
- Your Azure account must have
Microsoft.Authorization/roleAssignments/write
permissions, such as Role Based Access Control Administrator, User Access Administrator, or Owner. If you don't have subscription-level permissions, you must be granted RBAC for an existing resource group and deploy to that existing group. - Your Azure account also needs
Microsoft.Resources/deployments/write
permissions on the subscription level.
Suggested: Both Contributor and User Access Administrator roles on the subscription.
-
Login to Azure
azd auth login
az login
-
Provision and deploy all the resources:
azd up
It will prompt you to provide an
azd
environment name (like "java-ai"), select a subscription from your Azure account, and select a location where OpenAI is available (like "eastus2"). Then it will provision the resources in your account and deploy the latest code. If you get an error or timeout with deployment, changing the location can help, as there may be availability constraints for the OpenAI resource. -
When azd has finished deploying, visit the api-gateway url and begin your experience on AI java apps.
INFO: Deploy finish succeed! INFO: Api Gateway App url: https://api-gateway.<cluster>.<region>.azurecontainerapps.io INFO: Spring Boot Admin url: https://springbootadmin-azure-java.ext.<cluster>.<region>.azurecontainerapps.io
-
When you've made any changes to the app code, you can just run:
-
azd deploy
for all services -
azd deploy -n <service>
for single service
-
For running this lab you will need:
- A GitHub account
- An Azure Subscription
-
This template uses Azure OpenAI Service deployment mododules gpt-4o and text-embedding-ada-002 which may not be available in all Azure regions. Check for up-to-date region availability and select a region during deployment accordingly
-
The template uses Azure Database for MySQL - Flexible Server version 8.0 to store data. You may select a region suite for this service. Or create a database instance manually then Reuse existing service.
- We recommend using East US, East US 2, North Central US, Sweden Central.
You can estimate the cost of this project's architecture with Azure's pricing calculator
- Azure Container Apps - Consumption
- Azure Database for MySQL - Flexible Server
- Azure OpenAI Service - Standard
- Azure Monitor - Analytics Logs
This template has Managed Identity built in to eliminate the need for developers to manage these credentials.
Applications can use managed identities to obtain Microsoft Entra tokens without having to manage any credentials. Additionally, we have added a GitHub Action tool that scans the infrastructure-as-code files and generates a report containing any detected issues. To ensure best practices in your repo we recommend anyone creating solutions based on our templates ensure that the Github secret scanning setting is enabled in your repos.
- Go to the lab for more details Deploying and running Java Applications with AI in Azure Container Apps
- Full installation guidance and options for running this lab can be found in the Installation instructions.