Skip to content

Commit

Permalink
Add Dapr sidecar port environment variables (#4086)
Browse files Browse the repository at this point in the history
* Add Dapr sidecar port environment variablea

* Cast int to string?

* Fix
  • Loading branch information
frankbuckley authored Aug 5, 2024
1 parent 4c96d90 commit db86cef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Net.Sockets;
using static Aspire.Hosting.Dapr.CommandLineArgs;

Expand Down Expand Up @@ -148,6 +149,9 @@ public async Task BeforeStartAsync(DistributedApplicationModel appModel, Cancell
var http = daprCli.GetEndpoint("http");
var grpc = daprCli.GetEndpoint("grpc");
context.EnvironmentVariables.TryAdd("DAPR_HTTP_PORT", http.Port.ToString(CultureInfo.InvariantCulture));
context.EnvironmentVariables.TryAdd("DAPR_GRPC_PORT", grpc.Port.ToString(CultureInfo.InvariantCulture));
context.EnvironmentVariables.TryAdd("DAPR_GRPC_ENDPOINT", grpc);
context.EnvironmentVariables.TryAdd("DAPR_HTTP_ENDPOINT", http);
}));
Expand Down
3 changes: 3 additions & 0 deletions tests/Aspire.Hosting.Tests/Dapr/DaprTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public async Task WithDaprSideCarAddsAnnotationAndSidecarResource()
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(container, DistributedApplicationOperation.Run, TestServiceProvider.Instance);
var sidecarArgs = await ArgumentEvaluator.GetArgumentListAsync(sideCarCli);

Assert.Equal("3500", config["DAPR_HTTP_PORT"]);
Assert.Equal("50001", config["DAPR_GRPC_PORT"]);

Assert.Equal("http://localhost:3500", config["DAPR_HTTP_ENDPOINT"]);
Assert.Equal("http://localhost:50001", config["DAPR_GRPC_ENDPOINT"]);

Expand Down

0 comments on commit db86cef

Please sign in to comment.