-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor sample_spring-petclinic-microservices. #186
Merged
backwind1233
merged 6 commits into
Azure-Samples:spring-cloud-azure_4.0.0-beta.4
from
hui1110:yonghui/spring-petclinic-sample
Feb 21, 2022
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
170db0f
refactor sample spring-petclinic-sample .
hui-00 34f6b57
conflict resolution.
hui-00 7af9dd5
Optimize the code, update the README.md
hui-00 2426b70
Merge branch 'spring-cloud-azure_4.0.0-beta.4' of github.com:Azure-Sa…
hui-00 4db9461
Merge branch 'spring-cloud-azure_4.0.0-beta.4' of github.com:Azure-Sa…
hui-00 6706d41
Update README.md.
hui-00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,48 +45,137 @@ 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 | ||
This sample will create Azure resources using Terraform. If you choose to run it without using Terraform to provision resources, please pay attention to: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete this here
|
||
> [!IMPORTANT] | ||
> If you choose to use a security principal to authenticate and authorize with Azure Active Directory for accessing an Azure resource | ||
> please refer to [Authorize access with Azure AD](https://microsoft.github.io/spring-cloud-azure/current/reference/html/index.html#authorize-access-with-azure-active-directory) to make sure the security principal has been granted the sufficient permission to access the Azure resource. | ||
|
||
### 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": "your-username@domain.com", | ||
"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.kv: Creating... | ||
azurecaf_name.cosmos: Creating... | ||
azurecaf_name.resource_group: 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: 5 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. | ||
|
||
### 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) | ||
``` | ||
|
||
## Starting services locally with docker-compose | ||
|
||
In order to start entire infrastructure using Docker, you have to build images by | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It failed for me to run the samples with docker, can you check and run it locally?