|
| 1 | +using Aspire.Hosting.Azure; |
1 | 2 | using AspireDevTunnels.AppHost.Extensions; |
2 | 3 |
|
3 | 4 | var builder = DistributedApplication.CreateBuilder(args); |
|
8 | 9 | var foundryResourceName = builder.AddParameter("FoundryResourceName"); |
9 | 10 | var foundryProjectName = builder.AddParameter("FoundryProjectName"); |
10 | 11 | var appInsightsName = builder.AddParameter("ApplicationInsightsName"); |
| 12 | +var uniqueSuffix = builder.Configuration["Parameters:UniqueSuffix"] ?? throw new InvalidOperationException("Please set the 'Parameters:UniqueSuffix' configuration value to a unique suffix for resource names."); |
11 | 13 |
|
12 | 14 | var appInsights = builder.AddAzureApplicationInsights("app-insights") |
13 | 15 | .RunAsExisting(appInsightsName, rg); |
14 | 16 |
|
15 | 17 | var foundry = builder.AddAzureAIFoundry("ai-foundry") |
16 | 18 | .RunAsExisting(foundryResourceName, rg); |
17 | 19 |
|
18 | | -var pg = builder.AddAzurePostgresFlexibleServer("pg"); |
| 20 | +var devtunnel = builder.AddDevTunnel($"mcp-devtunnel-{uniqueSuffix}"); |
19 | 21 |
|
20 | | -if (builder.Configuration["Parameters:PostgresName"] is not null) |
| 22 | +IResourceBuilder<IResourceWithConnectionString> storeManagerUser; |
| 23 | +IResourceBuilder<AzurePostgresFlexibleServerDatabaseResource>? zava = null; |
| 24 | + |
| 25 | +if (builder.Configuration["ConnectionStrings:Postgres"] is not null) |
21 | 26 | { |
22 | | - pg.RunAsExisting(builder.AddParameter("PostgresName"), rg); |
| 27 | + storeManagerUser = builder.AddConnectionString("store-manager", ReferenceExpression.Create($"{builder.Configuration["ConnectionStrings:Postgres"]}")); |
23 | 28 | } |
24 | 29 | else |
25 | 30 | { |
26 | | - pg.RunAsContainer(configureContainer: containerBuilder => |
| 31 | + var pg = builder.AddAzurePostgresFlexibleServer("pg"); |
| 32 | + if (builder.Configuration["Parameters:PostgresName"] is not null) |
27 | 33 | { |
28 | | - containerBuilder |
29 | | - .WithPgAdmin() |
30 | | - .WithInitFiles(Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "scripts")) |
31 | | - // Use the pgvector image for PostgreSQL with pgvector extension |
32 | | - .WithImage("pgvector/pgvector", "pg17") |
33 | | - .WithLifetime(ContainerLifetime.Persistent); |
34 | | - }); |
35 | | -} |
36 | | - |
37 | | - |
38 | | -var zava = pg.AddDatabase("zava"); |
39 | | -var storeManagerUser = zava.AddPostgresAccount( |
40 | | - "store-manager", |
41 | | - builder.AddParameter("store-manager-user", "store_manager"), |
42 | | - builder.AddParameter("store-manager-password", "StoreManager123!")); |
| 34 | + pg.RunAsExisting(builder.AddParameter("PostgresName"), rg); |
| 35 | + } |
| 36 | + else |
| 37 | + { |
| 38 | + pg.RunAsContainer(configureContainer: containerBuilder => |
| 39 | + { |
| 40 | + containerBuilder |
| 41 | + .WithPgAdmin() |
| 42 | + .WithInitFiles(Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "scripts")) |
| 43 | + // Use the pgvector image for PostgreSQL with pgvector extension |
| 44 | + .WithImage("pgvector/pgvector", "pg17") |
| 45 | + .WithLifetime(ContainerLifetime.Persistent); |
| 46 | + }); |
43 | 47 |
|
44 | | -var devtunnel = builder.AddDevTunnel("mcp-devtunnel"); |
| 48 | + } |
| 49 | + zava = pg.AddDatabase("zava"); |
| 50 | + storeManagerUser = zava.AddPostgresAccount( |
| 51 | + "store-manager", |
| 52 | + builder.AddParameter("store-manager-user", "store_manager"), |
| 53 | + builder.AddParameter("store-manager-password", "StoreManager123!")); |
| 54 | +} |
45 | 55 |
|
46 | 56 | var dotnetMcpServer = builder.AddProject<Projects.McpAgentWorkshop_McpServer>("dotnet-mcp-server") |
47 | 57 | .WithReference(storeManagerUser) |
48 | | - .WaitFor(zava) |
49 | 58 | .WithDevTunnel(devtunnel) |
50 | 59 | .WithReference(appInsights) |
51 | 60 | .WithReference(foundry) |
52 | 61 | .WaitFor(foundry); |
53 | 62 |
|
| 63 | +if (zava is not null) |
| 64 | +{ |
| 65 | + dotnetMcpServer.WaitFor(zava); |
| 66 | +} |
| 67 | + |
54 | 68 | var dotnetAgentApp = builder.AddProject<Projects.McpAgentWorkshop_WorkshopApi>("dotnet-agent-app") |
55 | 69 | .WithReference(dotnetMcpServer) |
56 | 70 | .WaitFor(dotnetMcpServer) |
|
75 | 89 | { |
76 | 90 | var foundryEndpoint = builder.AddParameter("FoundryEndpoint"); |
77 | 91 | var aoai = builder.AddParameter("AzureOpenAIEndpoint"); |
78 | | - builder.AddPythonWorkshop(zava, devtunnel, appInsights, foundryEndpoint, chatDeployment, embeddingDeployment, aoai); |
| 92 | + builder.AddPythonWorkshop(storeManagerUser, devtunnel, appInsights, foundryEndpoint, chatDeployment, embeddingDeployment, aoai); |
79 | 93 | } |
80 | 94 |
|
81 | 95 | builder.Build().Run(); |
0 commit comments