Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
123 lines (100 loc) · 5.08 KB
/
Copy pathProgram.cs
File metadata and controls
123 lines (100 loc) · 5.08 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using eShop.AppHost;
var builder = DistributedApplication.CreateBuilder(args);
builder.AddForwardedHeaders();
var redis = builder.AddRedis("redis");
var rabbitMq = builder.AddRabbitMQ("eventbus")
.WithLifetime(ContainerLifetime.Persistent);
var postgres = builder.AddPostgres("postgres")
.WithImage("ankane/pgvector")
.WithImageTag("latest")
.WithLifetime(ContainerLifetime.Persistent);
var catalogDb = postgres.AddDatabase("catalogdb");
var identityDb = postgres.AddDatabase("identitydb");
var orderDb = postgres.AddDatabase("orderingdb");
var webhooksDb = postgres.AddDatabase("webhooksdb");
var launchProfileName = ShouldUseHttpForEndpoints() ? "http" : "https";
// Services
var identityApi = builder.AddProject<Projects.Identity_API>("identity-api", launchProfileName)
.WithExternalHttpEndpoints()
.WithReference(identityDb)
.WithHttpHealthCheck("/health");
var identityEndpoint = identityApi.GetEndpoint(launchProfileName);
var basketApi = builder.AddProject<Projects.Basket_API>("basket-api")
.WithReference(redis)
.WithReference(rabbitMq).WaitFor(rabbitMq)
.WithEnvironment("Identity__Url", identityEndpoint);
redis.WithParentRelationship(basketApi);
var catalogApi = builder.AddProject<Projects.Catalog_API>("catalog-api")
.WithReference(rabbitMq).WaitFor(rabbitMq)
.WithReference(catalogDb)
.WithEnvironment("OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT", "true")
.WithEnvironment("OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_METADATA", "true")
.WithEnvironment("OTEL_INSTRUMENTATION_GENAI_CAPTURE_TOOL_OUTPUT", "true")
.WithEnvironment("OTEL_INSTRUMENTATION_GENAI_CAPTURE_TOOL_INPUT", "true");
var orderingApi = builder.AddProject<Projects.Ordering_API>("ordering-api")
.WithReference(rabbitMq).WaitFor(rabbitMq)
.WithReference(orderDb).WaitFor(orderDb)
.WithHttpHealthCheck("/health")
.WithEnvironment("Identity__Url", identityEndpoint);
builder.AddProject<Projects.OrderProcessor>("order-processor")
.WithReference(rabbitMq).WaitFor(rabbitMq)
.WithReference(orderDb)
.WaitFor(orderingApi); // wait for the orderingApi to be ready because that contains the EF migrations
builder.AddProject<Projects.PaymentProcessor>("payment-processor")
.WithReference(rabbitMq).WaitFor(rabbitMq);
var webHooksApi = builder.AddProject<Projects.Webhooks_API>("webhooks-api")
.WithReference(rabbitMq).WaitFor(rabbitMq)
.WithReference(webhooksDb)
.WithEnvironment("Identity__Url", identityEndpoint);
// Reverse proxies
builder.AddYarp("mobile-bff")
.WithExternalHttpEndpoints()
.ConfigureMobileBffRoutes(catalogApi, orderingApi, identityApi);
// Apps
var webhooksClient = builder.AddProject<Projects.WebhookClient>("webhooksclient", launchProfileName)
.WithReference(webHooksApi)
.WithEnvironment("IdentityUrl", identityEndpoint);
var webApp = builder.AddProject<Projects.WebApp>("webapp", launchProfileName)
.WithExternalHttpEndpoints()
.WithUrls(c => c.Urls.ForEach(u => u.DisplayText = $"Online Store ({u.Endpoint?.EndpointName})"))
.WithReference(basketApi)
.WithReference(catalogApi)
.WithReference(orderingApi)
.WithReference(rabbitMq).WaitFor(rabbitMq)
.WaitFor(identityApi)
.WithEnvironment("IdentityUrl", identityEndpoint)
.WithEnvironment("OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT", "true")
.WithEnvironment("OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_METADATA", "true")
.WithEnvironment("OTEL_INSTRUMENTATION_GENAI_CAPTURE_TOOL_OUTPUT", "true")
.WithEnvironment("OTEL_INSTRUMENTATION_GENAI_CAPTURE_TOOL_INPUT", "true");
// set to true if you want to use OpenAI
bool useOpenAI = true;
if (useOpenAI)
{
builder.AddOpenAI(catalogApi, webApp, OpenAITarget.AzureOpenAIExistingWithKey); // set to AzureOpenAI if you want to use Azure OpenAI
}
bool useOllama = false;
if (useOllama)
{
builder.AddOllama(catalogApi, webApp);
}
// Wire up the callback urls (self referencing)
webApp.WithEnvironment("CallBackUrl", webApp.GetEndpoint(launchProfileName));
webhooksClient.WithEnvironment("CallBackUrl", webhooksClient.GetEndpoint(launchProfileName));
// Identity has a reference to all of the apps for callback urls, this is a cyclic reference
identityApi.WithEnvironment("BasketApiClient", basketApi.GetEndpoint("http"))
.WithEnvironment("OrderingApiClient", orderingApi.GetEndpoint("http"))
.WithEnvironment("WebhooksApiClient", webHooksApi.GetEndpoint("http"))
.WithEnvironment("WebhooksWebClient", webhooksClient.GetEndpoint(launchProfileName))
.WithEnvironment("WebAppClient", webApp.GetEndpoint(launchProfileName));
builder.Build().Run();
// For test use only.
// Looks for an environment variable that forces the use of HTTP for all the endpoints. We
// are doing this for ease of running the Playwright tests in CI.
static bool ShouldUseHttpForEndpoints()
{
const string EnvVarName = "ESHOP_USE_HTTP_ENDPOINTS";
var envValue = Environment.GetEnvironmentVariable(EnvVarName);
// Attempt to parse the environment variable value; return true if it's exactly "1".
return int.TryParse(envValue, out int result) && result == 1;
}