Quickstart: Build and deploy apps to Azure Spring Apps using the Enterprise plan

Note

Azure Spring Apps is the new name for the Azure Spring Cloud service. Although the service has a new name, you'll see the old name in some places for a while as we work to update assets such as screenshots, videos, and diagrams.

This article applies to: ❌ Basic/Standard ✔️ Enterprise

This quickstart shows you how to build and deploy applications to Azure Spring Apps using the Enterprise plan.

Prerequisites

Download the sample app

Use the following commands to download the sample:

git clone https://github.com/Azure-Samples/acme-fitness-store
cd acme-fitness-store

Provision a service instance

Use the following steps to provision an Azure Spring Apps service instance.

  1. Use the following command to sign in to the Azure CLI and choose your active subscription:

    az login
    az account list --output table
    az account set --subscription <subscription-ID>
    
  2. Use the following command to accept the legal terms and privacy statements for the Enterprise plan. This step is necessary only if your subscription has never been used to create an Enterprise plan instance of Azure Spring Apps.

    az provider register --namespace Microsoft.SaaS
    az term accept \
        --publisher vmware-inc \
        --product azure-spring-cloud-vmware-tanzu-2 \
        --plan asa-ent-hr-mtr
    
  3. Select a location. This location must be a location supporting the Azure Spring Apps Enterprise plan. For more information, see the Azure Spring Apps FAQ.

  4. Create variables to hold the resource names by using the following commands. Be sure to replace the placeholders with your own values. The name of your Azure Spring Apps service instance must be between 4 and 32 characters long and can contain only lowercase letters, numbers, and hyphens. The first character of the service name must be a letter and the last character must be either a letter or a number.

    export LOCATION="<location>"
    export RESOURCE_GROUP="<resource-group-name>"
    export SERVICE_NAME="<Azure-Spring-Apps-service-instance-name>"
    export WORKSPACE_NAME="<workspace-name>"
    
  5. Use the following command to create a resource group:

    az group create \
        --name ${RESOURCE_GROUP} \
        --location ${LOCATION}
    

    For more information about resource groups, see What is Azure Resource Manager?.

  6. Use the following command to create an Azure Spring Apps service instance:

    az spring create \
        --resource-group ${RESOURCE_GROUP} \
        --name ${SERVICE_NAME} \
        --sku enterprise \
        --enable-application-configuration-service \
        --enable-service-registry \
        --enable-gateway \
        --enable-api-portal
    
  7. Use the following command to create a Log Analytics Workspace to be used for your Azure Spring Apps service:

    az monitor log-analytics workspace create \
        --resource-group ${RESOURCE_GROUP} \
        --workspace-name ${WORKSPACE_NAME} \
        --location ${LOCATION}
    
  8. Use the following commands to retrieve the Resource ID for your Log Analytics Workspace and Azure Spring Apps service instance:

    export LOG_ANALYTICS_RESOURCE_ID=$(az monitor log-analytics workspace show \
        --resource-group ${RESOURCE_GROUP} \
        --workspace-name ${WORKSPACE_NAME} \
        --query id \
        --output tsv)
    
    export AZURE_SPRING_APPS_RESOURCE_ID=$(az spring show \
        --resource-group ${RESOURCE_GROUP} \
        --name ${SERVICE_NAME} \
        --query id \
        --output tsv)
    
  9. Use the following command to configure diagnostic settings for the Azure Spring Apps Service:

    az monitor diagnostic-settings create \
        --name "send-logs-and-metrics-to-log-analytics" \
        --resource ${AZURE_SPRING_APPS_RESOURCE_ID} \
        --workspace ${LOG_ANALYTICS_RESOURCE_ID} \
        --logs '[
             {
               "category": "ApplicationConsole",
               "enabled": true,
               "retentionPolicy": {
                 "enabled": false,
                 "days": 0
               }
             },
             {
                "category": "SystemLogs",
                "enabled": true,
                "retentionPolicy": {
                  "enabled": false,
                  "days": 0
                }
              },
             {
                "category": "IngressLogs",
                "enabled": true,
                "retentionPolicy": {
                  "enabled": false,
                  "days": 0
                 }
               }
           ]' \
           --metrics '[
             {
               "category": "AllMetrics",
               "enabled": true,
               "retentionPolicy": {
                 "enabled": false,
                 "days": 0
               }
             }
           ]'
    
  10. Use the following commands to create applications for cart-service, order-service, payment-service, catalog-service, and frontend:

    az spring app create \
        --resource-group ${RESOURCE_GROUP} \
        --name cart-service \
        --service ${SERVICE_NAME}
    
    az spring app create \
        --resource-group ${RESOURCE_GROUP} \
        --name order-service \
        --service ${SERVICE_NAME}
    
    az spring app create \
        --resource-group ${RESOURCE_GROUP} \
        --name payment-service \
        --service ${SERVICE_NAME}
    
    az spring app create \
        --resource-group ${RESOURCE_GROUP} \
        --name catalog-service \
        --service ${SERVICE_NAME}
    
    az spring app create \
        --resource-group ${RESOURCE_GROUP} \
        --name frontend \
        --service ${SERVICE_NAME}
    

Externalize configuration with Application Configuration Service

Use the following steps to configure Application Configuration Service.

  1. Use the following command to create a configuration repository for Application Configuration Service:

    az spring application-configuration-service git repo add \
        --resource-group ${RESOURCE_GROUP} \
        --name acme-fitness-store-config \
        --service ${SERVICE_NAME} \
        --label main \
        --patterns "catalog/default,catalog/key-vault,identity/default,identity/key-vault,payment/default" \
        --uri "https://github.com/Azure-Samples/acme-fitness-store-config"
    
  2. Use the following commands to bind applications to Application Configuration Service:

    az spring application-configuration-service bind \
        --resource-group ${RESOURCE_GROUP} \
        --app payment-service \
        --service ${SERVICE_NAME}
    
    az spring application-configuration-service bind \
        --resource-group ${RESOURCE_GROUP} \
        --app catalog-service \
        --service ${SERVICE_NAME}
    

Activate service registration and discovery

To active service registration and discovery, use the following commands to bind applications to Service Registry:

az spring service-registry bind \
    --resource-group ${RESOURCE_GROUP} \
    --app payment-service \
    --service ${SERVICE_NAME}

az spring service-registry bind \
    --resource-group ${RESOURCE_GROUP} \
    --app catalog-service \
    --service ${SERVICE_NAME}

Deploy polyglot applications with Tanzu Build Service

Use the following steps to deploy and build applications. For these steps, make sure that the terminal is in the project folder before running any commands.

  1. Use the following command to create a custom builder in Tanzu Build Service:

    az spring build-service builder create \
        --resource-group ${RESOURCE_GROUP} \
        --name quickstart-builder \
        --service ${SERVICE_NAME} \
        --builder-file azure-spring-apps-enterprise/resources/json/tbs/builder.json
    
  2. Use the following command to build and deploy the payment service:

    az spring app deploy \
        --resource-group ${RESOURCE_GROUP} \
        --name payment-service \
        --service ${SERVICE_NAME} \
        --config-file-pattern payment/default \
        --source-path apps/acme-payment \
        --build-env BP_JVM_VERSION=17
    
  3. Use the following command to build and deploy the catalog service:

    az spring app deploy \
        --resource-group ${RESOURCE_GROUP} \
        --name catalog-service \
        --service ${SERVICE_NAME} \
        --config-file-pattern catalog/default \
        --source-path apps/acme-catalog \
        --build-env BP_JVM_VERSION=17
    
  4. Use the following command to build and deploy the order service:

    az spring app deploy \
        --resource-group ${RESOURCE_GROUP} \
        --name order-service \
        --service ${SERVICE_NAME} \
        --builder quickstart-builder \
        --source-path apps/acme-order
    
  5. Use the following command to build and deploy the cart service:

    az spring app deploy \
        --resource-group ${RESOURCE_GROUP} \
        --name cart-service \
        --service ${SERVICE_NAME} \
        --builder quickstart-builder \
        --env "CART_PORT=8080" \
        --source-path apps/acme-cart
    
  6. Use the following command to build and deploy the frontend application:

    az spring app deploy \
        --resource-group ${RESOURCE_GROUP} \
        --name frontend \
        --service ${SERVICE_NAME} \
        --source-path apps/acme-shopping
    

Tip

To troubleshot deployments, you can use the following command to get logs streaming in real time whenever the app is running: az spring app logs --name <app name> --follow.

Route requests to apps with Spring Cloud Gateway

Use the following steps to configure Spring Cloud Gateway and configure routes to applications.

  1. Use the following command to assign an endpoint to Spring Cloud Gateway:

    az spring gateway update \
        --resource-group ${RESOURCE_GROUP} \
        --service ${SERVICE_NAME} \
        --assign-endpoint true
    
  2. Use the following commands to configure Spring Cloud Gateway API information:

    export GATEWAY_URL=$(az spring gateway show \
        --resource-group ${RESOURCE_GROUP} \
        --service ${SERVICE_NAME} \
        --query properties.url \
        --output tsv)
    
    az spring gateway update \
        --resource-group ${RESOURCE_GROUP} \
        --service ${SERVICE_NAME} \
        --api-description "Fitness Store API" \
        --api-title "Fitness Store" \
        --api-version "v1.0" \
        --server-url "https://${GATEWAY_URL}" \
        --allowed-origins "*"
    
  3. Use the following command to create routes for the cart service:

    az spring gateway route-config create \
        --resource-group ${RESOURCE_GROUP} \
        --name cart-routes \
        --service ${SERVICE_NAME} \
        --app-name cart-service \
        --routes-file azure-spring-apps-enterprise/resources/json/routes/cart-service.json
    
  4. Use the following command to create routes for the order service:

    az spring gateway route-config create \
        --resource-group ${RESOURCE_GROUP} \
        --name order-routes \
        --service ${SERVICE_NAME} \
        --app-name order-service \
        --routes-file azure-spring-apps-enterprise/resources/json/routes/order-service.json
    
  5. Use the following command to create routes for the catalog service:

    az spring gateway route-config create \
        --resource-group ${RESOURCE_GROUP} \
        --name catalog-routes \
        --service ${SERVICE_NAME} \
        --app-name catalog-service \
        --routes-file azure-spring-apps-enterprise/resources/json/routes/catalog-service.json
    
  6. Use the following command to create routes for the frontend:

    az spring gateway route-config create \
        --resource-group ${RESOURCE_GROUP} \
        --name frontend-routes \
        --service ${SERVICE_NAME} \
        --app-name frontend \
        --routes-file azure-spring-apps-enterprise/resources/json/routes/frontend.json
    
  7. Use the following commands to retrieve the URL for Spring Cloud Gateway:

    export GATEWAY_URL=$(az spring gateway show \
        --resource-group ${RESOURCE_GROUP} \
        --service ${SERVICE_NAME} \
        --query properties.url \
        --output tsv)
    
    echo "https://${GATEWAY_URL}"
    

    You can open the output URL in a browser to explore the deployed application.

Browse and try APIs with API Portal

Use the following steps to configure API Portal.

  1. Use the following command to assign an endpoint to API Portal:

    az spring api-portal update \
        --resource-group ${RESOURCE_GROUP} \
        --service ${SERVICE_NAME} \
        --assign-endpoint true
    
  2. Use the following commands to retrieve the URL for API Portal:

    export PORTAL_URL=$(az spring api-portal show \
        --resource-group ${RESOURCE_GROUP} \
        --service ${SERVICE_NAME} \
        --query properties.url \
        --output tsv)
    
    echo "https://${PORTAL_URL}"
    

    You can open the output URL in a browser to explore the application APIs.


Clean up resources

If you plan to continue working with subsequent quickstarts and tutorials, you might want to leave these resources in place. When no longer needed, delete the resource group, which deletes the resources in the resource group. To delete the resource group by using Azure CLI, use the following commands:

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."

Next steps

Now that you've successfully built and deployed your app, continue on to any of the following optional quickstarts: