Skip to content

Commit

Permalink
Miscellaneous Fixes & Updates (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonkurtz-MSFT authored Jan 7, 2025
1 parent 81824b2 commit 6d4e99a
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/aca/01-deploy-api-to-aca/global-dotnet9.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "9.0.100",
"version": "9.0.101",
"rollForward": "latestFeature"
}
}
2 changes: 1 addition & 1 deletion docs/aca/03-aca-dapr-integration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ We are ready now to verify the changes on the Frontend Web App and test locally.

--8<-- "snippets/dapr-run-backend-api.md:basic"

Notice how we assigned the Dapr App Id tasksmanager-frontend-webapp to the Frontend WebApp.
Notice how we assigned the Dapr App Id "tasksmanager-frontend-webapp" to the Frontend WebApp.

!!! note
If you need to run both microservices together, you need to keep calling `dapr run` manually each time in the terminal. And when you have multiple microservices talking to each other you need to run at the same time to debug the solution. This can be a convoluted process. You can refer to the [debug and launch Dapr applications in VSCode](../30-appendix/01-run-debug-dapr-app-vscode.md) to see how to configure VScode for running and debugging Dapr applications.
Expand Down
19 changes: 16 additions & 3 deletions docs/aca/04-aca-dapr-stateapi/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,19 @@ $result = az cosmosdb check-name-exists `
# Continue if the Cosmos DB account does not yet exist
if ($result -eq "false") {
echo "Creating Cosmos DB account..."
echo "Creating Cosmos DB account. This may take a few minutes..."
# Create a Cosmos account for SQL API
az cosmosdb create `
--name $COSMOS_DB_ACCOUNT `
--resource-group $RESOURCE_GROUP
--resource-group $RESOURCE_GROUP `
# Enable local authentication to avoid a 401 when running locally.
az resource update `
--name $COSMOS_DB_ACCOUNT `
--resource-group $RESOURCE_GROUP `
--resource-type "Microsoft.DocumentDB/databaseAccounts" `
--set properties.disableLocalAuth=false
# Create a SQL API database
az cosmosdb sql database create `
Expand Down Expand Up @@ -246,7 +253,7 @@ if ($result -eq "false") {
```
!!! note
The `primaryMasterKey` connection string is only needed for our local testing on the development machine, we'll be using a different approach (**Managed Identities**) when deploying Dapr component to Azure Container Apps Environment.
The `primaryMasterKey` connection string is only needed for our local testing on the development machine, we'll be using a different approach (**Managed Identities**) when deploying Dapr component to Azure Container Apps Environment. For this workshop, we are allowing local authentication with the `az resource update` command above, but this should not be done for production workloads.

Once the scripts execution is completed, we need to get the `primaryMasterKey` of the Cosmos DB account next. You can do this using the PowerShell script below.
Copy the value of `primaryMasterKey` as we will use it in the next step.
Expand Down Expand Up @@ -321,6 +328,12 @@ If you have been using the dapr cli commands instead of the aforementioned debug
!!! note "Deprecation Warning"
components-path is being deprecated in favor of --resources-path. At the time of producing this workshop the --resources-path was not supported yet by the VS code extension. Hence, you will notice the use of the property "componentsPath": "./components" in the tasks.json file. Check the extension documentation in case that has changed.
Run the local frontend UI in the other terminal again:
=== ".NET 8 or above"
--8<-- "snippets/dapr-run-frontend-webapp.md:basic"
After creating a new record you can navigate to the Data explorer on the [Azure portal](https://portal.azure.com){target=_blank} for the Azure Cosmos DB account. It should look like the image below:
![cosmos-db-dapr-state-store](../../assets/images/04-aca-dapr-stateapi/cosmos-db-dapr-state-store.jpg)
Expand Down
4 changes: 2 additions & 2 deletions docs/aca/05-aca-dapr-pubsubapi/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Update below file in **TasksTracker.Processor.Backend.Svc** project.
- Let's verify that the Dapr dependency is restored properly and that the project compiles. From VS Code Terminal tab, open developer command prompt or PowerShell terminal and navigate to the parent directory which hosts the `.csproj` project folder and build the project.

```shell
cd ~\TasksTracker.ContainerApps\TasksTracker.TasksManager.Backend.Svc
cd ~\TasksTracker.ContainerApps\TasksTracker.Processor.Backend.Svc
dotnet build
```

Expand Down Expand Up @@ -356,7 +356,7 @@ az servicebus namespace authorization-rule keys list `
#### 3.2 Create a local Dapr Component file for Pub/Sub API Using Azure Service Bus
We need to add a new [Dapr Azure Service Bus Topic component](https://docs.dapr.io/reference/components-reference/supported-pubsub/setup-azure-servicebus-topics){target=_blank}. Add a new file in the **components** folder as shown below:
We need to add a new [Dapr Azure Service Bus Topic component](https://docs.dapr.io/reference/components-reference/supported-pubsub/setup-azure-servicebus-topics){target=_blank}. Add a new file in the **components** folder as shown below. Be sure to update the connection string value.
```yaml title="dapr-pubsub-svcbus.yaml"
--8<-- "docs/aca/05-aca-dapr-pubsubapi/dapr-pubsub-svcbus.yaml"
Expand Down
1 change: 1 addition & 0 deletions docs/aca/06-aca-dapr-bindingsapi/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ Add new files under the **aca-components** use the yaml below:
- We are setting the property `secretStoreComponent` value to `secretstoreakv` which is the name of Dapr secret store component.
- We are using `secretRef` when setting the metadata `storageAccessKey`. The value `external-azure-storage-key` represents the AKV secret created earlier

Ensure that you replace `<Your Storage Account Name>` with the value from step 1.1.
With those changes in place, we are ready to rebuild the backend background processor container image, update Azure Container Apps Env, and redeploy a new revision.

### 4. Deploy a New Revision of the Backend Background Processor App to ACA
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;

namespace TasksTracker.TasksManager.Backend.Svc
namespace TasksTracker.Processor.Backend.Svc
{
public class AppInsightsTelemetryInitializer : ITelemetryInitializer
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;

namespace TasksTracker.TasksManager.Frontend.Ui
namespace TasksTracker.WebPortal.Frontend.Ui
{
public class AppInsightsTelemetryInitializer : ITelemetryInitializer
{
Expand Down
2 changes: 1 addition & 1 deletion docs/aca/08-aca-monitoring/Program-Backend.Svc-dotnet8.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.ApplicationInsights.Extensibility;
using TasksTracker.TasksManager.Backend.Svc;
using TasksTracker.Processor.Backend.Svc;

var builder = WebApplication.CreateBuilder(args);

Expand Down
2 changes: 1 addition & 1 deletion docs/aca/08-aca-monitoring/Program-Backend.Svc-dotnet9.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

builder.Services.AddApplicationInsightsTelemetry();
builder.Services.Configure<TelemetryConfiguration>((o) => {
o.TelemetryInitializers.Add(new TasksTracker.TasksManager.Backend.Svc.AppInsightsTelemetryInitializer());
o.TelemetryInitializers.Add(new TasksTracker.Processor.Backend.Svc.AppInsightsTelemetryInitializer());
});

builder.Services.AddControllers().AddDapr();
Expand Down
2 changes: 1 addition & 1 deletion docs/aca/08-aca-monitoring/Program-Frontend.UI-dotnet8.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.ApplicationInsights.Extensibility;
using TasksTracker.TasksManager.Frontend.Ui;
using TasksTracker.WebPortal.Frontend.Ui;

var builder = WebApplication.CreateBuilder(args);

Expand Down
2 changes: 1 addition & 1 deletion docs/aca/08-aca-monitoring/Program-Frontend.UI-dotnet9.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Add services to the container.
builder.Services.AddApplicationInsightsTelemetry();
builder.Services.Configure<TelemetryConfiguration>((o) => {
o.TelemetryInitializers.Add(new TasksTracker.TasksManager.Frontend.Ui.AppInsightsTelemetryInitializer());
o.TelemetryInitializers.Add(new TasksTracker.WebPortal.Frontend.Ui.AppInsightsTelemetryInitializer());
});

builder.Services.AddRazorPages();
Expand Down
10 changes: 5 additions & 5 deletions docs/aca/08-aca-monitoring/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ To incorporate the SDK, use the NuGet reference below in the `csproj` file of th
--8<-- "docs/aca/08-aca-monitoring/Backend.Api-dotnet8.csproj"
```

=== "TasksTracker.TasksManager.Backend.Svc.csproj"
=== "TasksTracker.Processor.Backend.Svc.csproj"

```xml hl_lines="12"
--8<-- "docs/aca/08-aca-monitoring/Backend.Svc-dotnet8.csproj"
```

=== "TasksTracker.TasksManager.Frontend.Ui.csproj"
=== "TasksTracker.WebPortal.Frontend.Ui.csproj"

```xml hl_lines="11"
--8<-- "docs/aca/08-aca-monitoring/Frontend.Ui-dotnet8.csproj"
Expand All @@ -79,13 +79,13 @@ To incorporate the SDK, use the NuGet reference below in the `csproj` file of th
--8<-- "docs/aca/08-aca-monitoring/Backend.Api-dotnet9.csproj"
```

=== "TasksTracker.TasksManager.Backend.Svc.csproj"
=== "TasksTracker.Processor.Backend.Svc.csproj"

```xml hl_lines="11"
--8<-- "docs/aca/08-aca-monitoring/Backend.Svc-dotnet9.csproj"
```

=== "TasksTracker.TasksManager.Frontend.Ui.csproj"
=== "TasksTracker.WebPortal.Frontend.Ui.csproj"

```xml hl_lines="11"
--8<-- "docs/aca/08-aca-monitoring/Frontend.Ui-dotnet9.csproj"
Expand Down Expand Up @@ -183,7 +183,7 @@ Next, we need to register this `AppInsightsTelemetryInitializer` class in **Prog

In the previous module, we've used Dapr Secret Store to store connection strings and keys. In this module we will demonstrate how we can use another approach to secrets in Container Apps.

We need to set the Application Insights Instrumentation Key so that the projects are able to send telemetry data to the Application Insights instance. We are going to set this via secrets and environment variables once we redeploy the Container Apps and create new revisions. Locally, we can set it in each appsettings.json file. Obtain the key from the variable:
We need to set the Application Insights Instrumentation Key so that the projects are able to send telemetry data to the Application Insights instance. We are going to set this via secrets and environment variables once we redeploy the Container Apps and create new revisions. Locally, we can **set it in each appsettings.json** file. Obtain the key from the variable:

```shell
$APPINSIGHTS_INSTRUMENTATIONKEY
Expand Down
15 changes: 10 additions & 5 deletions docs/aca/12-optimize-containers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ Our original `Dockerfile` files look like this:
--8<-- "docs/aca/12-optimize-containers/Frontend.Ui.Dockerfile"
```

```shell
cd ~\TasksTracker.ContainerApps
From the TasksTracker.ContainerApps directory, run the following commands:

```shell
docker build -t backend-api-status-quo -f .\TasksTracker.TasksManager.Backend.Api\Dockerfile .
docker build -t backend-svc-status-quo -f .\TasksTracker.Processor.Backend.Svc\Dockerfile .
docker build -t frontend-ui-status-quo -f .\TasksTracker.WebPortal.Frontend.Ui\Dockerfile .
Expand All @@ -77,6 +77,8 @@ For example, the Backend API image is comprised of two images, 451 packages, and

The VS Code Docker extension produces a Dockerfile that's helpful for development but not as ideal for creation of production containers. We can significantly simplify and streamline the files (note that `publish` builds for `Release` by default, so we don't need to declare the configuration). These changes do not immediately impact image size yet.

Create three new files, `Dockerfile.concise` in each of their respective directories:

=== "Concise Backend.API Dockerfile"
```Dockerfile
--8<-- "docs/aca/12-optimize-containers/Backend.Api.Dockerfile.concise"
Expand All @@ -92,7 +94,7 @@ The VS Code Docker extension produces a Dockerfile that's helpful for developmen
--8<-- "docs/aca/12-optimize-containers/Frontend.Ui.Dockerfile.concise"
```

Create three new files, `Dockerfile.concise` in each of their respective directories, then run the following commands from the project root directory to build the concise images. All images will build, but they will continue to essentially be identical to the status quo images.
Run the following commands from the project root directory to build the concise images. All images will build, but they will continue to essentially be identical to the status quo images.

```shell
docker build -t backend-api-concise -f .\TasksTracker.TasksManager.Backend.Api\Dockerfile.concise .\TasksTracker.TasksManager.Backend.Api
Expand All @@ -106,6 +108,8 @@ docker image list

Microsoft and Ubuntu's creator, Canonical, collaborated on the concept of a [chiseled image for .NET](https://learn.microsoft.com/dotnet/core/docker/container-images#scenario-based-images){target=_blank}. Take a general-purpose base image and start chiseling away until you are left with an image that contains nothing more than the bare necessities to run your workload. No shell, no package manager, no bloat.

Create three new files, `Dockerfile.chiseled` in each of their respective directories:

=== "Chiseled Backend.API Dockerfile"
```Dockerfile
--8<-- "docs/aca/12-optimize-containers/Backend.Api.Dockerfile.chiseled"
Expand All @@ -121,7 +125,7 @@ Microsoft and Ubuntu's creator, Canonical, collaborated on the concept of a [chi
--8<-- "docs/aca/12-optimize-containers/Frontend.Ui.Dockerfile.chiseled"
```

Create three new files, `Dockerfile.chiseled` in each of their respective directories, then run the following commands from the project root directory to build the chiseled images:
Run the following commands from the project root directory to build the chiseled images:

```shell
docker build -t backend-api-chiseled -f .\TasksTracker.TasksManager.Backend.Api\Dockerfile.chiseled .\TasksTracker.TasksManager.Backend.Api
Expand All @@ -139,7 +143,6 @@ This image is comprised of one image, 331 packages, and has five vulnerabilities

![Backend API Status Quo Image Stats](../../assets/images/12-optimize-containers/backend-api-chiseled-image-stats.png)


#### 1.4 Deploying the Updated Images

While the image is vastly reduced, what hasn't changed is the functionality of the API. Whether you are executing it locally or deploying to Azure, the Backend API will continue to function as it always has. However, now it has less vulnerabilities, less time to transfer from the registry, less startup time, and less of a memory footprint. Furthermore, 16 MB is the uncompressed image. With compression, we are likely to continue dropping in size.
Expand Down Expand Up @@ -208,6 +211,8 @@ The Backend API and the Backend Svc projects are all but identical while the Fro
| Backend Svc Concise | 226 MB | 0 MB | | 2 | 451 | 25 |
| Backend Svc Chiseled | 119 MB | 107 MB | 56.6% | 1 | 328 | 2 |

--8<-- "snippets/persist-state.md:module12"

## Review

In this module, we have accomplished two objectives:
Expand Down
10 changes: 5 additions & 5 deletions docs/aca/30-appendix/01-run-debug-dapr-app-vscode.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ To accomplish this, open file `launch.json` and add the two configurations shown
Make sure you append the configurations below to the existing array instead of replacing what you have. This way you will preserve your existing configuration and simply add two new ones.

??? example "Looking for complete launch.json?"

=== "launch.json"

```json
--8<-- "https://raw.githubusercontent.com/Azure/aca-dotnet-workshop/main/.vscode/launch.json"
```
Expand Down Expand Up @@ -46,9 +46,9 @@ Now we will add 4 tasks, for each application, there will be a task to support t
??? tip "Curious to learn more about the tasks.json file above?"

* The tasks with the label `backend-api-dapr-debug` will invoke the `daprd` task. This task is similar to calling dapr run from CLI.
* We are setting the appPort, httpPort, and grpcPort properties (grpcPort is needed in future modules when we start using the state manager building block.
* We are setting the appPort, httpPort, and grpcPort properties (grpcPort is needed in future modules when we start using the state manager building block.
If you didn't set it, you might face a similar [issue](https://github.com/dapr/dotnet-sdk/issues/609){target=_blank})
* We are setting the componentsPath property. This is needed when start working with the state manager, pub/sub, etc.
* We are setting the "componentsPath" property. This is needed when start working with the state manager, pub/sub, etc.
* We are setting the dependsOn property, so this means this task will fire after the dependsOn tasks complete successfully. We need to add those dependsOn tasks.
* The tasks with the label `daprd-down-backend-api` will terminate the Dapr Sidecar process. This will be used for the `postDebug` activity in configuration.json.
* For a complete list of available properties please check this [link.](https://docs.dapr.io/developing-applications/ides/vscode/vscode-how-to-debug-multiple-dapr-apps/#daprd-parameter-table){target=_blank}
Expand Down Expand Up @@ -85,7 +85,7 @@ Next let's add the dependsOn tasks. Open `tasks.json` and add the tasks below:
??? example "Looking for complete tasks.json?"

=== "tasks.json"

```json
--8<-- "https://raw.githubusercontent.com/Azure/aca-dotnet-workshop/main/.vscode/tasks.json"
```
Expand Down
8 changes: 8 additions & 0 deletions snippets/dapr-run-backend-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ dapr run `
--app-id tasksmanager-backend-api `
--app-port $API_APP_PORT `
--dapr-http-port 3500 `
--scheduler-host-address "" `
--app-ssl `
-- dotnet run --launch-profile https
```

!!! note
An [issue with dapr-scheduler](https://github.com/Azure/aca-dotnet-workshop/issues/168){target=_blank} presently exists with Dapr 1.4. However, this should not affect the labs negatively.
--8<-- [end:basic]

<!-- Dapr Components snippet -->
Expand All @@ -22,7 +26,11 @@ dapr run `
--app-port $API_APP_PORT `
--dapr-http-port 3500 `
--app-ssl `
--scheduler-host-address "" `
--resources-path "../components" `
-- dotnet run --launch-profile https
```

!!! note
An [issue with dapr-scheduler](https://github.com/Azure/aca-dotnet-workshop/issues/168){target=_blank} presently exists with Dapr 1.4. However, this should not affect the labs negatively.
--8<-- [end:dapr-components]
4 changes: 4 additions & 0 deletions snippets/dapr-run-backend-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ dapr run `
--app-id tasksmanager-backend-processor `
--app-port $BACKEND_SERVICE_APP_PORT `
--dapr-http-port 3502 `
--scheduler-host-address "" `
--app-ssl `
--resources-path "../components" `
-- dotnet run --launch-profile https
```

!!! note
An [issue with dapr-scheduler](https://github.com/Azure/aca-dotnet-workshop/issues/168){target=_blank} presently exists with Dapr 1.4. However, this should not affect the labs negatively.
--8<-- [end:dapr-components]
4 changes: 4 additions & 0 deletions snippets/dapr-run-frontend-webapp.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ dapr run `
--app-id tasksmanager-frontend-webapp `
--app-port $UI_APP_PORT `
--dapr-http-port 3501 `
--scheduler-host-address "" `
--app-ssl `
-- dotnet run --launch-profile https
```

!!! note
An [issue with dapr-scheduler](https://github.com/Azure/aca-dotnet-workshop/issues/168){target=_blank} presently exists with Dapr 1.4. However, this should not affect the labs negatively.
--8<-- [end:basic]
2 changes: 1 addition & 1 deletion snippets/persist-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@

--8<-- [start:module12]

- Navigate to the root and persist the module to Git.
Navigate to the root and persist the module to Git.

```shell
git add .
Expand Down

0 comments on commit 6d4e99a

Please sign in to comment.