-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathProgram.cs
69 lines (52 loc) · 2.21 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using Projects;
var builder = DistributedApplication.CreateBuilder(args);
// Databases
var basketStore = builder.AddRedis("BasketStore")
.WithRedisCommander();
var postgres = builder.AddPostgres("postgres")
.WithPgAdmin();
var catalogDb = postgres.AddDatabase("CatalogDB");
var orderDb = postgres.AddDatabase("OrderingDB");
// Identity Providers
var idp = builder.AddKeycloakContainer("idp", tag: "23.0")
.ImportRealms("../Keycloak/data/import");
// DB Manager Apps
builder.AddProject<Catalog_Data_Manager>("catalog-db-mgr")
.WithReference(catalogDb);
builder.AddProject<Ordering_Data_Manager>("ordering-db-mgr")
.WithReference(orderDb);
// API Apps
var catalogApi = builder.AddProject<Catalog_API>("catalog-api")
.WithReference(catalogDb);
var basketApi = builder.AddProject<Basket_API>("basket-api")
.WithReference(basketStore)
.WithReference(idp);
var orderingApi = builder.AddProject<Ordering_API>("ordering-api")
.WithReference(orderDb)
.WithReference(idp);
// Apps
var webApp = builder.AddProject<WebApp>("webapp")
.WithReference(basketApi)
.WithReference(catalogApi)
.WithReference(orderingApi)
.WithReference(idp, env: "Identity__ClientSecret");
// Inject the project URLs for Keycloak realm configuration
var webAppHttp = webApp.GetEndpoint("http");
var webAppHttps = webApp.GetEndpoint("https");
idp.WithEnvironment("WEBAPP_HTTP_CONTAINERHOST", webAppHttp);
idp.WithEnvironment("WEBAPP_HTTP", () => $"{webAppHttp.Scheme}://{webAppHttp.Host}:{webAppHttp.Port}");
if (webAppHttps.Exists)
{
idp.WithEnvironment("WEBAPP_HTTPS_CONTAINERHOST", webAppHttps);
idp.WithEnvironment("WEBAPP_HTTPS", () => $"{webAppHttps.Scheme}://{webAppHttps.Host}:{webAppHttps.Port}");
}
else
{
// Still need to set these environment variables so the KeyCloak realm import doesn't fail
idp.WithEnvironment("WEBAPP_HTTPS_CONTAINERHOST", webAppHttp);
idp.WithEnvironment("WEBAPP_HTTPS", () => $"{webAppHttp.Scheme}://{webAppHttp.Host}:{webAppHttp.Port}");
}
idp.WithEnvironment("ORDERINGAPI_HTTP", orderingApi.GetEndpoint("http"));
// Inject assigned URLs for Catalog API
catalogApi.WithEnvironment("CatalogOptions__PicBaseAddress", catalogApi.GetEndpoint("http"));
builder.Build().Run();