-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor sample_spring-petclinic-microservices. (#186)
- Loading branch information
Showing
28 changed files
with
551 additions
and
573 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,21 +18,16 @@ You will: | |
|
||
## What you will need | ||
|
||
In order to deploy a Java app to cloud, you need an Azure subscription. If you do not already have | ||
an Azure subscription, you can activate your | ||
[MSDN subscriber benefits](https://azure.microsoft.com/pricing/member-offers/msdn-benefits-details/) | ||
or sign up for a | ||
[free Azure account]((https://azure.microsoft.com/free/)). | ||
|
||
In addition, you will need the following: | ||
|
||
- [Azure CLI version 2.0.67 or higher](https://docs.microsoft.com/cli/azure/install-azure-cli?view=azure-cli-latest) | ||
- [Java 8](https://www.azul.com/downloads/azure-only/zulu/?version=java-8-lts&architecture=x86-64-bit&package=jdk) | ||
- [Maven](https://maven.apache.org/download.cgi) | ||
- [An Azure subscription](https://azure.microsoft.com/free/) | ||
- [Terraform](https://www.terraform.io/) | ||
- [JDK8](https://www.oracle.com/java/technologies/downloads/) or later | ||
- [MySQL CLI](https://dev.mysql.com/downloads/shell/) | ||
- [Git](https://git-scm.com/) | ||
- [Jq](https://stedolan.github.io/jq/) | ||
|
||
- [Maven](https://maven.apache.org/download.cgi) | ||
- You can also import the code straight into your IDE: | ||
- [IntelliJ IDEA](https://www.jetbrains.com/idea/download) | ||
|
||
## Clone and build the repo | ||
|
||
### Clone the sample app repository | ||
|
@@ -50,44 +45,113 @@ In addition, you will need the following: | |
|
||
This will take a few minutes. | ||
|
||
## Provision Azure resources using Azure CLI | ||
## Provision Azure Resources Required to Run This Sample | ||
|
||
### Login to Azure | ||
### Authenticate Using the Azure CLI | ||
Terraform must authenticate to Azure to create infrastructure. | ||
|
||
Login to the Azure CLI and choose your active subscription. Be sure to choose the active | ||
subscription that is whitelisted for Azure Spring Cloud | ||
In your terminal, use the Azure CLI tool to setup your account permissions locally. | ||
|
||
```bash | ||
az login | ||
az account list -o table | ||
az account set --subscription ${SUBSCRIPTION} | ||
```shell | ||
az login | ||
``` | ||
|
||
### Prepare your environment for deployments | ||
Your browser window will open and you will be prompted to enter your Azure login credentials. After successful authentication, your terminal will display your subscription information. You do not need to save this output as it is saved in your system for Terraform to use. | ||
|
||
Create a bash script with environment variables by making a copy of the supplied template: | ||
```shell | ||
You have logged in. Now let us find all the subscriptions to which you have access... | ||
|
||
[ | ||
{ | ||
"cloudName": "AzureCloud", | ||
"homeTenantId": "home-Tenant-Id", | ||
"id": "subscription-id", | ||
"isDefault": true, | ||
"managedByTenants": [], | ||
"name": "Subscription-Name", | ||
"state": "Enabled", | ||
"tenantId": "0envbwi39-TenantId", | ||
"user": { | ||
"name": "[email protected]", | ||
"type": "user" | ||
} | ||
} | ||
] | ||
``` | ||
|
||
```bash | ||
cp .scripts/setup-env-variables-azure-template.sh .scripts/setup-env-variables-azure.sh | ||
If you have more than one subscription, specify the subscription-id you want to use with command below: | ||
```shell | ||
az account set --subscription <your-subscription-id> | ||
``` | ||
|
||
Open `.scripts/setup-env-variables-azure.sh` and enter the following information: | ||
### Provision the Resources | ||
|
||
```bash | ||
After login Azure CLI with your account, now you can use the terraform script to create Azure Resources. | ||
|
||
#### Run with Bash | ||
|
||
```shell | ||
# In the root directory of the sample | ||
# Initialize your Terraform configuration | ||
terraform -chdir=./terraform init | ||
|
||
# Apply your Terraform Configuration | ||
terraform -chdir=./terraform apply -auto-approve | ||
|
||
export RESOURCE_GROUP=resource-group-name # customize this | ||
export LOCATION=SouthCentralUS #customize this | ||
export COSMOSDB_NAME=mycosmosdbaccname # customize this | ||
export REDIS_NAME=myredisname #customize this | ||
export KEYVAULT_NAME=myend2endkv #customize this | ||
export APP_NAME_FOR_KEYVAULT=myappforkeyvault #customize this | ||
|
||
``` | ||
|
||
Then, set the environment: | ||
#### Run with Powershell | ||
|
||
```bash | ||
source .scripts/setup-env-variables-azure.sh | ||
```shell | ||
# In the root directory of the sample | ||
# Initialize your Terraform configuration | ||
terraform -chdir=terraform init | ||
|
||
# Apply your Terraform Configuration | ||
terraform -chdir=terraform apply -auto-approve | ||
|
||
``` | ||
|
||
It may take a few minutes to run the script. After successful running, you will see prompt information like below: | ||
|
||
```shell | ||
azurecaf_name.resource_group: Creating... | ||
azurecaf_name.redis: Creating... | ||
azurecaf_name.service-principal: Creating... | ||
azurecaf_name.cosmos: Creating... | ||
azurecaf_name.kv: Creating... | ||
... | ||
azurerm_resource_group.main: Creating... | ||
... | ||
azurerm_key_vault.kv_account: Creating... | ||
azurerm_cosmosdb_account.application: Creating... | ||
azurerm_key_vault.kv_account: Still creating... [10s elapsed] | ||
... | ||
|
||
Apply complete! Resources: 8 added, 0 changed, 0 destroyed. | ||
|
||
Outputs: | ||
... | ||
``` | ||
|
||
You can go to [Azure portal](https://ms.portal.azure.com/) in your web browser to check the resources you created. | ||
|
||
### Export Output to Your Local Environment | ||
|
||
#### Run with Bash | ||
|
||
Running the command below to export environment values: | ||
|
||
```shell | ||
source ./terraform/setup_env.sh | ||
``` | ||
|
||
#### Run with Powershell | ||
|
||
Running the command below to export environment values: | ||
|
||
```shell | ||
. terraform\setup_env.ps1 | ||
``` | ||
|
||
make sure keyvault.env file is created at the root of the repo. | ||
|
@@ -113,6 +177,24 @@ Containers startup order is coordinated with [`dockerize` script](https://github | |
Cloud Gateway timeouts. | ||
You can track services availability using Eureka dashboard available by default at `http://localhost:8761`. | ||
|
||
## Clean Up Resources | ||
After running the sample, if you don't want to run the sample, remember to destroy the Azure resources you created to avoid unnecessary billing. | ||
|
||
The terraform destroy command terminates resources managed by your Terraform project. | ||
To destroy the resources you created. | ||
|
||
### Run with Bash | ||
|
||
```shell | ||
az group delete --name $(terraform -chdir=./terraform output -raw resource_group_name) | ||
``` | ||
|
||
### Run with Powershell | ||
|
||
```shell | ||
az group delete --name $(terraform -chdir=terraform output -raw resource_group_name) | ||
``` | ||
|
||
## Understanding the Spring Petclinic application | ||
|
||
[See the presentation of the Spring Petclinic Framework version](http://fr.slideshare.net/AntoineRey/spring-framework-petclinic-sample-application) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.