Skip to content

Commit e270445

Browse files
authored
Optimized speed to load codespaces with prebuilds (#7)
* Start up docker compose on postCreate once again * Added dotnet projects to docker compose. Added host name env vars, * Added a db profile in docker compose to only load up db during oncreate * Remove postCreate afterall * Try fix access denied problem * Try the updateContentCommand instead * Added start.sh to manage the start of all services * Still getting access denied error. Let's not build from script * Try use dotnet run instead * Add missing path to docker compose * Wait till all the services run in onCreate
1 parent 6b524b9 commit e270445

File tree

17 files changed

+274
-71
lines changed

17 files changed

+274
-71
lines changed

.devcontainer/devcontainer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"DOTNET_NOLOGO": "true"
99
},
1010
"onCreateCommand": "chmod +x /workspaces/developer-bootcamp/polyglot-persistence/onCreateCommand.sh && /workspaces/developer-bootcamp/polyglot-persistence/onCreateCommand.sh",
11-
"postCreateCommand": "chmod +x /workspaces/developer-bootcamp/polyglot-persistence/postCreateCommand.sh && /workspaces/developer-bootcamp/polyglot-persistence/postCreateCommand.sh",
1211
"forwardPorts": [27017, 5432, 6379, 2113, 1113],
1312
"portsAttributes": {
1413
"2113": {

polyglot-persistence/.devcontainer/Dockerfile

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

polyglot-persistence/.devcontainer/devcontainer.json

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

polyglot-persistence/Common/Common.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>

polyglot-persistence/DemoWeb/PostgresService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public class PostgresService
1010
public PostgresService(IConfiguration configuration, ILogger<PostgresService> logger)
1111
{
1212
_logger = logger;
13-
_connectionString = configuration.GetConnectionString("PostgreSQL")
14-
?? "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=postgres";
13+
var postgresHost = Environment.GetEnvironmentVariable("POSTGRES_HOST") ?? "localhost";
14+
_connectionString = $"Host={postgresHost};Port=5432;Database=postgres;Username=postgres;Password=postgres";
1515

1616
_logger.LogInformation("PostgreSQL connection string: {ConnectionString}",
1717
_connectionString.Replace("Password=", "Password=***"));

polyglot-persistence/DemoWeb/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
builder.Services.AddSignalR();
1212

1313
// Register Redis services
14+
var redisHost = Environment.GetEnvironmentVariable("REDIS_HOST") ?? "localhost";
1415
builder.Services.AddSingleton<IConnectionMultiplexer>(sp =>
15-
ConnectionMultiplexer.Connect("localhost:6379"));
16+
ConnectionMultiplexer.Connect($"{redisHost}:6379"));
1617
builder.Services.AddSingleton<RedisService>();
1718

1819
// Register PostgreSQL service
@@ -44,4 +45,6 @@
4445
// Map SignalR hub
4546
app.MapHub<TopProductsHub>("/topProductsHub");
4647

47-
app.Run();
48+
app.Run();
49+
50+
Console.WriteLine($"{AppDomain.CurrentDomain.FriendlyName} started");

polyglot-persistence/DemoWeb/Properties/launchSettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"commandName": "Project",
1414
"dotnetRunMessages": true,
1515
"launchBrowser": true,
16-
"applicationUrl": "http://localhost:5108",
16+
"applicationUrl": "http://0.0.0.0:5108",
1717
"environmentVariables": {
1818
"ASPNETCORE_ENVIRONMENT": "Development"
1919
}
@@ -22,7 +22,7 @@
2222
"commandName": "Project",
2323
"dotnetRunMessages": true,
2424
"launchBrowser": true,
25-
"applicationUrl": "https://localhost:7164;http://localhost:5108",
25+
"applicationUrl": "https://0.0.0.0:7164;http://0.0.0.0:5108",
2626
"environmentVariables": {
2727
"ASPNETCORE_ENVIRONMENT": "Development"
2828
}

polyglot-persistence/DemoWeb/appsettings.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
2-
"ConnectionStrings": {
3-
"PostgreSQL": "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=postgres"
4-
},
52
"Logging": {
63
"LogLevel": {
74
"Default": "Information",

polyglot-persistence/MongoProjection/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
Console.WriteLine($"{AppDomain.CurrentDomain.FriendlyName} started");
99

1010
// Connect to MongoDB
11-
var mongoCollection = new MongoClient("mongodb://localhost:27017").GetDatabase("polyglot-persistence").GetCollection<BsonDocument>("total-payment");
11+
var mongoHost = Environment.GetEnvironmentVariable("MONGO_HOST") ?? "localhost";
12+
var mongoCollection = new MongoClient($"mongodb://{mongoHost}:27017").GetDatabase("polyglot-persistence").GetCollection<BsonDocument>("total-payment");
1213

1314
// Connect to EventStoreDB
14-
var esdb = new EventStoreClient(EventStoreClientSettings.Create("esdb://admin:changeit@localhost:2113?tls=false"));
15+
var esdbHost = Environment.GetEnvironmentVariable("ESDB_HOST") ?? "localhost";
16+
var esdb = new EventStoreClient(EventStoreClientSettings.Create($"esdb://admin:changeit@{esdbHost}:2113?tls=false"));
1517

1618
var checkpointValue = mongoCollection // Get the checkpoint value from MongoDB..
1719
.Find(Builders<BsonDocument>.Filter.Eq("_id", "total")) // from the total document's..

polyglot-persistence/PostgresProjection/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626
// Connect to PostgreSQL and EventStoreDB //
2727
// -------------------------------------- //
2828

29-
var postgres = new PostgresDataAccess(new NpgsqlConnection("Host=localhost;Port=5432;Database=postgres;Username=postgres"));
30-
var esdb = new EventStoreClient(EventStoreClientSettings.Create("esdb://admin:changeit@localhost:2113?tls=false"));
29+
var postgresHost = Environment.GetEnvironmentVariable("POSTGRES_HOST") ?? "localhost";
30+
var postgres = new PostgresDataAccess(new NpgsqlConnection($"Host={postgresHost};Port=5432;Database=postgres;Username=postgres"));
31+
32+
var esdbHost = Environment.GetEnvironmentVariable("ESDB_HOST") ?? "localhost";
33+
var esdb = new EventStoreClient(EventStoreClientSettings.Create($"esdb://admin:changeit@{esdbHost}:2113?tls=false"));
3134

3235
postgres.Execute(CartProjection.GetCreateCartTableCommand()); // Create the checkpoint table if it doesn't exist
3336
postgres.Execute(Checkpoint.GetCreateTableCommand()); // Create the checkpoint table if it doesn't exist

0 commit comments

Comments
 (0)