Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .scripts/setup-env-variables-azure-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
export STOMP_PORT=80
163 changes: 123 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,72 +38,91 @@ 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

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
```

Open `.scripts/setup-env-variables-azure.sh` and enter the following information:

```bash
# ==== Resource Group ====
export SUBSCRIPTION=subscription-id # customize this
export RESOURCE_GROUP=resource-group-name # customize this
export REGION=westeurope

Important: Enable the 'redisearch' module from the Advanced tab during the creation process.
# ==== First Instance ====
export SPRING_CLOUD_SERVICE=azure-spring-cloud-name # customize this
export APP_NAME=retail

## Install the Azure CLI extension
# ==== JARS ====
export BREWDIS_JAR=brewdis-api/build/libs/brewdis-api-1.0.0-SNAPSHOT.jar

Install the Azure Spring Cloud extension for the Azure CLI using the following command
# ==== REDIS INFO ====
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
```

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}
```
### Create resource group
```bash
az group create -n ${RESOURCE_GROUP} --location ${REGION}
```

### Change directory and build the project

### Create Redis Enterprise
```bash
cd brewdis
./gradlew build
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"
```
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 | sed 's/"//g')"
export SPRING_REDIS_PASSWORD="$(az redisenterprise database list-keys --cluster-name ${REDIS_NAME} -g ${RESOURCE_GROUP} --query primaryKey | sed 's/"//g')"
```

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.
Expand Down Expand Up @@ -134,7 +153,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.

Expand All @@ -145,7 +164,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.

Expand Down Expand Up @@ -301,6 +320,70 @@ 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.getenv("SUBSCRIPTION")
resourceGroup = System.getenv("RESOURCE_GROUP")
appName = System.getenv("WEB_APP_NAME")
pricingTier = 'P1v2'
region = System.getenv("REGION")
runtime {
os = 'Linux'
webContainer = 'Java SE'
javaVersion = 'Java 11'
}

appSettings {
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'
}
}

```

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:
Expand Down