From 1297c80ac5ae66813d951f7fa044d672735d58c1 Mon Sep 17 00:00:00 2001 From: Manuel Menegazzo Date: Thu, 13 Jun 2024 22:43:48 +0200 Subject: [PATCH 01/12] up Signed-off-by: Manuel Menegazzo --- examples/Actor/DemoActor/DemoActor.csproj | 22 ++++++++++------- examples/Actor/DemoActor/Dockerfile | 29 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 examples/Actor/DemoActor/Dockerfile diff --git a/examples/Actor/DemoActor/DemoActor.csproj b/examples/Actor/DemoActor/DemoActor.csproj index 1ee37fdbe..a274b39f2 100644 --- a/examples/Actor/DemoActor/DemoActor.csproj +++ b/examples/Actor/DemoActor/DemoActor.csproj @@ -1,13 +1,17 @@  - - net6 - - - - - - - + + net6 + + + + + + + + + + + diff --git a/examples/Actor/DemoActor/Dockerfile b/examples/Actor/DemoActor/Dockerfile new file mode 100644 index 000000000..1d879c782 --- /dev/null +++ b/examples/Actor/DemoActor/Dockerfile @@ -0,0 +1,29 @@ +FROM mcr.microsoft.com/dotnet/aspnet:6.0-jammy-chiseled AS base +WORKDIR /app +EXPOSE 5010 + +FROM mcr.microsoft.com/dotnet/sdk:6.0-jammy AS build +WORKDIR / +# Copy base projects +COPY ["examples/Actor/DemoActor/", "examples/Actor/DemoActor/"] +# Copy shared dependencies +COPY ["examples/Actor/IDemoActor/", "examples/Actor/IDemoActor/"] +COPY ["src/Dapr.Actors/", "src/Dapr.Actors/"] +COPY ["src/Dapr.Actors.AspNetCore/", "src/Dapr.Actors.AspNetCore/"] +COPY ["src/Dapr.Client/", "src/Dapr.Client/"] +# Restore the project and build it +WORKDIR "/examples/Actor/DemoActor" +RUN dotnet restore "DemoActor.csproj" +RUN dotnet build "DemoActor.csproj" -c Release -o /app/build + +# Publish the project +FROM build AS publish +RUN dotnet publish "DemoActor.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app +# Set environment variables +ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false +# Copy published files +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "DemoActor.dll"] \ No newline at end of file From 8a826428e95ff393dd32f7a63eda90210ed53c27 Mon Sep 17 00:00:00 2001 From: Manuel Menegazzo Date: Mon, 17 Jun 2024 18:55:57 +0200 Subject: [PATCH 02/12] Fixed build Signed-off-by: Manuel Menegazzo --- examples/Actor/DemoActor/Dockerfile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/Actor/DemoActor/Dockerfile b/examples/Actor/DemoActor/Dockerfile index 1d879c782..b1fb9f9ef 100644 --- a/examples/Actor/DemoActor/Dockerfile +++ b/examples/Actor/DemoActor/Dockerfile @@ -1,16 +1,15 @@ -FROM mcr.microsoft.com/dotnet/aspnet:6.0-jammy-chiseled AS base +FROM mcr.microsoft.com/dotnet/aspnet:6.0-jammy-chiseled-extra AS base WORKDIR /app EXPOSE 5010 -FROM mcr.microsoft.com/dotnet/sdk:6.0-jammy AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build WORKDIR / # Copy base projects COPY ["examples/Actor/DemoActor/", "examples/Actor/DemoActor/"] -# Copy shared dependencies +# Copy dependencies COPY ["examples/Actor/IDemoActor/", "examples/Actor/IDemoActor/"] -COPY ["src/Dapr.Actors/", "src/Dapr.Actors/"] -COPY ["src/Dapr.Actors.AspNetCore/", "src/Dapr.Actors.AspNetCore/"] -COPY ["src/Dapr.Client/", "src/Dapr.Client/"] +COPY ["src/", "src/"] +COPY ["properties/", "properties/"] # Restore the project and build it WORKDIR "/examples/Actor/DemoActor" RUN dotnet restore "DemoActor.csproj" From 91e49b8016dddfea86b31c75c01e12b8924114a1 Mon Sep 17 00:00:00 2001 From: Manuel Menegazzo Date: Mon, 17 Jun 2024 19:43:21 +0200 Subject: [PATCH 03/12] Added scripts for image build Signed-off-by: Manuel Menegazzo --- examples/Actor/build-container.ps1 | 3 +++ examples/Actor/build-container.sh | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 examples/Actor/build-container.ps1 create mode 100644 examples/Actor/build-container.sh diff --git a/examples/Actor/build-container.ps1 b/examples/Actor/build-container.ps1 new file mode 100644 index 000000000..a2672ee3b --- /dev/null +++ b/examples/Actor/build-container.ps1 @@ -0,0 +1,3 @@ +cd ../../ + +docker build --file ./examples/Actor/DemoActor/Dockerfile -t demo-actor:latest . \ No newline at end of file diff --git a/examples/Actor/build-container.sh b/examples/Actor/build-container.sh new file mode 100644 index 000000000..3989f34e7 --- /dev/null +++ b/examples/Actor/build-container.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +cd ../../ + +docker build --file ./examples/Actor/DemoActor/Dockerfile -t demo-actor:latest . \ No newline at end of file From 62431f64420d1f75d5d5c48fefbff69833b9974f Mon Sep 17 00:00:00 2001 From: Manuel Menegazzo Date: Mon, 17 Jun 2024 19:54:18 +0200 Subject: [PATCH 04/12] Added readme Build and push Docker image Signed-off-by: Manuel Menegazzo --- .../Actor/{ => DemoActor}/build-container.ps1 | 2 +- .../Actor/{ => DemoActor}/build-container.sh | 2 +- examples/Actor/README.md | 24 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) rename examples/Actor/{ => DemoActor}/build-container.ps1 (86%) rename examples/Actor/{ => DemoActor}/build-container.sh (87%) diff --git a/examples/Actor/build-container.ps1 b/examples/Actor/DemoActor/build-container.ps1 similarity index 86% rename from examples/Actor/build-container.ps1 rename to examples/Actor/DemoActor/build-container.ps1 index a2672ee3b..8c5e432a9 100644 --- a/examples/Actor/build-container.ps1 +++ b/examples/Actor/DemoActor/build-container.ps1 @@ -1,3 +1,3 @@ -cd ../../ +cd ../../../ docker build --file ./examples/Actor/DemoActor/Dockerfile -t demo-actor:latest . \ No newline at end of file diff --git a/examples/Actor/build-container.sh b/examples/Actor/DemoActor/build-container.sh similarity index 87% rename from examples/Actor/build-container.sh rename to examples/Actor/DemoActor/build-container.sh index 3989f34e7..35c5df617 100644 --- a/examples/Actor/build-container.sh +++ b/examples/Actor/DemoActor/build-container.sh @@ -1,5 +1,5 @@ #!/bin/sh -cd ../../ +cd ../../../ docker build --file ./examples/Actor/DemoActor/Dockerfile -t demo-actor:latest . \ No newline at end of file diff --git a/examples/Actor/README.md b/examples/Actor/README.md index ddc42cecf..ebe0e9813 100644 --- a/examples/Actor/README.md +++ b/examples/Actor/README.md @@ -80,3 +80,27 @@ On Windows: ```sh curl -X POST http://127.0.0.1:3500/v1.0/actors/DemoActor/abc/method/GetData ``` + +### Build and push Docker image +You can build the docker image of `DemoActor` service by running the following commands in the `DemoActor` project directory: + +On Linux, MacOS: +``` Bash +. ./build-container.sh +``` + +On Windows: +``` PowerShell +powershell .\build-container.ps1 +``` + +The build produce and image with tag `demo-actor:latest`. +Now the image can be pushed to your Docker registry by running the following commands: + +``` Bash +# Replace with your Docker registry +docket tag demo-actor:latest /demo-actor:latest + +# Push the image to your Docker registry +docker push /demo-actor:latest +``` \ No newline at end of file From dc1cd7d313810139a20e77896a8aa1658832c774 Mon Sep 17 00:00:00 2001 From: Manuel Menegazzo Date: Mon, 17 Jun 2024 20:58:56 +0200 Subject: [PATCH 05/12] Added demo-actor.yaml Signed-off-by: Manuel Menegazzo --- examples/Actor/DemoActor/Startup.cs | 2 +- examples/Actor/DemoActor/demo-actor.yaml | 50 ++++++++++++++++++++++++ examples/Actor/README.md | 40 +++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 examples/Actor/DemoActor/demo-actor.yaml diff --git a/examples/Actor/DemoActor/Startup.cs b/examples/Actor/DemoActor/Startup.cs index c04dfdcba..da2b9e764 100644 --- a/examples/Actor/DemoActor/Startup.cs +++ b/examples/Actor/DemoActor/Startup.cs @@ -1,4 +1,4 @@ -// ------------------------------------------------------------------------ +// ------------------------------------------------------------------------ // Copyright 2021 The Dapr Authors // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/examples/Actor/DemoActor/demo-actor.yaml b/examples/Actor/DemoActor/demo-actor.yaml new file mode 100644 index 000000000..8f8a7741c --- /dev/null +++ b/examples/Actor/DemoActor/demo-actor.yaml @@ -0,0 +1,50 @@ +kind: Service +apiVersion: v1 +metadata: + name: demoactor + labels: + app: demoactor +spec: + selector: + app: demoactor + ports: + - protocol: TCP + port: 5010 + targetPort: app-port + type: LoadBalancer +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: demoactor + labels: + app: demoactor +spec: + replicas: 1 + selector: + matchLabels: + app: demoactor + template: + metadata: + labels: + app: demoactor + annotations: + dapr.io/enabled: "true" + dapr.io/app-id: "demoactor" + dapr.io/app-port: "5010" + dapr.io/enable-api-logging: "true" + spec: + containers: + - name: demoactor + # image: /demo-actor:latest + image: demo-actor:latest + # if you are using docker desktop, you can use imagePullPolicy: Never to use local image + imagePullPolicy: Never + env: + - name: APP_PORT + value: "5010" + - name: ASPNETCORE_URLS + value: "http://+:5010" + ports: + - name: app-port + containerPort: 5010 \ No newline at end of file diff --git a/examples/Actor/README.md b/examples/Actor/README.md index ebe0e9813..f19bf6b5f 100644 --- a/examples/Actor/README.md +++ b/examples/Actor/README.md @@ -103,4 +103,44 @@ docket tag demo-actor:latest /demo-actor:latest # Push the image to your Docker registry docker push /demo-actor:latest +``` + +### Deploy the Actor service to Kubernetes +#### Prerequisites +- A Kubernetes cluster with `kubectl` configured to access it. +- Dapr v1.13+ installed on the Kubernetes cluster. Follow the instructions [here](https://docs.dapr.io/getting-started/install-dapr-kubernetes/). +- A Docker registry where you pushed the `DemoActor` image. + +#### Deploy the Actor service +To deploy the `DemoActor` service to Kubernetes, you can use the provided Kubernetes manifest file `demo-actor.yaml` in the `DemoActor` project directory. +Before applying the manifest file, replace the image name in the manifest file with the image name you pushed to your Docker registry. + +Part to update in `demo-actor.yaml`: +``` YAML +image: /demoactor:latest +``` + +To install the application in `default` namespace, run the following command: + +``` Bash +kubectl apply -f demo-actor.yaml +``` + +This will deploy the `DemoActor` service to Kubernetes. You can check the status of the deployment by running: + +``` Bash +kubectl get pods -n default +``` + +The manifest create 2 services: + +- `demoactor` service: The service that hosts the `DemoActor` actor. +- `demoactor-dapr` service: The service that hosts the Dapr sidecar for the `DemoActor` actor. + +### Make client calls to the deployed Actor service +To make client calls to the deployed `DemoActor` service, you can use the `ActorClient` project. +Before running the client, update the `DAPR_HTTP_PORT` environment variable in the `ActorClient` project directory to the port on which Dapr is running in the Kubernetes cluster. + +``` Bash +export DAPR_HTTP_PORT= ``` \ No newline at end of file From 14ad2e6f9c20ccb9295ae513a188ae1392f7fd24 Mon Sep 17 00:00:00 2001 From: Manuel Menegazzo Date: Mon, 17 Jun 2024 21:43:32 +0200 Subject: [PATCH 06/12] Fixed typo Signed-off-by: Manuel Menegazzo --- examples/Actor/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Actor/README.md b/examples/Actor/README.md index f19bf6b5f..b66bc0a69 100644 --- a/examples/Actor/README.md +++ b/examples/Actor/README.md @@ -99,7 +99,7 @@ Now the image can be pushed to your Docker registry by running the following com ``` Bash # Replace with your Docker registry -docket tag demo-actor:latest /demo-actor:latest +docker tag demo-actor:latest /demo-actor:latest # Push the image to your Docker registry docker push /demo-actor:latest From 926e0b70c47bac6b09cbdd53a698fcddc112876b Mon Sep 17 00:00:00 2001 From: Manuel Menegazzo Date: Mon, 24 Jun 2024 20:09:16 +0200 Subject: [PATCH 07/12] Updated guide, fixed invocation throw curl Signed-off-by: Manuel Menegazzo --- examples/Actor/DemoActor/demo-actor.yaml | 20 +++++++++++++++++++- examples/Actor/README.md | 23 +++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/examples/Actor/DemoActor/demo-actor.yaml b/examples/Actor/DemoActor/demo-actor.yaml index 8f8a7741c..18df1561e 100644 --- a/examples/Actor/DemoActor/demo-actor.yaml +++ b/examples/Actor/DemoActor/demo-actor.yaml @@ -1,3 +1,14 @@ +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: statestore +spec: + type: state.in-memory + version: v1 + metadata: + - name: actorStateStore + value: "true" +--- kind: Service apiVersion: v1 metadata: @@ -8,9 +19,14 @@ spec: selector: app: demoactor ports: - - protocol: TCP + - name: app-port + protocol: TCP port: 5010 targetPort: app-port + - name: dapr-http + protocol: TCP + port: 3500 + targetPort: 3500 type: LoadBalancer --- apiVersion: apps/v1 @@ -33,12 +49,14 @@ spec: dapr.io/app-id: "demoactor" dapr.io/app-port: "5010" dapr.io/enable-api-logging: "true" + dapr.io/sidecar-listen-addresses: "0.0.0.0" spec: containers: - name: demoactor # image: /demo-actor:latest image: demo-actor:latest # if you are using docker desktop, you can use imagePullPolicy: Never to use local image + # built with build-container.sh/ps1 imagePullPolicy: Never env: - name: APP_PORT diff --git a/examples/Actor/README.md b/examples/Actor/README.md index b66bc0a69..ffb9394e7 100644 --- a/examples/Actor/README.md +++ b/examples/Actor/README.md @@ -112,6 +112,12 @@ docker push /demo-actor:latest - A Docker registry where you pushed the `DemoActor` image. #### Deploy the Actor service +For quick deployment you can install dapr in dev mode using the following command: + +``` Bash +dapr init -k --dev +``` + To deploy the `DemoActor` service to Kubernetes, you can use the provided Kubernetes manifest file `demo-actor.yaml` in the `DemoActor` project directory. Before applying the manifest file, replace the image name in the manifest file with the image name you pushed to your Docker registry. @@ -129,7 +135,7 @@ kubectl apply -f demo-actor.yaml This will deploy the `DemoActor` service to Kubernetes. You can check the status of the deployment by running: ``` Bash -kubectl get pods -n default +kubectl get pods -n default --watch ``` The manifest create 2 services: @@ -141,6 +147,19 @@ The manifest create 2 services: To make client calls to the deployed `DemoActor` service, you can use the `ActorClient` project. Before running the client, update the `DAPR_HTTP_PORT` environment variable in the `ActorClient` project directory to the port on which Dapr is running in the Kubernetes cluster. +On Linux, MacOS: +``` Bash +export DAPR_HTTP_PORT=3500 +``` + +Than port forward the `DemoActor` service to your local machine: + +``` Bash +kubectl port-forward svc/demoactor 3500:3500 +``` + +Now you can run the client project from the `ActorClient` directory: + ``` Bash -export DAPR_HTTP_PORT= +dotnet run ``` \ No newline at end of file From 1d2143e279759166b7edd02d75347301f829eb58 Mon Sep 17 00:00:00 2001 From: Manuel Menegazzo Date: Tue, 25 Jun 2024 21:41:39 +0200 Subject: [PATCH 08/12] Removed dockerfile, updated readme, removed ps1 and sh scripts Signed-off-by: Manuel Menegazzo --- all.sln | 14 +--------- examples/Actor/DemoActor/DemoActor.csproj | 9 ++++++- examples/Actor/DemoActor/Dockerfile | 28 -------------------- examples/Actor/DemoActor/build-container.ps1 | 3 --- examples/Actor/DemoActor/build-container.sh | 5 ---- examples/Actor/README.md | 14 +++------- 6 files changed, 13 insertions(+), 60 deletions(-) delete mode 100644 examples/Actor/DemoActor/Dockerfile delete mode 100644 examples/Actor/DemoActor/build-container.ps1 delete mode 100644 examples/Actor/DemoActor/build-container.sh diff --git a/all.sln b/all.sln index 0b95478f3..228047852 100644 --- a/all.sln +++ b/all.sln @@ -32,6 +32,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1BD1276E-D28A-45EA-89B1-6AD48471500D}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig + README.md = README.md EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapr.Actors.AspNetCore.Test", "test\Dapr.Actors.AspNetCore.Test\Dapr.Actors.AspNetCore.Test.csproj", "{9C1D6ABA-5EDE-4FA0-A8A9-0AB98CB74737}" @@ -347,16 +348,3 @@ Global SolutionGuid = {65220BF2-EAE1-4CB2-AA58-EBE80768CB40} EndGlobalSection EndGlobal -8-446B-AECD-DCC2CC871F73} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {65220BF2-EAE1-4CB2-AA58-EBE80768CB40} - EndGlobalSection -EndGlobal -C991940} = {DD020B34-460F-455F-8D17-CF4A949F100B} - {C74FBA78-13E8-407F-A173-4555AEE41FF3} = {A7F41094-8648-446B-AECD-DCC2CC871F73} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {65220BF2-EAE1-4CB2-AA58-EBE80768CB40} - EndGlobalSection -EndGlobal diff --git a/examples/Actor/DemoActor/DemoActor.csproj b/examples/Actor/DemoActor/DemoActor.csproj index a274b39f2..087022ecd 100644 --- a/examples/Actor/DemoActor/DemoActor.csproj +++ b/examples/Actor/DemoActor/DemoActor.csproj @@ -4,8 +4,15 @@ net6 + + true + true + demo-actor + mcr.microsoft.com/dotnet/runtime:6.0-jammy-chiseled-extra + + - + diff --git a/examples/Actor/DemoActor/Dockerfile b/examples/Actor/DemoActor/Dockerfile deleted file mode 100644 index b1fb9f9ef..000000000 --- a/examples/Actor/DemoActor/Dockerfile +++ /dev/null @@ -1,28 +0,0 @@ -FROM mcr.microsoft.com/dotnet/aspnet:6.0-jammy-chiseled-extra AS base -WORKDIR /app -EXPOSE 5010 - -FROM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build -WORKDIR / -# Copy base projects -COPY ["examples/Actor/DemoActor/", "examples/Actor/DemoActor/"] -# Copy dependencies -COPY ["examples/Actor/IDemoActor/", "examples/Actor/IDemoActor/"] -COPY ["src/", "src/"] -COPY ["properties/", "properties/"] -# Restore the project and build it -WORKDIR "/examples/Actor/DemoActor" -RUN dotnet restore "DemoActor.csproj" -RUN dotnet build "DemoActor.csproj" -c Release -o /app/build - -# Publish the project -FROM build AS publish -RUN dotnet publish "DemoActor.csproj" -c Release -o /app/publish - -FROM base AS final -WORKDIR /app -# Set environment variables -ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false -# Copy published files -COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "DemoActor.dll"] \ No newline at end of file diff --git a/examples/Actor/DemoActor/build-container.ps1 b/examples/Actor/DemoActor/build-container.ps1 deleted file mode 100644 index 8c5e432a9..000000000 --- a/examples/Actor/DemoActor/build-container.ps1 +++ /dev/null @@ -1,3 +0,0 @@ -cd ../../../ - -docker build --file ./examples/Actor/DemoActor/Dockerfile -t demo-actor:latest . \ No newline at end of file diff --git a/examples/Actor/DemoActor/build-container.sh b/examples/Actor/DemoActor/build-container.sh deleted file mode 100644 index 35c5df617..000000000 --- a/examples/Actor/DemoActor/build-container.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -cd ../../../ - -docker build --file ./examples/Actor/DemoActor/Dockerfile -t demo-actor:latest . \ No newline at end of file diff --git a/examples/Actor/README.md b/examples/Actor/README.md index ffb9394e7..e35cbf354 100644 --- a/examples/Actor/README.md +++ b/examples/Actor/README.md @@ -84,18 +84,12 @@ curl -X POST http://127.0.0.1:3500/v1.0/actors/DemoActor/abc/method/GetData ### Build and push Docker image You can build the docker image of `DemoActor` service by running the following commands in the `DemoActor` project directory: -On Linux, MacOS: ``` Bash -. ./build-container.sh -``` - -On Windows: -``` PowerShell -powershell .\build-container.ps1 +dotnet publish --os linux --arch x64 /t:PublishContainer -p ContainerImageTags='"latest"' ``` -The build produce and image with tag `demo-actor:latest`. -Now the image can be pushed to your Docker registry by running the following commands: +The build produce and image with tag `demo-actor:latest` and load it in the local registry. +Now the image can be pushed to your remote Docker registry by running the following commands: ``` Bash # Replace with your Docker registry @@ -152,7 +146,7 @@ On Linux, MacOS: export DAPR_HTTP_PORT=3500 ``` -Than port forward the `DemoActor` service to your local machine: +Than port-forward the `DemoActor` service to your local machine: ``` Bash kubectl port-forward svc/demoactor 3500:3500 From 3c9d46316a51ea5ba68a3157191bf68982f66377 Mon Sep 17 00:00:00 2001 From: Manuel Menegazzo Date: Tue, 25 Jun 2024 23:24:48 +0200 Subject: [PATCH 09/12] Updated base image Signed-off-by: Manuel Menegazzo <65919883+m3nax@users.noreply.github.com> Signed-off-by: Manuel Menegazzo --- examples/Actor/DemoActor/DemoActor.csproj | 2 +- examples/Actor/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Actor/DemoActor/DemoActor.csproj b/examples/Actor/DemoActor/DemoActor.csproj index 087022ecd..24a42ee0e 100644 --- a/examples/Actor/DemoActor/DemoActor.csproj +++ b/examples/Actor/DemoActor/DemoActor.csproj @@ -8,10 +8,10 @@ true true demo-actor - mcr.microsoft.com/dotnet/runtime:6.0-jammy-chiseled-extra + diff --git a/examples/Actor/README.md b/examples/Actor/README.md index e35cbf354..a7bb46c03 100644 --- a/examples/Actor/README.md +++ b/examples/Actor/README.md @@ -85,7 +85,7 @@ curl -X POST http://127.0.0.1:3500/v1.0/actors/DemoActor/abc/method/GetData You can build the docker image of `DemoActor` service by running the following commands in the `DemoActor` project directory: ``` Bash -dotnet publish --os linux --arch x64 /t:PublishContainer -p ContainerImageTags='"latest"' +dotnet publish --os linux --arch x64 /t:PublishContainer -p ContainerImageTags='"latest"' --self-contained ``` The build produce and image with tag `demo-actor:latest` and load it in the local registry. From ebe73b6e33dd5444c0368c1d251cdda5326bc6f1 Mon Sep 17 00:00:00 2001 From: Manuel Menegazzo <65919883+m3nax@users.noreply.github.com> Date: Tue, 25 Jun 2024 22:02:13 +0200 Subject: [PATCH 10/12] Update demo-actor.yaml Signed-off-by: Manuel Menegazzo <65919883+m3nax@users.noreply.github.com> Signed-off-by: Manuel Menegazzo --- examples/Actor/DemoActor/demo-actor.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/Actor/DemoActor/demo-actor.yaml b/examples/Actor/DemoActor/demo-actor.yaml index 18df1561e..99a8abd34 100644 --- a/examples/Actor/DemoActor/demo-actor.yaml +++ b/examples/Actor/DemoActor/demo-actor.yaml @@ -56,7 +56,6 @@ spec: # image: /demo-actor:latest image: demo-actor:latest # if you are using docker desktop, you can use imagePullPolicy: Never to use local image - # built with build-container.sh/ps1 imagePullPolicy: Never env: - name: APP_PORT @@ -65,4 +64,4 @@ spec: value: "http://+:5010" ports: - name: app-port - containerPort: 5010 \ No newline at end of file + containerPort: 5010 From a8a79801c599109d36ad7533490ee18d33dfcfc2 Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Tue, 25 Jun 2024 14:30:18 -0500 Subject: [PATCH 11/12] Added overload for DaprClient DI registration (#1289) * Added overload for DaprClient DI registration allowing the consumer to easily use values from injected services (e.g. IConfiguration). Signed-off-by: Whit Waldo * Added supporting unit test Signed-off-by: Whit Waldo --------- Signed-off-by: Whit Waldo Co-authored-by: Phillip Hoff Signed-off-by: Manuel Menegazzo --- .../DaprServiceCollectionExtensions.cs | 30 ++++++++++++++----- .../DaprServiceCollectionExtensionsTest.cs | 30 +++++++++++++++++++ 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/Dapr.AspNetCore/DaprServiceCollectionExtensions.cs b/src/Dapr.AspNetCore/DaprServiceCollectionExtensions.cs index 8491cb9b2..388015b80 100644 --- a/src/Dapr.AspNetCore/DaprServiceCollectionExtensions.cs +++ b/src/Dapr.AspNetCore/DaprServiceCollectionExtensions.cs @@ -31,18 +31,32 @@ public static class DaprServiceCollectionExtensions /// public static void AddDaprClient(this IServiceCollection services, Action configure = null) { - if (services is null) - { - throw new ArgumentNullException(nameof(services)); - } + ArgumentNullException.ThrowIfNull(services, nameof(services)); services.TryAddSingleton(_ => { var builder = new DaprClientBuilder(); - if (configure != null) - { - configure.Invoke(builder); - } + configure?.Invoke(builder); + + return builder.Build(); + }); + } + + /// + /// Adds Dapr client services to the provided . This does not include integration + /// with ASP.NET Core MVC. Use the AddDapr() extension method on IMvcBuilder to register MVC integration. + /// + /// The . + /// + public static void AddDaprClient(this IServiceCollection services, + Action configure) + { + ArgumentNullException.ThrowIfNull(services, nameof(services)); + + services.TryAddSingleton(serviceProvider => + { + var builder = new DaprClientBuilder(); + configure?.Invoke(serviceProvider, builder); return builder.Build(); }); diff --git a/test/Dapr.AspNetCore.Test/DaprServiceCollectionExtensionsTest.cs b/test/Dapr.AspNetCore.Test/DaprServiceCollectionExtensionsTest.cs index 614faf5e4..a82948cf3 100644 --- a/test/Dapr.AspNetCore.Test/DaprServiceCollectionExtensionsTest.cs +++ b/test/Dapr.AspNetCore.Test/DaprServiceCollectionExtensionsTest.cs @@ -48,6 +48,31 @@ public void AddDaprClient_RegistersDaprClientOnlyOnce() Assert.True(daprClient.JsonSerializerOptions.PropertyNameCaseInsensitive); } + [Fact] + public void AddDaprClient_RegistersUsingDependencyFromIServiceProvider() + { + + var services = new ServiceCollection(); + services.AddSingleton(); + services.AddDaprClient((provider, builder) => + { + var configProvider = provider.GetRequiredService(); + var caseSensitivity = configProvider.GetCaseSensitivity(); + + builder.UseJsonSerializationOptions(new JsonSerializerOptions + { + PropertyNameCaseInsensitive = caseSensitivity + }); + }); + + var serviceProvider = services.BuildServiceProvider(); + + DaprClientGrpc client = serviceProvider.GetRequiredService() as DaprClientGrpc; + + //Registers with case-insensitive as true by default, but we set as false above + Assert.False(client.JsonSerializerOptions.PropertyNameCaseInsensitive); + } + #if NET8_0_OR_GREATER [Fact] public void AddDaprClient_WithKeyedServices() @@ -65,5 +90,10 @@ public void AddDaprClient_WithKeyedServices() Assert.NotNull(daprClient); } #endif + + private class TestConfigurationProvider + { + public bool GetCaseSensitivity() => false; + } } } From 1adc9561c68b4ce409f31818142ef712ebc62e13 Mon Sep 17 00:00:00 2001 From: Phillip Hoff Date: Tue, 25 Jun 2024 13:46:25 -0700 Subject: [PATCH 12/12] Merge `release-1.13` back into `master` (#1285) * Update protos and related use for Dapr 1.13. (#1236) * Update protos and related use. Signed-off-by: Phillip Hoff * Update Dapr runtime version. Signed-off-by: Phillip Hoff * Init properties. Signed-off-by: Phillip Hoff --------- Signed-off-by: Phillip Hoff * Update artifact action versions. (#1240) Signed-off-by: Phillip Hoff * Make recursive true as default (#1243) Signed-off-by: Shivam Kumar * Fix for secret key transformation in multi-value scenarios (#1274) * Add repro test. Signed-off-by: Phillip Hoff * Fix for secret key transformation in multi-value scenarios. Signed-off-by: Phillip Hoff --------- Signed-off-by: Phillip Hoff * Update Dapr version numbers used during testing. Signed-off-by: Phillip Hoff --------- Signed-off-by: Phillip Hoff Signed-off-by: Shivam Kumar Co-authored-by: Shivam Kumar Signed-off-by: Manuel Menegazzo --- .github/workflows/itests.yml | 4 +-- .../DaprSecretStoreConfigurationProvider.cs | 11 +++++-- ...aprSecretStoreConfigurationProviderTest.cs | 29 +++++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/.github/workflows/itests.yml b/.github/workflows/itests.yml index 2c97343ed..00121c9f5 100644 --- a/.github/workflows/itests.yml +++ b/.github/workflows/itests.yml @@ -43,8 +43,8 @@ jobs: GOARCH: amd64 GOPROXY: https://proxy.golang.org DAPR_CLI_VER: 1.13.0 - DAPR_RUNTIME_VER: 1.13.0 - DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/release-1.13/install/install.sh + DAPR_RUNTIME_VER: 1.13.2 + DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/release-1.12/install/install.sh DAPR_CLI_REF: '' steps: - name: Set up Dapr CLI diff --git a/src/Dapr.Extensions.Configuration/DaprSecretStoreConfigurationProvider.cs b/src/Dapr.Extensions.Configuration/DaprSecretStoreConfigurationProvider.cs index 5991a7dad..ecd0ac91b 100644 --- a/src/Dapr.Extensions.Configuration/DaprSecretStoreConfigurationProvider.cs +++ b/src/Dapr.Extensions.Configuration/DaprSecretStoreConfigurationProvider.cs @@ -227,8 +227,15 @@ private async Task LoadAsync() $"A duplicate key '{key}' was found in the secret store '{store}'. Please remove any duplicates from your secret store."); } - data.Add(normalizeKey ? NormalizeKey(secretDescriptor.SecretName) : secretDescriptor.SecretName, - result[key]); + // The name of the key "as desired" by the user based on the descriptor. + // + // NOTE: This should vary only if a single secret of the same name is returned. + string desiredKey = StringComparer.Ordinal.Equals(key, secretDescriptor.SecretKey) ? secretDescriptor.SecretName : key; + + // The name of the key normalized based on the configured delimiters. + string normalizedKey = normalizeKey ? NormalizeKey(desiredKey) : desiredKey; + + data.Add(normalizedKey, result[key]); } } diff --git a/test/Dapr.Extensions.Configuration.Test/DaprSecretStoreConfigurationProviderTest.cs b/test/Dapr.Extensions.Configuration.Test/DaprSecretStoreConfigurationProviderTest.cs index d35275dd1..9bac31352 100644 --- a/test/Dapr.Extensions.Configuration.Test/DaprSecretStoreConfigurationProviderTest.cs +++ b/test/Dapr.Extensions.Configuration.Test/DaprSecretStoreConfigurationProviderTest.cs @@ -198,6 +198,35 @@ public void LoadSecrets_FromSecretStoreThatCanReturnsMultipleValues() config[secondSecretKey].Should().Be(secondSecretValue); } + [Fact] + public void LoadSecrets_FromSecretStoreThatCanReturnsMultivaluedValues() + { + var storeName = "store"; + var parentSecretKey = "connectionStrings"; + var firstSecretKey = "first_secret"; + var secondSecretKey = "second_secret"; + var firstSecretValue = "secret1"; + var secondSecretValue = "secret2"; + + var secretDescriptors = new[] + { + new DaprSecretDescriptor(parentSecretKey) + }; + + var daprClient = new Mock(); + + daprClient.Setup(c => c.GetSecretAsync(storeName, parentSecretKey, + It.IsAny>(), default)) + .ReturnsAsync(new Dictionary { { firstSecretKey, firstSecretValue }, { secondSecretKey, secondSecretValue } }); + + var config = CreateBuilder() + .AddDaprSecretStore(storeName, secretDescriptors, daprClient.Object) + .Build(); + + config[firstSecretKey].Should().Be(firstSecretValue); + config[secondSecretKey].Should().Be(secondSecretValue); + } + [Fact] public void LoadSecrets_FromSecretStoreWithADifferentSecretKeyAndName() {