Skip to content

Commit 1683b31

Browse files
authored
add steps for azd automation (#57)
## Purpose And fix doc order issue ## Does this introduce a breaking change? <!-- Mark one with an "x". --> ``` [ ] Yes [x] No ``` ## Pull Request Type What kind of change does this Pull Request introduce? <!-- Please check the one that applies to this PR using "x". --> ``` [x] Bugfix [x] Feature [ ] Code style update (formatting, local variables) [ ] Refactoring (no functional changes, no api changes) [x] Documentation content changes [ ] Other... Please describe: ```
1 parent d04f42e commit 1683b31

26 files changed

+184
-224
lines changed

azure.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json
22

33
name: java-microservices-aca-lab
4-
resourceGroup: rg-petclinic
54
infra:
65
provider: bicep
76
path: infra/bicep

docs/02_lab_migrate/0203.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Your MySQL database will also have a firewall enabled. This firewall will by def
5959
--rule-name allAzureIPs \
6060
--name ${MYSQL_SERVER_NAME} \
6161
--resource-group ${RESOURCE_GROUP} \
62-
--start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0
62+
--start-ip-address 0.0.0.0 --end-ip-address 255.255.255.255
6363
```
6464

6565
1. From the Git Bash window, in the config repository you cloned locally, use your favorite text editor to open the _application.yml_ file. Replace the full contents of the _application.yml_ file with the contents of [this application.yml](0203_application.yml) file. The updated _application.yml_ file includes the following changes:
@@ -70,7 +70,7 @@ Your MySQL database will also have a firewall enabled. This firewall will by def
7070
* It adds extra `eureka` config on lines 61 to 66.
7171
* It removes the `chaos-monkey` and `mysql` profiles.
7272

73-
1. In the part you pasted, update the values of the target datasource endpoint on line 12, the corresponding admin user account on line 13, and its password on line 14 to match your configuration. Set these values by using the information in the Azure Database for MySQL Flexible Server connection string you recorded earlier in this task.
73+
1. In the part you pasted, update the values of the target datasource endpoint on line 6, the corresponding admin user account on line 7, and its password on line 8 to match your configuration. Set these values by using the information in the Azure Database for MySQL Flexible Server connection string you recorded earlier in this task.
7474

7575
1. Save the changes and push the updates you made to the _application.yml_ file to your private GitHub repo by running the following commands from the Git Bash prompt:
7676

docs/06_lab_automation/0601.md

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,67 @@
11
---
2-
title: '1. Prepare the configuration'
2+
title: '1. Prepare the environment'
33
layout: default
44
nav_order: 1
5-
parent: 'Lab 8: Use Azd to deploy the lab solution'
5+
parent: 'Lab 6: Deploy to Azure automatically'
66
---
77

8-
# 1. Prepare the configuration
8+
# 1. Prepare the environment
99

10-
Fill the configuration file according to your environment.
10+
Prepare your local environment and plan your Azure resource, get ready for the one-click deployment.
11+
12+
{: .note }
13+
> This automation guide is tested in linux environment only. Here we use WSL environment to run the automation tool.
1114
1215
## Step by step guidance
1316

14-
1. If you want to use azd to deploy from a new environment, prepare your images in Azure Container Registry
17+
1. Install WSL environment
18+
Note: you may skip this step if you are using other linux environment.
19+
Install WSL to your windows system [How to install Linux on Windows with WSL](https://learn.microsoft.com/en-us/windows/wsl/install)
1520

16-
```bash
17-
APPNAME=petclinic
18-
RESOURCE_GROUP=rg-$APPNAME
21+
1. Install tools
22+
23+
- Follow this guide to install azd tool to your WSL environment: [Install Azd](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/install-azd?tabs=winget-windows%2Cbrew-mac%2Cscript-linux&pivots=os-linux)
24+
- Install az cli: [Install az](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt#option-1-install-with-one-command)
25+
- Install docker: [Docker Desktop WSL 2](https://docs.docker.com/desktop/wsl/)
26+
27+
1. Plan your Azure Container Registry
28+
29+
An Azure Container Registry is required to save the images for the solution, either create a new Container Registry or use an existing one:
30+
- Option 1: Create a new Azure Container Registry
1931

20-
# prepare ACR
21-
MYACR=acr$APPNAME
32+
```bash
33+
ACR_RESOURCE_GROUP=<your-resource-group>
34+
ACR_NAME=<acr-name>
2235
az acr create \
23-
-n $MYACR \
24-
-g $RESOURCE_GROUP \
36+
-n $ACR_NAME \
37+
-g $ACR_RESOURCE_GROUP \
2538
--sku Basic \
2639
--admin-enabled true
40+
```
2741

28-
ACR_ID=$(az acr show -n $MYACR -g $RESOURCE_GROUP --query id -o tsv)
42+
- Option 2: Use existing
43+
Collect the values for variable `ACR_RESOURCE_GROUP` and `ACR_NAME`
44+
Please add yourself the `Contributor` role in the container registry, we will:
45+
1. push images to the acr.
46+
1. assign `AcrPull` permission to new user managed identity.
2947

30-
# create user managed identity
31-
ACR_IDENTITY=uid-acr-$APPNAME
48+
1. Prepare placeholder image to Azure Container Registry
49+
In the azd deploy process, we will first create azure resource and container apps, then update the target container apps with the code in the lab solution.
50+
In this step, we push a placeholder image for the new container apps.
3251

33-
az identity create --resource-group $RESOURCE_GROUP --name $ACR_IDENTITY
34-
ACR_UMID=$(az identity show --resource-group $RESOURCE_GROUP --name $ACR_IDENTITY --query id --output tsv)
35-
SP_ID=$(az identity show --resource-group $RESOURCE_GROUP --name $ACR_IDENTITY --query principalId --output tsv)
36-
CLIENT_ID=$(az identity show --resource-group $RESOURCE_GROUP --name $ACR_IDENTITY --query clientId --output tsv)
52+
- login to acr with command `az acr login -n $ACR_NAME`
53+
- use a simple java image as the placeholder image:
3754

38-
# assign role
39-
az role assignment create --assignee $SP_ID --scope $ACR_ID --role acrpull
55+
```bash
56+
az acr import --name $ACR_NAME \
57+
--source mcr.microsoft.com/azurespringapps/default-banner:distroless-2024022107-66ea1a62-87936983 \
58+
--image azurespringapps/default-banner:latest
4059
```
4160

42-
1. Prepare your images to Azure Container Registry
43-
You may use the ACR createed in Lab 3, and the user managed identity too.
44-
Please build your passwordless image after Lab 4.
45-
46-
1. In your local repo, open file `infra/bicep/main.parameters.json`, fill the parameters
47-
48-
- vnetEndpointInternal: is the container apps subnet internal-only?
49-
- sqlAdmin: the admin user for sql server
50-
- sqlAdminPassword: the admin password for sql server
51-
- configGitRepo: Default to this repo `https://github.com/Azure-Samples/spring-petclinic-microservices-config`
52-
- configGitPath: `passwordless` profile default to directory `config` in this repo
53-
- acrRegistry: The ACR address with your build images, `$MYACR.azurecr.io`
54-
- acrIdentityId: The user mananged identity id with AcrPull access, `$ACR_UMID`
55-
- miPrincipalId: The principal id for the user mananged identity, `$SP_ID`
56-
- miClientId: The client id for the user mananged identity, `$CLIENT_ID`
57-
- apiGatewayImage: The API gateway image with tag
58-
- customerServiceImage: The customer service image with tag
59-
- vetsServiceImage: The vets service image with tag
60-
- visitsServiceImage: The visits service image with tag
61-
- adminServerImage: The admin server image with tag
62-
- chatAgentImage: The chat agent image with tag
63-
- applicationInsightsConnString: The connection string of your AI instance
61+
1. Fill the azd configuration files
62+
63+
- In your local repo, open file `azure.yaml`
64+
- replace all the `<your-acr>` with your variable `$ACR_NAME`
65+
66+
- By default, the azd tool will create all resource into the same resource group, default to `rg-${environmentName}`
67+
Please refer to file [main.bicep](../../infra/bicep/main.bicep) for more configurations.

docs/06_lab_automation/0602.md

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,41 @@
22
title: '2. Run Azd'
33
layout: default
44
nav_order: 2
5-
parent: 'Lab 8: Use Azd to deploy the lab solution'
5+
parent: 'Lab 6: Deploy to Azure automatically'
66
---
77

8-
# 1. Run Azd Command to deploy
8+
# 2. Run Azd Command to deploy
99

1010
Run `azd up` to deploy the petclinic solution and dependent components to Azure Container App
1111

1212
## Step by step guidance
1313

1414
1. Run `azd up`
15-
16-
- fill your environment name.
17-
- select the target subscription
18-
- select the target region
19-
20-
This command will create these components to your environment:
21-
22-
- Resource Group
23-
- Virtual Network with subnets
24-
- Log Analytics Workspace
25-
- Azure Container Apps environment
26-
- Managed components in ACA environment: SpringCloudEureka / SpringCloudConfig / SpringBootAdmin
27-
- MySQL flexibleServers
28-
- The petclinic solution apps api-gateway, admin-server, customer-service, vets-service, visits-service
29-
30-
You can view detailed progress in the Azure Portal: xxx
31-
Open the link to check the deployment status in portal
32-
33-
{: .note }
34-
> You may encounter some failures during the deploy, fix the errors according to the deployment status.
35-
> If there are internal errors, please re-run the `azd up` commands to redeploy.
36-
37-
1. Run rebuild service connection from apps to sql database
38-
Due to some limitation, the bicep won't create database user for the service connections, See Lab 4 step 2.
39-
40-
Run the commands below to create the db user
41-
42-
```bash
43-
CLIENT_ID=$(az identity show --resource-group $RESOURCE_GROUP --name $ACA_IDENTITY --query 'clientId' --output tsv)
44-
echo $CLIENT_ID
45-
az containerapp connection create mysql-flexible \
46-
--connection mysql_conn \
47-
--source-id $CUSTOMERS_ID \
48-
--target-id $DB_ID \
49-
--client-type SpringBoot \
50-
--user-identity client-id=$CLIENT_ID subs-id=$SUBID mysql-identity-id=$ADMIN_IDENTITY_RESOURCE_ID \
51-
-c customers-service
15+
Fill the variables required from the prompt:
16+
17+
```text
18+
? Enter a new environment name: <env-name>
19+
? Select an Azure Subscription to use: xxx xxx
20+
? Select an Azure location to use: xxx
21+
? Enter a value for the 'acrGroupName' infrastructure parameter: <your acr group>
22+
? Enter a value for the 'acrName' infrastructure parameter: <your acr name>
23+
? Enter a value for the 'acrSubscription' infrastructure parameter: <your acr subscription>
5224
```
5325
54-
Only one command required for this solution:
26+
You may find the settings in directory `.azure/<env-name>/`
27+
28+
Then azd commands are executed:
29+
- azd package: package your solution via the services and docker configurations in ./azure.yaml
30+
- azd provision: create/update the azure resources defined in infra/bicep/main.bicep
31+
- azd deploy: deploy the local build solution to azure services.
5532
56-
- The apps share the same connection name, so same user name in db.
57-
- Once the user name is set, your don't have to recreate it.
33+
If you meet any problems during this step, refer to page [Triage the issues](0603.md)
5834
59-
1. Verify
35+
1. Run `azd show`
36+
You may see lots of variables from the results.
37+
Open the urls to your deployed service:
6038
61-
- visit the api-gateway Application Url
62-
- visit the admin-server Application Url
39+
```text
40+
gatewayFqdn="api-gateway.<cluster-id>.<region>.azurecontainerapps.io"
41+
adminFqdn="admin-server.<cluster-id>.<region>.azurecontainerapps.io"
42+
```

docs/06_lab_automation/0603.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: '3. Triage the issues'
3+
layout: default
4+
nav_order: 3
5+
parent: 'Lab 6: Deploy to Azure automatically'
6+
---
7+
8+
# 3. Triage the issues
9+
10+
1. Visit deployment details
11+
From the command output, find the hint:
12+
`You can view detailed progress in the Azure Portal:`
13+
And visit the link to see the details of your deployment.
14+
15+
In your deployment page, you may click each Resource link, and check the Inputs/Output variables for better triage.
16+
17+
1. Failed to provision java component 'configserver'
18+
19+
```text
20+
ERROR: error deploying infrastructure: deploying to subscription:
21+
22+
Deployment Error Details:
23+
JavaComponentOperationError: Failed to provision java component 'configserver'. Error details: Failed to create config map external-auth-config-map for JavaComponent configserver in k8se-system namespace. There will be no re-tries..
24+
```
25+
26+
> This is a temporary error in service, just ignore and retry.
27+
28+
1. Failed to deploy open AI instance
29+
30+
```text
31+
InvalidTemplateDeployment: The template deployment 'openai' is not valid according to the validation procedure. The tracking id is 'xxx'. See inner errors for details.
32+
SpecialFeatureOrQuotaIdRequired: The subscription does not have QuotaId/Feature required by SKU 'S0' from kind 'OpenAI' or contains blocked QuotaId/Feature.
33+
```
34+
35+
> Azure OpenAI is not enabled in your subscription + region settings, please check the feature status. You may edit the configurations in `./infra/bicep/main.parameters.json`
36+
> - Disable openAI by set *enableOpenAi = false* and run *azd up*.
37+
> - Find a subcription + region combination and set the values `openAiSubscription`, `openAiLocation`, and run *azd up*.
38+
> - Use an existed openAI instance. See guide in page [Reuse existing resource](./0604.md)

docs/06_lab_automation/0604.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: '4. Reuse existing resource'
3+
layout: default
4+
nav_order: 4
5+
parent: 'Lab 6: Deploy to Azure automatically'
6+
---
7+
8+
# 4. Reuse existing resource
9+
10+
The default `azd up` process will create lots of resource into the target resource group.
11+
Sometimes you may reuse some existing resources for your solution.
12+
13+
1. Reuse Azure openAI instance

docs/06_lab_automation/06_openlab_automation.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
title: 'Lab 6: Automatically deploy lab solution to Azure Container Apps'
2+
title: 'Lab 6: Deploy to Azure automatically'
33
layout: default
44
nav_order: 8
55
has_children: true
66
---
77

8-
# Lab 6: Automatically deploy lab solution to Azure Container Apps
8+
# Lab 6: Deploy to Azure automatically
99

1010
# Student manual
1111

@@ -14,14 +14,14 @@ has_children: true
1414
In the Lab 2, Lab 3, Lab 4 and Lab 5 we deploy the petclinic microservice solution to Azure Container Apps step by step.
1515
These steps are full of details but time costing.
1616

17-
In this lab, we import a new tool [azd](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/) to help deploy the solution to Azure with single command.
17+
In this lab, we introduce a new tool [azd](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/) to help deploy the solution to Azure with single command.
1818

1919
## Objectives
2020

2121
After you complete this lab, you will be able to:
2222

2323
- Get familiar with the azd tool.
24-
- Deploy the petclinic solution to new ACA environment.
24+
- Deploy the petclinic solution (with AI) to new ACA environment.
2525
- Test your setup.
2626

2727
## Lab Duration
@@ -35,7 +35,7 @@ During this lab, you will:
3535
- Prepare your azd tools environment.
3636
- Get your Azure Registry ready and fill the configuration files.
3737
- Run `azd up` command to deploy the sample soluton to Azure Container Apps.
38-
- Test your setup.
38+
- Learn how to triage some problems with the one-click solution.
3939

4040
## Limits
4141

docs/07_lab_security/0701.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: '1. Networking resources'
33
layout: default
44
nav_order: 1
5-
parent: 'Lab 6: Protect endpoints using Web Application Firewalls'
5+
parent: 'Lab 7: Protect endpoints using Web Application Firewalls'
66
---
77

88
# Create additional networking resources

docs/07_lab_security/0702.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: '2. Create Key Vault'
33
layout: default
44
nav_order: 2
5-
parent: 'Lab 6: Protect endpoints using Web Application Firewalls'
5+
parent: 'Lab 7: Protect endpoints using Web Application Firewalls'
66
---
77

88
# Create an Azure Key Vault service

docs/07_lab_security/0703.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: '3. Certificate'
33
layout: default
44
nav_order: 3
5-
parent: 'Lab 6: Protect endpoints using Web Application Firewalls'
5+
parent: 'Lab 7: Protect endpoints using Web Application Firewalls'
66
---
77

88
# Acquire a certificate and add it to Key Vault

0 commit comments

Comments
 (0)