Skip to content

Commit 0effa85

Browse files
authored
Merge pull request #45 from microsoft/dotnet-fixes
2 parents b1f1f36 + 27ba5e3 commit 0effa85

File tree

5 files changed

+58
-30
lines changed

5 files changed

+58
-30
lines changed

infra/deploy.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ if (Test-Path $CSHARP_PROJECT_PATH) {
101101
dotnet user-secrets set "Azure:ResourceGroup" "$RESOURCE_GROUP_NAME" --project "$CSHARP_PROJECT_PATH"
102102
dotnet user-secrets set "Azure:Location" "$RG_LOCATION" --project "$CSHARP_PROJECT_PATH"
103103
dotnet user-secrets set "Azure:SubscriptionId" "$SUBSCRIPTION_ID" --project "$CSHARP_PROJECT_PATH"
104+
dotnet user-secrets set "Parameters:UniqueSuffix" "$UNIQUE_SUFFIX" --project "$CSHARP_PROJECT_PATH"
104105
}
105106

106107
# Clean up output.json

infra/deploy.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ if [ -f "$CSHARP_PROJECT_PATH" ]; then
9898
dotnet user-secrets set "Azure:ResourceGroup" "$RESOURCE_GROUP_NAME" --project "$CSHARP_PROJECT_PATH"
9999
dotnet user-secrets set "Azure:Location" "$AZURE_LOCATION" --project "$CSHARP_PROJECT_PATH"
100100
dotnet user-secrets set "Azure:SubscriptionId" "$AZURE_SUBSCRIPTION_ID" --project "$CSHARP_PROJECT_PATH"
101+
dotnet user-secrets set "Parameters:UniqueSuffix" "$UNIQUE_SUFFIX" --project "$CSHARP_PROJECT_PATH"
101102
fi
102103

103104
# Delete the output.json file

infra/skillable/lca-2-solution-variables.ps1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,24 @@ if (Test-Path $CSHARP_PROJECT_PATH) {
173173
if ($aiProjectName) {
174174
Log "Setting user-secret: Parameters:FoundryProjectName"
175175
dotnet user-secrets set "Parameters:FoundryProjectName" "$aiProjectName" --project "$CSHARP_PROJECT_PATH"
176-
} else {
176+
}
177+
else {
177178
Log "Skipping Parameters:FoundryProjectName - aiProjectName is null/empty"
178179
}
179180

180181
if ($aiFoundryName) {
181182
Log "Setting user-secret: Parameters:FoundryResourceName"
182183
dotnet user-secrets set "Parameters:FoundryResourceName" "$aiFoundryName" --project "$CSHARP_PROJECT_PATH"
183-
} else {
184+
}
185+
else {
184186
Log "Skipping Parameters:FoundryResourceName - aiFoundryName is null/empty"
185187
}
186188

187189
if ($applicationInsightsName) {
188190
Log "Setting user-secret: Parameters:ApplicationInsightsName"
189191
dotnet user-secrets set "Parameters:ApplicationInsightsName" "$applicationInsightsName" --project "$CSHARP_PROJECT_PATH"
190-
} else {
192+
}
193+
else {
191194
Log "Skipping Parameters:ApplicationInsightsName - applicationInsightsName is null/empty"
192195
}
193196

@@ -207,6 +210,13 @@ if (Test-Path $CSHARP_PROJECT_PATH) {
207210

208211
Log "Setting user-secret: Azure:SubscriptionId"
209212
dotnet user-secrets set "Azure:SubscriptionId" "$SubId" --project "$CSHARP_PROJECT_PATH"
213+
214+
Log "Setting ConnectionStrings:Postgres"
215+
$pgConnectionString = "Host=$AzurePgHost;Port=$AzurePgPort;Database=zava;Username=store_manager;Password=StoreManager123!;SSL Mode=Require;Trust Server Certificate=true;"
216+
dotnet user-secrets set "ConnectionStrings:Postgres" "$pgConnectionString" --project "$CSHARP_PROJECT_PATH"
217+
218+
Log "Setting Parameters:UniqueSuffix"
219+
dotnet user-secrets set "Parameters:UniqueSuffix" "$UniqueSuffix" --project "$CSHARP_PROJECT_PATH"
210220
}
211221
else {
212222
Log "C# project not found at expected location: $CSHARP_PROJECT_PATH. Skipping user-secrets configuration."
Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Aspire.Hosting.Azure;
12
using AspireDevTunnels.AppHost.Extensions;
23

34
var builder = DistributedApplication.CreateBuilder(args);
@@ -8,49 +9,62 @@
89
var foundryResourceName = builder.AddParameter("FoundryResourceName");
910
var foundryProjectName = builder.AddParameter("FoundryProjectName");
1011
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.");
1113

1214
var appInsights = builder.AddAzureApplicationInsights("app-insights")
1315
.RunAsExisting(appInsightsName, rg);
1416

1517
var foundry = builder.AddAzureAIFoundry("ai-foundry")
1618
.RunAsExisting(foundryResourceName, rg);
1719

18-
var pg = builder.AddAzurePostgresFlexibleServer("pg");
20+
var devtunnel = builder.AddDevTunnel($"mcp-devtunnel-{uniqueSuffix}");
1921

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)
2126
{
22-
pg.RunAsExisting(builder.AddParameter("PostgresName"), rg);
27+
storeManagerUser = builder.AddConnectionString("store-manager", ReferenceExpression.Create($"{builder.Configuration["ConnectionStrings:Postgres"]}"));
2328
}
2429
else
2530
{
26-
pg.RunAsContainer(configureContainer: containerBuilder =>
31+
var pg = builder.AddAzurePostgresFlexibleServer("pg");
32+
if (builder.Configuration["Parameters:PostgresName"] is not null)
2733
{
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+
});
4347

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+
}
4555

4656
var dotnetMcpServer = builder.AddProject<Projects.McpAgentWorkshop_McpServer>("dotnet-mcp-server")
4757
.WithReference(storeManagerUser)
48-
.WaitFor(zava)
4958
.WithDevTunnel(devtunnel)
5059
.WithReference(appInsights)
5160
.WithReference(foundry)
5261
.WaitFor(foundry);
5362

63+
if (zava is not null)
64+
{
65+
dotnetMcpServer.WaitFor(zava);
66+
}
67+
5468
var dotnetAgentApp = builder.AddProject<Projects.McpAgentWorkshop_WorkshopApi>("dotnet-agent-app")
5569
.WithReference(dotnetMcpServer)
5670
.WaitFor(dotnetMcpServer)
@@ -75,7 +89,7 @@
7589
{
7690
var foundryEndpoint = builder.AddParameter("FoundryEndpoint");
7791
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);
7993
}
8094

8195
builder.Build().Run();

src/csharp/McpAgentWorkshop.AppHost/Extensions.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ namespace Aspire.Hosting;
1111
public static class Extensions
1212
{
1313
static readonly string sourceFolder = Path.Combine(Environment.CurrentDirectory, "..", "..");
14-
static readonly string virtualEnvironmentPath = "/usr/local/python/current";
14+
static readonly string virtualEnvironmentPath = OperatingSystem.IsWindows() ?
15+
Path.Join(sourceFolder, "python", "workshop", ".venv") :
16+
"/usr/local/python/current";
1517

16-
public static IResourceBuilder<PythonAppResource> WithPostgres(this IResourceBuilder<PythonAppResource> builder, IResourceBuilder<AzurePostgresFlexibleServerDatabaseResource> db)
18+
public static IResourceBuilder<PythonAppResource> WithPostgres(this IResourceBuilder<PythonAppResource> builder, IResourceBuilder<IResourceWithConnectionString> db)
1719
{
1820
builder.WithEnvironment(async (ctx) =>
1921
{
@@ -30,7 +32,7 @@ public static IResourceBuilder<PythonAppResource> WithPostgres(this IResourceBui
3032

3133
public static IDistributedApplicationBuilder AddPythonWorkshop(
3234
this IDistributedApplicationBuilder builder,
33-
IResourceBuilder<AzurePostgresFlexibleServerDatabaseResource> zava,
35+
IResourceBuilder<IResourceWithConnectionString> storeManagerUser,
3436
IResourceBuilder<DevTunnelResource> devtunnel,
3537
IResourceBuilder<IResourceWithConnectionString> appInsights,
3638
IResourceBuilder<ParameterResource> foundryEndpoint,
@@ -41,7 +43,7 @@ public static IDistributedApplicationBuilder AddPythonWorkshop(
4143

4244

4345
var mcpServer = builder.AddPythonApp("python-mcp-server", Path.Combine(sourceFolder, "python", "mcp_server", "sales_analysis"), "sales_analysis.py", virtualEnvironmentPath: virtualEnvironmentPath)
44-
.WithPostgres(zava)
46+
.WithPostgres(storeManagerUser)
4547
.WithHttpEndpoint(env: "PORT")
4648
.WithOtlpExporter()
4749
.WithEnvironment("OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED", "true")
@@ -57,7 +59,7 @@ public static IDistributedApplicationBuilder AddPythonWorkshop(
5759
.WithEnvironment("AZURE_OPENAI_ENDPOINT", aoai)
5860
.WithEnvironment("APPLICATIONINSIGHTS_CONNECTION_STRING", appInsights)
5961
.WithEnvironment("AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED", "true")
60-
.WithPostgres(zava)
62+
.WithPostgres(storeManagerUser)
6163
.WithEnvironment("MAP_MCP_FUNCTIONS", "false")
6264
.WithReference(mcpServer)
6365
.WaitFor(mcpServer)

0 commit comments

Comments
 (0)