Skip to content

Commit 1de2d7b

Browse files
docs: update bicep module to simplify image creation
1 parent 8b292eb commit 1de2d7b

File tree

4 files changed

+174
-31
lines changed

4 files changed

+174
-31
lines changed

bicep/modules/container-apps/processor-backend-service.bicep

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ resource backendProcessorService 'Microsoft.App/containerApps@2022-06-01-preview
134134
value: containerRegistryPassword
135135
}
136136
]
137-
registries: [
137+
registries: !empty(containerRegistryName) ? [
138138
{
139139
server: '${containerRegistryName}.azurecr.io'
140140
username: containerRegistryUsername
141141
passwordSecretRef: containerRegistryPasswordRefName
142142
}
143-
]
143+
] : []
144144
}
145145
template: {
146146
containers: [

bicep/modules/container-apps/webapi-backend-service.bicep

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ resource backendApiService 'Microsoft.App/containerApps@2022-06-01-preview' = {
105105
logLevel: 'info'
106106
enableApiLogging: true
107107
}
108-
registries: [
108+
registries: !empty(containerRegistryName) ? [
109109
{
110110
server: '${containerRegistryName}.azurecr.io'
111111
username: containerRegistryUsername
112112
passwordSecretRef: containerRegistryPasswordRefName
113113
}
114-
]
114+
] : []
115115
secrets: [
116116
{
117117
name: 'appinsights-key'

bicep/modules/container-apps/webapp-frontend-service.bicep

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ resource frontendWebAppService 'Microsoft.App/containerApps@2022-06-01-preview'
7272
value: containerRegistryPassword
7373
}
7474
]
75-
registries: [
75+
registries: !empty(containerRegistryName) ? [
7676
{
7777
server: '${containerRegistryName}.azurecr.io'
7878
username: containerRegistryUsername
7979
passwordSecretRef: containerRegistryPasswordRefName
8080
}
81-
]
81+
] : []
8282
}
8383
template: {
8484
containers: [

docs/aca/10-aca-iac-bicep/index.md

Lines changed: 168 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ To begin, we need to define the Bicep modules that will be required to generate
3333
![aca-resources](../../assets/images/10-aca-iac-bicep/aca-rescources.jpg)
3434

3535
!!! note
36-
To simplify the execution of the module, we will assume that the azure resource "Azure Container Registry" is already provisioned and it contains the latest images of the three services. If we deployed ACR part of the Bicep scripts, then we can't build and push images to the created ACR in an automated way because creating the three ACA container apps is reliant on ACR's images.
36+
To simplify the execution of the module, we will assume that you have already created latest images of three services and pushed them to a container registry. [This section](#deploy-the-infrastructure-and-create-the-components) below guides you through
37+
different options of getting images pushed to either Azure Container Registry (ACR) or GitHub Container Registry (GHCR).
38+
39+
If we created and deployed container registery as part of the Bicep scripts, then we can't build and push images to the created ACR in an automated way because creating the three ACA container apps is reliant on ACR's images.
3740

38-
In a production setting, a DevOps pipeline would be in place to automate the whole process - commencing with ACR creation, followed by building and pushing docker images, and concluding with executing the Bicep script to establish the remaining resources. As it is outside the scope of this workshop, we will not delve into the creation of a DevOps pipeline here.
41+
In a production setting, a DevOps pipeline would be in place to automate the whole process - commencing with ACR creation, followed by building and pushing docker images, and concluding with executing the
42+
Bicep script to establish the remaining resources. As it is outside the scope of this workshop, we will not delve into the creation of a DevOps pipeline here.
43+
3944
#### 1. Add the Needed Extension to VS Code
4045
To proceed, you must install an extension called [Bicep](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep). This extension will simplify building Bicep files as it offers IntelliSense, Validation, listing all available resource types, etc..
4146

@@ -273,47 +278,185 @@ To achieve this, add a new file under the `bicep` directory as shown below:
273278
Start by creating a new resource group which will contain all the resources to be created by the Bicep scripts.
274279

275280
```Powershell
276-
az group create `
277-
--name "<your RG name>" `
278-
--location "eastus"
279-
```
280-
281-
Next create an ACR inside the newly created Resource Group:
281+
$RESOURCE_GROUP="<your RG name>"
282+
$LOCATION="<your location>"
282283
283-
```Powershell
284-
az acr create `
285-
--resource-group <your RG name> `
286-
--name <your ACR name>`
287-
--sku Basic `
288-
--admin-enabled true
284+
az group create `
285+
--name $RESOURCE_GROUP `
286+
--location $LOCATION
289287
```
290288

291-
!!! note
292-
Once the RG and ACR are created you can check [this section](../../aca/08-aca-monitoring/index.md#2-build-new-images-and-push-them-to-acr) which shows the different commands to build and push the images to ACR. Make sure you are at the root project directory when executing the aforementioned commands. Finally run the bicep file against the newly created Resource Group as shown below.
293-
294-
With the steps above completed we are ready to deploy all the different resources. We just need to create a parameters file which will simplify the invocation of the main bicep file.
289+
Create a parameters file which will simplify the invocation of the main bicep file. To achieve this, right click on file `main.bicep` and select **Generate Parameter File**.
290+
This will result in creating a file named `main.parameters.json` similar to the file below:
295291

296-
To achieve this, right click on file `main.bicep` and select **Generate Parameter File**. This will result in creating a file named `main.parameters.json` similar to the file below:
292+
??? example
297293

298-
???+ example
299294
=== "main.parameters.json"
300295

301296
```json
302297
--8<-- "https://raw.githubusercontent.com/Azure/aca-dotnet-workshop/main/bicep/main.parameters.json"
303298
```
304-
305299
!!! note
306-
300+
307301
To use this file, you need to edit this generated file and provide values for the parameters. You can use the same values shown above in sample file.
308-
309-
You only need to replace parameter values between the angle brackets `<>` with values related to your ACR resource and SendGrid.
302+
303+
You only need to replace parameter values between the angle brackets `<>` with values related to your container registry and SendGrid. Values for container registry and container images can be dervied by following
304+
one of the three options in next step.
305+
306+
Next, we will prepare container images for the three container apps and update the values in `main.parameters.json` file. You can do so by any of the three options below:
307+
308+
=== "Option 1: Build and Push the Images to Azure Container Registry (ACR)"
309+
310+
1. Create an Azure Container Registry (ACR) inside the newly created Resource Group:
311+
312+
```Powershell
313+
$CONTAINER_REGISTRY_NAME="<your ACR name>"
314+
315+
az acr create `
316+
--resource-group $RESOURCE_GROUP `
317+
--name $CONTAINER_REGISTRY_NAME `
318+
--sku Basic `
319+
--admin-enabled true
320+
```
321+
322+
2. Build and push the images to ACR as guided in [this section](../../aca/08-aca-monitoring/index.md#2-build-new-images-and-push-them-to-acr). Make sure you are at the root project directory when executing the following commands:
323+
324+
```Powershell
325+
326+
## Build Backend API on ACR and Push to ACR
327+
328+
az acr build --registry $CONTAINER_REGISTRY_NAME `
329+
--image "tasksmanager/$BACKEND_API_NAME" `
330+
--file 'TasksTracker.TasksManager.Backend.Api/Dockerfile' .
331+
332+
## Build Backend Service on ACR and Push to ACR
333+
334+
az acr build --registry $CONTAINER_REGISTRY_NAME `
335+
--image "tasksmanager/$BACKEND_SVC_NAME" `
336+
--file 'TasksTracker.Processor.Backend.Svc/Dockerfile' .
337+
338+
## Build Frontend Web App on ACR and Push to ACR
339+
340+
az acr build --registry $CONTAINER_REGISTRY_NAME `
341+
--image "tasksmanager/$FRONTEND_WEBAPP_NAME" `
342+
--file 'TasksTracker.WebPortal.Frontend.Ui/Dockerfile' .
343+
```
344+
345+
3. Update the `main.parameters.jsonc` file with the container registry name and the container images names as shown below:
346+
347+
```json hl_lines="3 6 9 12 15 18"
348+
{
349+
"containerRegistryName": {
350+
"value": "<CONTAINER_REGISTRY_NAME>"
351+
},
352+
"containerRegistryUsername": {
353+
"value": "<CONTAINER_REGISTRY_ADMIN>"
354+
},
355+
"containerRegistryPassword": {
356+
"value": "<CONTAINER_REGISTRY_PASSWORD>"
357+
},
358+
"backendProcessorServiceImage": {
359+
"value": "<CONTAINER_REGISTRY_NAME>.azurecr.io/tasksmanager/<BACKEND_API_NAME>:latest"
360+
},
361+
"backendApiServiceImage": {
362+
"value": "<CONTAINER_REGISTRY_NAME>.azurecr.io/tasksmanager/<FRONTEND_WEBAPP_NAME>:latest"
363+
},
364+
"frontendWebAppServiceImage": {
365+
"value": "<CONTAINER_REGISTRY_NAME>.azurecr.io/tasksmanager/<BACKEND_SVC_NAME>:latest"
366+
}
367+
}
368+
```
369+
370+
371+
=== "Option 2: Import pre-built public images to your private Azure Container Registry"
372+
373+
All the container image are available in a public image repository. If you do not wish to build the container images from code directly, you can import it directly into
374+
your private container instance as shown below.
375+
376+
1. Create an Azure Container Registry (ACR) inside the newly created Resource Group:
377+
378+
```Powershell
379+
az acr create `
380+
--resource-group $RESOURCE_GROUP `
381+
--name <your ACR name>`
382+
--sku Basic `
383+
--admin-enabled true
384+
```
385+
2. Import the images to your private ACR as shown below:
386+
387+
```Powershell
388+
389+
az acr import `
390+
--name $CONTAINER_REGISTRY_NAME `
391+
--image tasksmanager/tasksmanager-backend-api `
392+
--source ghcr.io/azure/tasksmanager-backend-api:latest
393+
394+
az acr import `
395+
--name $CONTAINER_REGISTRY_NAME `
396+
--image tasksmanager/tasksmanager-frontend-webapp `
397+
--source ghcr.io/azure/tasksmanager-frontend-webapp:latest
398+
399+
az acr import `
400+
--name $CONTAINER_REGISTRY_NAME `
401+
--image tasksmanager/tasksmanager-backend-processor `
402+
--source ghcr.io/azure/tasksmanager-backend-processor:latest
403+
404+
```
405+
406+
3. Update the `main.parameters.jsonc` file with the container registry name and the container images names as shown below:
407+
408+
```json hl_lines="3 6 9 12 15 18"
409+
{
410+
"containerRegistryName": {
411+
"value": "<CONTAINER_REGISTRY_NAME>"
412+
},
413+
"containerRegistryUsername": {
414+
"value": "<CONTAINER_REGISTRY_ADMIN>"
415+
},
416+
"containerRegistryPassword": {
417+
"value": "<CONTAINER_REGISTRY_PASSWORD>"
418+
},
419+
"backendProcessorServiceImage": {
420+
"value": "<CONTAINER_REGISTRY_NAME>.azurecr.io/tasksmanager/tasksmanager-backend-processor:latest"
421+
},
422+
"backendApiServiceImage": {
423+
"value": "<CONTAINER_REGISTRY_NAME>.azurecr.io/tasksmanager/tasksmanager-backend-api:latest"
424+
},
425+
"frontendWebAppServiceImage": {
426+
"value": "<CONTAINER_REGISTRY_NAME>.azurecr.io/tasksmanager/tasksmanager-frontend-webapp:latest"
427+
}
428+
}
429+
```
430+
431+
=== "Option 3: Use the pre-built images from the public repository"
432+
433+
All the container image are available in a public image repository. If you do not wish to build the container images from code directly, you can use the pre-built images from the public repository as shown below.
434+
435+
The public images can be set directly in the `main.parameters.jsonc` file:
436+
437+
```json hl_lines="3 6 9 12"
438+
{
439+
"containerRegistryName": {
440+
"value": ""
441+
},
442+
"backendProcessorServiceImage": {
443+
"value": "ghcr.io/azure/tasksmanager-backend-processor:latest"
444+
},
445+
"backendApiServiceImage": {
446+
"value": "ghcr.io/azure/tasksmanager-backend-api:latest"
447+
},
448+
"frontendWebAppServiceImage": {
449+
"value": "ghcr.io/azure/tasksmanager-frontend-webapp:latest"
450+
},
451+
}
452+
```
310453

311454
Start the deployment by calling `az deployment group create`. To accomplish this, open the PowerShell console and use the content below.
312455

313456

314457
```Powershell
315458
az deployment group create `
316-
--resource-group "<your RG name>" `
459+
--resource-group $RESOURCE_GROUP `
317460
--template-file "./bicep/main.bicep" `
318461
--parameters "./bicep/main.parameters.json"
319462
```

0 commit comments

Comments
 (0)