Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article shows you how to deploy the Spring PetClinic sample application to Azure Container Apps using a GitHub repository.
There are several options available for deploying Java applications, including the following options:
- Deployment from a local file system or from a code repository.
- Deployment using Maven or an IDE.
- Deployment using a WAR file, a JAR file, or directly from source code.
By the end of this tutorial, you deploy a web application that you can manage through the Azure portal. The following screenshot shows the home page of the PetClinic application deployed to Azure Container Apps:
- An Azure subscription. Create one for free..
- The
Contributor
orOwner
permission on the Azure subscription. For more information, see Assign Azure roles using the Azure portal. - A GitHub account.
- Git
- Azure CLI
- The Azure Container Apps CLI extension, version 0.3.47 or higher. Use the following command to install the latest version:
az extension add --name containerapp --upgrade --allow-preview
- The Java Development Kit, version 17 or later.
- Apache Maven
Use the Fork button on the Azure Container Apps Java Samples repo page to fork the repo to your personal GitHub account. When the fork is complete, copy the fork's URL for use in the next section.
Deploy the project by using the following steps:
Set the necessary environment variables by using the following commands:
export RESOURCE_GROUP="pet-clinic-container-apps" export LOCATION="canadacentral" export ENVIRONMENT="env-pet-clinic-container-apps" export CONTAINER_APP_NAME="pet-clinic" export REPO_URL="<URL-of-your-GitHub-repo-fork>"
Sign in to Azure from the CLI if you aren't already signed in. For more information, see the Setup section of Quickstart: Build and deploy from local source code to Azure Container Apps.
Build and deploy your Spring Boot app by using the following command:
az containerapp up \ --resource-group $RESOURCE_GROUP \ --name $CONTAINER_APP_NAME \ --location $LOCATION \ --environment $ENVIRONMENT \ --context-path ./spring-petclinic \ --repo $REPO_URL
This command performs the following tasks:
- Creates the resource group.
- Creates an Azure container registry.
- Builds the container image and pushes it to the registry.
- Creates the Container Apps environment with a Log Analytics workspace.
- Creates and deploys the container app by using the built container image.
The project is now deployed. When you push new code to the repository, a GitHub Action performs the following tasks:
- Builds the container image and pushes it to the Azure container registry.
- Deploys the container image to the created container app.
After the deployment finishes, go to the Azure portal Overview page of your container app and select Application Url to see the application running in the cloud.
If you plan to continue working with more quickstarts and tutorials, you might want to leave these resources in place. When you no longer need the resources, you can remove them to avoid Azure charges, by using the following command:
az group delete --name $RESOURCE_GROUP