Skip to content

Commit 8143d9f

Browse files
Simplify Aspire multi-replica configuration (#236)
1 parent de37b7f commit 8143d9f

File tree

9 files changed

+15
-76
lines changed

9 files changed

+15
-76
lines changed

src/DrawTogether.AppHost/AkkaManagementExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public static IResourceBuilder<ProjectResource> ConfigureAkkaManagementForApp(th
3131
.WithEnvironment("AkkaSettings__RemoteOptions__PublicHostName", "localhost")
3232
.WithEnvironment("AkkaSettings__AkkaManagementOptions__Enabled", "true")
3333
.WithEnvironment("AkkaSettings__AkkaManagementOptions__DiscoveryMethod", "AzureTableStorage")
34+
.WithEnvironment("AkkaSettings__AkkaManagementOptions__RequiredContactPointsNr", config.Replicas.ToString())
3435
.WithEnvironment("AkkaSettings__AkkaManagementOptions__FilterOnFallbackPort", "false");
3536

3637
return appBuilder;
@@ -68,7 +69,7 @@ public static IResourceBuilder<ContainerResource> ConfigureAkkaManagementForApp(
6869
appBuilder
6970
.WithEnvironment("AkkaSettings__AkkaManagementOptions__Enabled", "true")
7071
.WithEnvironment("AkkaSettings__AkkaManagementOptions__DiscoveryMethod", "AzureTableStorage")
71-
.WithEnvironment("AkkaSettings__AkkaManagementOptions__RequiredContactPointsNr", "1")
72+
.WithEnvironment("AkkaSettings__AkkaManagementOptions__RequiredContactPointsNr", config.Replicas.ToString())
7273
.WithEnvironment("AkkaSettings__AkkaManagementOptions__FilterOnFallbackPort", "false");
7374

7475
return appBuilder;

src/DrawTogether.AppHost/Configuration.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,4 @@ public class DrawTogetherConfiguration
2323
/// Only relevant when <see cref="UseAkkaManagement"/> is enabled.
2424
/// </summary>
2525
public int Replicas { get; set; } = 1;
26-
27-
public DeployEnvironment DeployEnvironment { get; set; } = DeployEnvironment.Local;
2826
}

src/DrawTogether.AppHost/DeployEnvironment.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/DrawTogether.AppHost/Program.cs

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,15 @@
2828
.WaitFor(db)
2929
.WithReference(db);
3030

31-
if (drawTogetherAspireConfig.DeployEnvironment == DeployEnvironment.Docker)
32-
{
33-
var drawTogether = builder.AddDockerfile("DrawTogether-1", "../../", "./src/DrawTogether/DockerFile")
34-
.WithImage("draw-together", "latest")
35-
.WithReference(db, "DefaultConnection")
36-
.ConfigureAkkaManagementForApp(drawTogetherAspireConfig)
37-
.WaitForCompletion(migrationService);
38-
39-
foreach (var index in Enumerable.Range(2, drawTogetherAspireConfig.Replicas - 1))
40-
{
41-
builder.AddContainer($"DrawTogether-{index}", "draw-together")
42-
.WithReference(db, "DefaultConnection")
43-
.ConfigureAkkaManagementForApp(drawTogetherAspireConfig)
44-
.WaitFor(drawTogether);
45-
}
46-
47-
// https://github.com/petabridge/pbm-sidecar - used to run `pbm` commands on the DrawTogether actor system
48-
var pbmSidecar = builder.AddContainer("pbm-sidecar", "petabridge/pbm:latest")
49-
.WaitFor(drawTogether);
50-
}
51-
else
52-
{
53-
var drawTogether = builder.AddProject<Projects.DrawTogether>("DrawTogether")
54-
.WithReplicas(drawTogetherAspireConfig.Replicas)
55-
.WithReference(db, "DefaultConnection")
56-
.WaitForCompletion(migrationService)
57-
.ConfigureAkkaManagementForApp(drawTogetherAspireConfig);
58-
59-
// https://github.com/petabridge/pbm-sidecar - used to run `pbm` commands on the DrawTogether actor system
60-
var pbmSidecar = builder.AddContainer("pbm-sidecar", "petabridge/pbm:latest")
61-
.WaitFor(drawTogether);
62-
}
31+
var drawTogether = builder.AddProject<Projects.DrawTogether>("DrawTogether")
32+
.WithReplicas(drawTogetherAspireConfig.Replicas)
33+
.WithReference(db, "DefaultConnection")
34+
.WaitForCompletion(migrationService)
35+
.ConfigureAkkaManagementForApp(drawTogetherAspireConfig);
36+
37+
// https://github.com/petabridge/pbm-sidecar - used to run `pbm` commands on the DrawTogether actor system
38+
var pbmSidecar = builder.AddContainer("pbm-sidecar", "petabridge/pbm:latest")
39+
.WaitFor(drawTogether);
6340

6441
builder
6542
.Build()

src/DrawTogether.AppHost/appsettings.Development.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@
44
"Default": "Information",
55
"Microsoft.AspNetCore": "Warning"
66
}
7-
},
8-
"DrawTogether": {
9-
"DeployEnvironment": "Local"
107
}
118
}

src/DrawTogether.AppHost/appsettings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"DrawTogether": {
1010
"UseVolumes": true,
1111
"UseAkkaManagement": true,
12-
"Replicas": 3,
13-
"DeployEnvironment": "Docker"
12+
"Replicas": 3
1413
}
1514
}

src/DrawTogether/Config/AkkaConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public static AkkaConfigurationBuilder ConfigureNetwork(this AkkaConfigurationBu
9090
options.ContactPointDiscovery.PortName = settings.AkkaManagementOptions.PortName;
9191
options.ContactPointDiscovery.RequiredContactPointsNr = settings.AkkaManagementOptions.RequiredContactPointsNr;
9292
options.ContactPointDiscovery.ContactWithAllContactPoints = true;
93+
options.ContactPointDiscovery.StableMargin = TimeSpan.FromSeconds(5);
9394

9495
options.ContactPoint.FilterOnFallbackPort = settings.AkkaManagementOptions.FilterOnFallbackPort;
9596
}, autoStart: true);

src/DrawTogether/DockerFile

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/DrawTogether.End2End.Tests/DrawTogetherFixture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public async Task InitializeAsync()
1313
{
1414
var builder = await DistributedApplicationTestingBuilder.CreateAsync<Projects.DrawTogether_AppHost>([
1515
"DrawTogether:UseVolumes=false",
16-
"DrawTogether:UseAkkaManagement=false"
16+
"DrawTogether:UseAkkaManagement=false",
17+
"DrawTogether:Replicas=1"
1718
]);
1819

1920
_app = await builder.BuildAsync();

0 commit comments

Comments
 (0)