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

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 tier ✔️ Enterprise tier

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

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 tier. This step is necessary only if your subscription has never been used to create an Enterprise tier 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 Azure Spring Apps Enterprise tier. For more information, see the Azure Spring Apps FAQ.

  4. Use the following command to create a resource group:

    az group create \
        --name <resource-group-name> \
        --location <location>
    

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

  5. Prepare a name for your Azure Spring Apps service instance. The name 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.

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

    az spring create \
        --resource-group <resource-group-name> \
        --name <Azure-Spring-Apps-service-instance-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-name> \
        --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:

    LOG_ANALYTICS_RESOURCE_ID=$(az monitor log-analytics workspace show \
        --resource-group <resource-group-name> \
        --workspace-name <workspace-name> | jq -r '.id')
    
    SPRING_CLOUD_RESOURCE_ID=$(az spring show \
        --resource-group <resource-group-name> \
        --name <Azure-Spring-Apps-service-instance-name> | jq -r '.id')
    
  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 ${SPRING_CLOUD_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> \
        --name cart-service \
        --service <Azure-Spring-Apps-service-instance-name>
    
    az spring app create \
        --resource-group <resource-group-name> \
        --name order-service \
        --service <Azure-Spring-Apps-service-instance-name>
    
    az spring app create \
        --resource-group <resource-group-name> \
        --name payment-service \
        --service <Azure-Spring-Apps-service-instance-name>
    
    az spring app create \
        --resource-group <resource-group-name> \
        --name catalog-service
        --service <Azure-Spring-Apps-service-instance-name>
    
    az spring app create \
        --resource-group <resource-group-name> \
        --name frontend \
        --service <Azure-Spring-Apps-service-instance-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> \
        --name acme-fitness-store-config \
        --service <Azure-Spring-Apps-service-instance-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-name> \
        --app payment-service \
        --service <Azure-Spring-Apps-service-instance-name>
    
    az spring application-configuration-service bind \
        --resource-group <resource-group-name> \
        --app catalog-service \
        --service <Azure-Spring-Apps-service-instance-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-name> \
    --app payment-service \
    --service <Azure-Spring-Apps-service-instance-name>

az spring service-registry bind \
    --resource-group <resource-group-name> \
    --app catalog-service \
    --service <Azure-Spring-Apps-service-instance-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> \
        --name quickstart-builder \
        --service <Azure-Spring-Apps-service-instance-name> \
        --builder-file azure/builder.json
    
  2. Use the following command to build and deploy the payment service:

    az spring app deploy \
        --resource-group <resource-group-name> \
        --name payment-service \
        --service <Azure-Spring-Apps-service-instance-name> \
        --config-file-pattern payment/default \
        --source-path apps/acme-payment
    
  3. Use the following command to build and deploy the catalog service:

    az spring app deploy \
        --resource-group <resource-group-name> \
        --name catalog-service \
        --service <Azure-Spring-Apps-service-instance-name> \
        --config-file-pattern catalog/default \
        --source-path apps/acme-catalog
    
  4. Use the following command to build and deploy the order service:

    az spring app deploy \
        --resource-group <resource-group-name> \
        --name order-service \
        --service <Azure-Spring-Apps-service-instance-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> \
        --name cart-service \
        --service <Azure-Spring-Apps-service-instance-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> \
        --name frontend \
        --service <Azure-Spring-Apps-service-instance-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-name> \
        --service <Azure-Spring-Apps-service-instance-name> \
        --assign-endpoint true
    
  2. Use the following commands to configure Spring Cloud Gateway API information:

    GATEWAY_URL=$(az spring gateway show \
        --resource-group <resource-group-name> \
        --service <Azure-Spring-Apps-service-instance-name> | jq -r '.properties.url')
    
    az spring gateway update \
        --resource-group <resource-group-name> \
        --service <Azure-Spring-Apps-service-instance-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> \
        --name cart-routes \
        --service <Azure-Spring-Apps-service-instance-name> \
        --app-name cart-service \
        --routes-file azure/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> \
        --name order-routes \
        --service <Azure-Spring-Apps-service-instance-name> \
        --app-name order-service \
        --routes-file azure/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> \
        --name catalog-routes \
        --service <Azure-Spring-Apps-service-instance-name> \
        --app-name catalog-service \
        --routes-file azure/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> \
        --name frontend-routes \
        --service <Azure-Spring-Apps-service-instance-name> \
        --app-name frontend \
        --routes-file azure/routes/frontend.json
    
  7. Use the following commands to retrieve the URL for Spring Cloud Gateway:

    GATEWAY_URL=$(az spring gateway show \
        --resource-group <resource-group-name> \
        --service <Azure-Spring-Apps-service-instance-name> | jq -r '.properties.url')
    
    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-name> \
        --service <Azure-Spring-Apps-service-instance-name> \
        --assign-endpoint true
    
  2. Use the following commands to retrieve the URL for API Portal:

    PORTAL_URL=$(az spring api-portal show \
        --resource-group <resource-group-name> \
        --service <Azure-Spring-Apps-service-instance-name> | jq -r '.properties.url')
    
    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: