Skip to content

Commit 3562c72

Browse files
Infrastructure to acquire db log for running migrations added in User managment and Centralized logging Apis. Docker-compose update for the Integration Portal and db2 health check
1 parent 84405e0 commit 3562c72

File tree

7 files changed

+78
-15
lines changed

7 files changed

+78
-15
lines changed

CentralizedLoggingApi/CentralizedLoggingApi.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CentralizedLoggingApi/Program.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using CentralizedLoggingApi;
22
using CentralizedLoggingApi.Data;
33
using CentralizedLoggingApi.DTO.Auth;
4+
using CentralizedLoggingApi.Infrastructure;
45
using CentralizedLoggingApi.Middlewares;
56
using Microsoft.AspNetCore.Authentication.JwtBearer;
67
using Microsoft.EntityFrameworkCore;
@@ -134,12 +135,20 @@
134135

135136
app.UseAuthorization();
136137

138+
app.MapControllers();
137139

138140

141+
const string GlobalLock = "IMIS_GLOBAL_MIGRATE_SEED"; // <-- same string used in BOTH APIs
142+
await app.MigrateAndSeedWithSqlLockAsync<LoggingDbContext>(
143+
connectionStringName: "MasterConnection", // change if your name differs
144+
globalLockName: GlobalLock,
145+
seedAsync: async (sp, ct) =>
146+
{
147+
// IMPORTANT: remove Migrate() inside your seeder
148+
// Old: DbSeeder.Seed(IServiceProvider) (sync). Wrap to awaitable:
149+
DbSeeder.Seed(sp);
150+
await Task.CompletedTask;
151+
});
139152

140-
app.MapControllers();
141-
142-
// Seed sample data
143-
DbSeeder.Seed(app.Services);
144153

145154
app.Run();
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"ConnectionStrings": {
3-
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=CentralizedLoggingDB;Trusted_Connection=True;MultipleActiveResultSets=true"
3+
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=CentralizedLoggingDB;Trusted_Connection=True;MultipleActiveResultSets=true",
4+
"MasterConnection": "Server=(localdb)\\mssqllocaldb;Trusted_Connection=True;MultipleActiveResultSets=true"
45
}
56
}

CentralizedLoggingApi/appsettings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,4 @@
3030
"Key": "dmVyeV9sb25nX2Rldl9rZXlfY2hhbmdlX2luX3Byb2RfMTIzNDU2Nzg5MA==",
3131
"ExpiresMinutes": 60
3232
}
33-
3433
}

UserManagementApi/Program.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using UserManagementApi;
88
using UserManagementApi.Data;
99
using UserManagementApi.DTO.Auth;
10+
using UserManagementApi.Infrastructure;
1011
using UserManagementApi.Middlewares;
1112

1213
var builder = WebApplication.CreateBuilder(args);
@@ -135,6 +136,19 @@
135136
app.MapControllers();
136137

137138
// Seed sample data
138-
DbSeeder.Seed(app.Services);
139+
//DbSeeder.Seed(app.Services);
140+
141+
const string GlobalLock = "IMIS_GLOBAL_MIGRATE_SEED"; // <-- same string used in BOTH APIs
142+
await app.MigrateAndSeedWithSqlLockAsync<AppDbContext>(
143+
connectionStringName: "MasterConnection", // change if your name differs
144+
globalLockName: GlobalLock,
145+
seedAsync: async (sp, ct) =>
146+
{
147+
// IMPORTANT: remove Migrate() inside your seeder
148+
// Old: DbSeeder.Seed(IServiceProvider) (sync). Wrap to awaitable:
149+
DbSeeder.Seed(sp);
150+
await Task.CompletedTask;
151+
});
152+
139153

140154
app.Run();

UserManagementApi/UserManagementApi.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.yml

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,57 @@
11
services:
22
api:
3-
build: ./CentralizedLoggingApi
3+
build:
4+
context: .
5+
dockerfile: CentralizedLoggingApi/Dockerfile
46
container_name: centralized_logging_api
57
environment:
68
- ASPNETCORE_ENVIRONMENT=Production
79
ports:
810
- "5000:8080" # Map host:container for HTTP
911
- "5001:8081" # Map host:container for HTTPS (if your app supports it)
1012
depends_on:
11-
- db
13+
db:
14+
condition: service_healthy
15+
1216
volumes:
1317
- ./CentralizedLoggingApi/logs:/app/logs
1418

1519
userapi:
16-
build: ./UserManagementApi
20+
build:
21+
context: .
22+
dockerfile: UserManagementApi/Dockerfile
1723
container_name: user_management_api
1824
environment:
1925
- ASPNETCORE_ENVIRONMENT=Production
2026
ports:
2127
- "6000:8080" # Host 6000 -> container 8080 (HTTP)
2228
# - "6001:8081" # Optional HTTPS mapping if your app listens on 8081
2329
depends_on:
24-
- db
30+
db:
31+
condition: service_healthy
32+
2533
volumes:
2634
- ./UserManagementApi/logs:/app/logs
2735

36+
web:
37+
build:
38+
context: .
39+
dockerfile: ApiIntegrationMvc/Dockerfile
40+
container_name: api_integration_web
41+
environment:
42+
- ASPNETCORE_ENVIRONMENT=Production
43+
- ASPNETCORE_URLS=http://+:8080
44+
# Point the web app to APIs by service name (DNS provided by Compose)
45+
- Services__CentralizedLogging__BaseUrl=http://api:8080
46+
- Services__UserManagement__BaseUrl=http://userapi:8080
47+
ports:
48+
- "7000:8080" # browse http://localhost:7000
49+
depends_on:
50+
api:
51+
condition: service_started
52+
userapi:
53+
condition: service_started
54+
2855
db:
2956
image: mcr.microsoft.com/mssql/server:2022-latest
3057
container_name: centralized_logging_db
@@ -34,10 +61,11 @@ services:
3461
ports:
3562
- "1433:1433"
3663
healthcheck:
37-
test: ["CMD", "/opt/mssql-tools/bin/sqlcmd", "-S", "localhost", "-U", "sa", "-P", "Bisp@123", "-Q", "SELECT 1"]
38-
interval: 10s
39-
retries: 10
40-
start_period: 30s
64+
test: ["CMD-SHELL", "/opt/mssql-tools18/bin/sqlcmd -S localhost,1433 -U sa -P 'Bisp@123' -C -Q \"SELECT 1\""]
65+
interval: 10s
66+
timeout: 5s
67+
retries: 10
68+
start_period: 30s
4169
volumes:
4270
- sql_data:/var/opt/mssql
4371

0 commit comments

Comments
 (0)