Skip to content

Commit 526fcd7

Browse files
Merge pull request #217147 from cebundy/ps-cmds
[Container Apps]: add PowerShell cmdlets to articles
2 parents c358c56 + 0b4a4ee commit 526fcd7

8 files changed

+496
-276
lines changed

articles/container-apps/communicate-between-microservices.md

Lines changed: 98 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ Sign in to the Azure CLI.
4747
az login
4848
```
4949

50-
# [PowerShell](#tab/powershell)
50+
# [Azure PowerShell](#tab/azure-powershell)
5151

52-
```powershell
53-
az login
52+
```azurepowershell
53+
Connect-AzAccount
5454
```
5555

5656
---
@@ -63,10 +63,10 @@ az login
6363
az acr login --name $ACR_NAME
6464
```
6565

66-
# [PowerShell](#tab/powershell)
66+
# [Azure PowerShell](#tab/azure-powershell)
6767

68-
```powershell
69-
az acr login --name $ACR_NAME
68+
```azurepowershell
69+
az acr login --name $ACRName
7070
```
7171

7272
---
@@ -110,10 +110,10 @@ az acr login --name $ACR_NAME
110110
az acr build --registry $ACR_NAME --image albumapp-ui .
111111
```
112112

113-
# [PowerShell](#tab/powershell)
113+
# [Azure PowerShell](#tab/azure-powershell)
114114

115-
```powershell
116-
az acr build --registry $ACR_NAME --image albumapp-ui .
115+
```azurepowershell
116+
az acr build --registry $ACRName --image albumapp-ui .
117117
```
118118

119119
---
@@ -132,10 +132,10 @@ Output from the `az acr build` command shows the upload progress of the source c
132132
docker build --tag "$ACR_NAME.azurecr.io/albumapp-ui" .
133133
```
134134
135-
# [PowerShell](#tab/powershell)
135+
# [Azure PowerShell](#tab/azure-powershell)
136136
137-
```powershell
138-
docker build --tag "$ACR_NAME.azurecr.io/albumapp-ui" .
137+
```azurepowershell
138+
docker build --tag "$ACRName.azurecr.io/albumapp-ui" .
139139
```
140140
141141
---
@@ -150,10 +150,10 @@ Output from the `az acr build` command shows the upload progress of the source c
150150
az acr login --name $ACR_NAME
151151
```
152152
153-
# [PowerShell](#tab/powershell)
153+
# [Azure PowerShell](#tab/azure-powershell)
154154
155-
```powershell
156-
az acr login --name $ACR_NAME
155+
```azurepowershell
156+
az acr login --name $ACRName
157157
```
158158
159159
---
@@ -167,11 +167,11 @@ Output from the `az acr build` command shows the upload progress of the source c
167167
docker push "$ACR_NAME.azurecr.io/albumapp-ui"
168168
```
169169
170-
# [PowerShell](#tab/powershell)
170+
# [Azure PowerShell](#tab/azure-powershell)
171171
172-
```powershell
172+
```azurepowershell
173173
174-
docker push "$ACR_NAME.azurecr.io/albumapp-ui"
174+
docker push "$ACRName.azurecr.io/albumapp-ui"
175175
```
176176
177177
---
@@ -207,10 +207,11 @@ Run the following command to query for the API endpoint address.
207207
API_BASE_URL=$(az containerapp show --resource-group $RESOURCE_GROUP --name $API_NAME --query properties.configuration.ingress.fqdn -o tsv)
208208
```
209209

210-
# [PowerShell](#tab/powershell)
210+
# [Azure PowerShell](#tab/azure-powershell)
211+
212+
```azurepowershell
213+
$APIBaseURL = (Get-AzContainerApp -Name $APIName -ResourceGroupName $ResourceGroup).IngressFqdn
211214
212-
```powershell
213-
$API_BASE_URL=$(az containerapp show --resource-group $RESOURCE_GROUP --name $API_NAME --query properties.configuration.ingress.fqdn -o tsv)
214215
```
215216

216217
---
@@ -232,47 +233,105 @@ az containerapp create \
232233
--target-port 3000 \
233234
--env-vars API_BASE_URL=https://$API_BASE_URL \
234235
--ingress 'external' \
235-
--registry-server $ACR_NAME.azurecr.io
236+
--registry-server $ACR_NAME.azurecr.io \
237+
--query properties.configuration.ingress.fqdn
236238
```
237239

238-
# [PowerShell](#tab/powershell)
239240

240-
```azurecli
241-
az containerapp create `
242-
--name $FRONTEND_NAME `
243-
--resource-group $RESOURCE_GROUP `
244-
--environment $ENVIRONMENT `
245-
--image "$ACR_NAME.azurecr.io/albumapp-ui" `
246-
--env-vars API_BASE_URL=https://$API_BASE_URL `
247-
--target-port 3000 `
248-
--ingress 'external' `
249-
--registry-server "$ACR_NAME.azurecr.io"
241+
By adding the argument `--env-vars "API_BASE_URL=https://$API_ENDPOINT"` to `az containerapp create`, you define an environment variable for your front end application. With this syntax, the environment variable named `API_BASE_URL` is set to the API's FQDN.
242+
243+
The output from the `az containerapp create` command shows the URL of the front end application.
244+
245+
# [Azure PowerShell](#tab/azure-powershell)
246+
247+
To create the container app, create template objects that you'll pass in as arguments to the `New-AzContainerApp` command.
248+
249+
Create a template object to define your container image parameters. The environment variable named `API_BASE_URL` is set to the API's FQDN.
250+
251+
```azurepowershell
252+
253+
$EnvVars = New-AzContainerAppEnvironmentVarObject -Name API_BASE_URL -Value https://$APIBaseURL
254+
255+
$ContainerArgs = @{
256+
Name = $FrontendName
257+
Image = $ACRName + '.azurecr.io/albumapp-ui'
258+
Env = $EnvVars
259+
}
260+
$ContainerObj = New-AzContainerAppTemplateObject @ContainerArgs
250261
```
251262

252-
---
263+
You'll need run the following command to get your registry credentials.
253264

254-
By adding the argument `--env-vars "API_BASE_URL=https://$API_ENDPOINT"` to `az containerapp create`, you define an environment variable for your front end application. With this syntax, the environment variable named `API_BASE_URL` is set to the API's FQDN.
265+
```azurepowershell
266+
$RegistryCredentials = Get-AzContainerRegistryCredential -Name $ACRName -ResourceGroupName $ResourceGroup
267+
```
268+
269+
Create a registry credential object to define your registry information, and a secret object to define your registry password. The `PasswordSecretRef` in `$RegistryObj` refers to the `Name` in `$SecretObj`.
270+
271+
```azurepowershell
272+
$RegistryArgs = @{
273+
Server = $ACRName + '.azurecr.io'
274+
PasswordSecretRef = 'registrysecret'
275+
Username = $RegistryCredentials.Username
276+
}
277+
$RegistryObj = New-AzContainerAppRegistryCredentialObject @RegistryArgs
278+
279+
$SecretObj = New-AzContainerAppSecretObject -Name 'registrysecret' -Value $RegistryCredentials.Password
280+
```
281+
282+
Get your environment ID.
283+
284+
```azurepowershell
285+
$EnvId = (Get-AzContainerAppManagedEnv -EnvName $Environment -ResourceGroup $ResourceGroup).Id
286+
```
287+
288+
Create the container app.
289+
290+
```azurepowershell
291+
$AppArgs = @{
292+
Name = $FrontendName
293+
Location = $Location
294+
ResourceGroupName = $ResourceGroup
295+
ManagedEnvironmentId = $EnvId
296+
TemplateContainer = $ContainerObj
297+
ConfigurationRegistry = $RegistryObj
298+
ConfigurationSecret = $SecretObj
299+
IngressTargetPort = 3000
300+
IngressExternal = $true
301+
}
302+
$FrontEndApp = New-AzContainerApp @AppArgs
303+
304+
# show the app's FQDN
305+
306+
$FrontEndApp.IngressFqdn
307+
```
308+
309+
---
255310

256311
## View website
257312

258-
The `az containerapp create` CLI command returns the fully qualified domain name (FQDN) of your album UI container app. Open this location in a browser to navigate to the web application resembling the following screenshot.
313+
Use the container app's FQDN to view the website. The page will resemble the following screenshot.
259314

260315
:::image type="content" source="media/communicate-between-microservices/azure-container-apps-album-ui.png" alt-text="Screenshot of album list UI microservice.":::
261316

262317
## Clean up resources
263318

264319
If you're not going to continue to use this application, run the following command to delete the resource group along with all the resources created in this quickstart.
265320

321+
> [!CAUTION]
322+
> This command deletes the specified resource group and all resources contained within it. If resources outside the scope of this tutorial exist in the specified resource group, they will also be deleted.
323+
324+
266325
# [Bash](#tab/bash)
267326

268327
```azurecli
269328
az group delete --name $RESOURCE_GROUP
270329
```
271330

272-
# [PowerShell](#tab/powershell)
331+
# [Azure PowerShell](#tab/azure-powershell)
273332

274-
```powershell
275-
az group delete --name $RESOURCE_GROUP
333+
```azurepowershell
334+
Remove-AzResourceGroup -Name $ResourceGroup -Force
276335
```
277336

278337
---

0 commit comments

Comments
 (0)