Quickstart: Launch your first Java application in Azure Container Apps using a GitHub Repository

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:

Screenshot of the home page of the PetClinic app.

Prerequisites

Prepare the project

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

Deploy the project by using the following steps:

  1. 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>"
    
  2. 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.

  3. 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.

Verify the app status

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.

Clean up resources

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