From a808f8fe40dabc060c5a17b7a8b1ad60a9d5daac Mon Sep 17 00:00:00 2001 From: Yuchen Wang <49381248+yucwan@users.noreply.github.com> Date: Thu, 19 Aug 2021 17:45:41 +0800 Subject: [PATCH 1/4] Add steps for Azure Web Apps --- README.md | 134 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 94 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index ef09b04..aff6148 100644 --- a/README.md +++ b/README.md @@ -38,72 +38,83 @@ In addition, you will need the following: | [Git](https://git-scm.com/) | -Create an instance of Azure Cache for Redis Enterprise: -| [Step-by-step directions](https://docs.microsoft.com/en-us/azure/azure-cache-for-redis/quickstart-create-redis-enterprise) -| [Start here https://aka.ms/redis-enterprise which includes preview feature flag](https://aka.ms/redis-enterprise) -| +## Prepare your environment for deployments -Important: Enable the 'redisearch' module from the Advanced tab during the creation process. +Create a bash script with environment variables by making a copy of the supplied template: +```bash + cp .scripts/setup-env-variables-azure-template.sh .scripts/setup-env-variables-azure.sh +``` -## Install the Azure CLI extension +Open `.scripts/setup-env-variables-azure.sh` and enter the following information: -Install the Azure Spring Cloud extension for the Azure CLI using the following command +```bash + # ==== Resource Group ==== + export SUBSCRIPTION=subscription-id # customize this + export RESOURCE_GROUP=resource-group-name # customize this + export REGION=westeurope + # ==== First Instance ==== + export SPRING_CLOUD_SERVICE=azure-spring-cloud-name # customize this + export APP_NAME=retail + + # ==== JARS ==== + export BREWDIS_JAR=brewdis-api/build/libs/brewdis-api-1.0.0-SNAPSHOT.jar + + # ==== REDIS INFO ==== + export REDIS_NAME=redis-cluster-name + export SPRING_REDIS_PORT=10000 + export STOMP_HOST=${SPRING_CLOUD_SERVICE}-${APP_NAME}.azuremicroservices.io + export STOMP_PORT=80 +``` + +Then, set the environment: ```bash - az extension add --name spring-cloud + source .scripts/setup-env-variables-azure.sh ``` -## Clone and build the repo +## Create an instance of Azure Cache for Redis Enterprise -### Create a new folder and clone the sample app repository to your Azure Cloud account +### Login to the Azure CLI +Login to the Azure CLI and choose your subscription. ```bash - mkdir source-code - git clone https://github.com/selvasingh/brewdis + az login + az account list -o table + az account set --subscription ${SUBSCRIPTION} ``` -### Change directory and build the project - +### Create Redis Enterprise ```bash - cd brewdis - ./gradlew build +az redisenterprise create --cluster-name ${REDIS_NAME} -g ${RESOURCE_GROUP} --sku Enterprise_E10 --location ${REGION} --client-protocol "Plaintext" --modules name="RediSearch" --port ${SPRING_REDIS_PORT} ``` -This will take a few minutes. -## Provision Azure Spring Cloud service instance using Azure CLI +Important: Enable the 'redisearch' module from the Advanced tab if you are creating from Portal. -### Prepare your environment for deployments +Once created, query the key information and save them to environment variables: -Create a bash script with environment variables by making a copy of the supplied template: ```bash - cp .scripts/setup-env-variables-azure-template.sh .scripts/setup-env-variables-azure.sh +export SPRING_REDIS_HOST="$(az redisenterprise show --cluster-name ${REDIS_NAME} -g ${RESOURCE_GROUP} --query hostName)" +export SPRING_REDIS_PASSWORD="$(az redisenterprise database list-keys --cluster-name ${REDIS_NAME} -g ${RESOURCE_GROUP} --query primaryKey)" ``` -Open `.scripts/setup-env-variables-azure.sh` and enter the following information: +## Clone and build the repo -```bash - export SUBSCRIPTION=subscription-id # customize this - export RESOURCE_GROUP=resource-group-name # customize this - ... - export SPRING_CLOUD_SERVICE=azure-spring-cloud-name # customize this - ... - export SPRING_REDIS_HOST=redis-server-host # customize this - export SPRING_REDIS_PASSWORD=redis-password # customize this -``` +### Create a new folder and clone the sample app repository to your Azure Cloud account -Then, set the environment: ```bash - source .scripts/setup-env-variables-azure.sh + mkdir source-code + git clone https://github.com/selvasingh/brewdis ``` -### Login to the Azure CLI -Login to the Azure CLI and choose your active subscription. Be sure to choose the active subscription that is whitelisted for Azure Spring Cloud +### Change directory and build the project ```bash - az login - az account list -o table - az account set --subscription ${SUBSCRIPTION} + cd brewdis + ./gradlew build ``` +This will take a few minutes. + +## Provision Azure Spring Cloud service instance using Azure CLI and deploy the app ### Create Azure Spring Cloud service instance Prepare a name for your Azure Spring Cloud service. 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. @@ -134,7 +145,7 @@ Set your default resource group name and cluster name using the following comman spring-cloud=${SPRING_CLOUD_SERVICE} ``` -## Create a microservice application +### Create a microservice application Create Spring Cloud microservice `retail` app. @@ -145,7 +156,7 @@ Create Spring Cloud microservice `retail` app. --jvm-options='-Xms2048m -Xmx2048m' ``` -## Deploy application and set environment variables +### Deploy application and set environment variables Deploy the application to Azure. @@ -301,6 +312,49 @@ Finally, edit the workfolw file `.github/workflows/app.yml` in your forked repo ``` After you commited this change, you will see GitHub Actions triggered to build and deploy the `brewdis-api` app to your Azure Spring Cloud instance. +## Deploy the app to Azure Web Apps with Gradle plugin + +Prepare the additional environment variables + +```bash + export WEB_APP_NAME=web-app-name # customize this + export STOMP_HOST= ${WEB_APP_NAME}.azurewebsites.net # customize this +``` + +Add the below configurations in the `build.gradle` under the folder `brewdis-api`: +```xml +plugins { + id "com.microsoft.azure.azurewebapp" version "1.0.0" +} +``` + +```xml +azurewebapp { + subscription = System.getProperty("SUBSCRIPTION") + resourceGroup = System.getProperty("RESOURCE_GROUP") + appName = System.getProperty("WEB_APP_NAME") + pricingTier = 'P1v2' + region = System.getProperty("REGION") + runtime { + os = 'Linux' + webContainer = 'Java SE' // or 'Java SE' if you want to run an executable jar + javaVersion = 'Java 11' + } + + appSettings { + SPRING_REDIS_HOST=System.getProperty("SPRING_REDIS_HOST") + SPRING_REDIS_PASSWORD=System.getProperty("SPRING_REDIS_PASSWORD") + SPRING_REDIS_PORT=System.getProperty("SPRING_REDIS_PORT") + STOMP_HOST= System.getProperty("STOMP_HOST") + STOMP_PORT=System.getProperty("STOMP_PORT") + } + + auth { + type = 'azure_cli' // support azure_cli, oauth2, device_code and service_principal + } +} +``` + ## Next Steps In this quickstart, you've deployed an existing Spring Boot application using Azure CLI. To learn more about Azure Spring Cloud, go to: From 5b67cf6e2cd30a3d9cc2f4fac920bc70aa22fa36 Mon Sep 17 00:00:00 2001 From: Yuchen Wang <49381248+yucwan@users.noreply.github.com> Date: Fri, 20 Aug 2021 12:09:19 +0800 Subject: [PATCH 2/4] Update README.md --- README.md | 57 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index aff6148..940c518 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Open `.scripts/setup-env-variables-azure.sh` and enter the following information export BREWDIS_JAR=brewdis-api/build/libs/brewdis-api-1.0.0-SNAPSHOT.jar # ==== REDIS INFO ==== - export REDIS_NAME=redis-cluster-name + export REDIS_NAME=redis-cluster-name # customize this export SPRING_REDIS_PORT=10000 export STOMP_HOST=${SPRING_CLOUD_SERVICE}-${APP_NAME}.azuremicroservices.io export STOMP_PORT=80 @@ -85,7 +85,11 @@ Login to the Azure CLI and choose your subscription. ### Create Redis Enterprise ```bash -az redisenterprise create --cluster-name ${REDIS_NAME} -g ${RESOURCE_GROUP} --sku Enterprise_E10 --location ${REGION} --client-protocol "Plaintext" --modules name="RediSearch" --port ${SPRING_REDIS_PORT} + az redisenterprise create --cluster-name ${REDIS_NAME} \ + -g ${RESOURCE_GROUP} --location ${REGION} \ + --port ${SPRING_REDIS_PORT} \ + --sku Enterprise_E10 --client-protocol "Plaintext" \ + --modules name="RediSearch" --eviction-policy "NoEviction" ``` Important: Enable the 'redisearch' module from the Advanced tab if you are creating from Portal. @@ -93,8 +97,8 @@ Important: Enable the 'redisearch' module from the Advanced tab if you are creat Once created, query the key information and save them to environment variables: ```bash -export SPRING_REDIS_HOST="$(az redisenterprise show --cluster-name ${REDIS_NAME} -g ${RESOURCE_GROUP} --query hostName)" -export SPRING_REDIS_PASSWORD="$(az redisenterprise database list-keys --cluster-name ${REDIS_NAME} -g ${RESOURCE_GROUP} --query primaryKey)" +export SPRING_REDIS_HOST="$(az redisenterprise show --cluster-name ${REDIS_NAME} -g ${RESOURCE_GROUP} --query hostName | sed 's/"//g')" +export SPRING_REDIS_PASSWORD="$(az redisenterprise database list-keys --cluster-name ${REDIS_NAME} -g ${RESOURCE_GROUP} --query primaryKey | sed 's/"//g')" ``` ## Clone and build the repo @@ -318,7 +322,7 @@ Prepare the additional environment variables ```bash export WEB_APP_NAME=web-app-name # customize this - export STOMP_HOST= ${WEB_APP_NAME}.azurewebsites.net # customize this + export STOMP_HOST=${WEB_APP_NAME}.azurewebsites.net # customize this ``` Add the below configurations in the `build.gradle` under the folder `brewdis-api`: @@ -330,31 +334,52 @@ plugins { ```xml azurewebapp { - subscription = System.getProperty("SUBSCRIPTION") - resourceGroup = System.getProperty("RESOURCE_GROUP") - appName = System.getProperty("WEB_APP_NAME") + subscription = System.getenv("SUBSCRIPTION") + resourceGroup = System.getenv("RESOURCE_GROUP") + appName = System.getenv("WEB_APP_NAME") pricingTier = 'P1v2' - region = System.getProperty("REGION") + region = System.getenv("REGION") runtime { os = 'Linux' - webContainer = 'Java SE' // or 'Java SE' if you want to run an executable jar + webContainer = 'Java SE' javaVersion = 'Java 11' } appSettings { - SPRING_REDIS_HOST=System.getProperty("SPRING_REDIS_HOST") - SPRING_REDIS_PASSWORD=System.getProperty("SPRING_REDIS_PASSWORD") - SPRING_REDIS_PORT=System.getProperty("SPRING_REDIS_PORT") - STOMP_HOST= System.getProperty("STOMP_HOST") - STOMP_PORT=System.getProperty("STOMP_PORT") + SPRING_REDIS_HOST=System.getenv("SPRING_REDIS_HOST") + SPRING_REDIS_PASSWORD=System.getenv("SPRING_REDIS_PASSWORD") + SPRING_REDIS_PORT=System.getenv("SPRING_REDIS_PORT") + STOMP_HOST=System.getenv("STOMP_HOST") + STOMP_PORT=System.getenv("STOMP_PORT") } auth { - type = 'azure_cli' // support azure_cli, oauth2, device_code and service_principal + type = 'azure_cli' } } + +``` + +Deploy the application to Azure. +```bash +gradle azureWebAppDeploy +``` + +Navigate to the URL provided by the previous command to open the brewdis application. + +![](./media/Brewdis-inventory.jpg) +![](./media/Brewdis-catalog.jpg) + +### Open logstream + +You can open the log stream from your development machine. + +```bash + az webapp log tail --name ${WEB_APP_NAME} --resource-group ${RESOURCE_GROUP} ``` +![](./media/az-spring-cloud-logs.jpg) + ## Next Steps In this quickstart, you've deployed an existing Spring Boot application using Azure CLI. To learn more about Azure Spring Cloud, go to: From a478cdf45aba7f6c64454fafc206edb108c21411 Mon Sep 17 00:00:00 2001 From: Yuchen Wang <49381248+yucwan@users.noreply.github.com> Date: Fri, 20 Aug 2021 12:10:08 +0800 Subject: [PATCH 3/4] Update setup-env-variables-azure-template.sh --- .scripts/setup-env-variables-azure-template.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.scripts/setup-env-variables-azure-template.sh b/.scripts/setup-env-variables-azure-template.sh index 0467dc9..77811ec 100755 --- a/.scripts/setup-env-variables-azure-template.sh +++ b/.scripts/setup-env-variables-azure-template.sh @@ -13,9 +13,7 @@ export APP_NAME=retail export BREWDIS_JAR=brewdis-api/build/libs/brewdis-api-1.0.0-SNAPSHOT.jar # ==== REDIS INFO ==== -export SPRING_REDIS_HOST=redis-server-host # customize this -export SPRING_REDIS_PASSWORD=redis-password # customize this +export REDIS_NAME=redis-cluster-name # customize this export SPRING_REDIS_PORT=10000 export STOMP_HOST=${SPRING_CLOUD_SERVICE}-${APP_NAME}.azuremicroservices.io -#export STOMP_HOST=localhost -export STOMP_PORT=80 \ No newline at end of file +export STOMP_PORT=80 From d6fcf5ddeba65f190c872f05c800c0f32fcc48e9 Mon Sep 17 00:00:00 2001 From: Yuchen Wang <49381248+yucwan@users.noreply.github.com> Date: Mon, 30 Aug 2021 22:39:01 +0800 Subject: [PATCH 4/4] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 940c518..42468df 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,10 @@ Login to the Azure CLI and choose your subscription. az account list -o table az account set --subscription ${SUBSCRIPTION} ``` +### Create resource group +```bash + az group create -n ${RESOURCE_GROUP} --location ${REGION} +``` ### Create Redis Enterprise ```bash