Enhance start-api-and-workers.sh and vibe-dev-server.sh scripts

- Added support for Swagger in the API by setting EnableSwagger environment variable.
- Implemented build error handling for both API and Workers, providing detailed feedback and suggestions for resolution.
- Updated vibe-dev-server.sh to start the API and Workers using Aspire, including improved logging and dashboard URL extraction.
- Enhanced waiting mechanisms for API readiness and Aspire dashboard availability, ensuring smoother startup experience.
This commit is contained in:
2025-12-31 05:23:07 +07:00
parent ab08e0241b
commit cef86a5025
9 changed files with 357 additions and 135 deletions

View File

@@ -11,36 +11,37 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.Npgsql" Version="8.1.0"/>
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0"/>
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="9.0.0"/>
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0"/>
<PackageReference Include="Essential.LoggerProvider.Elasticsearch" Version="1.3.2"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.5"/>
<PackageReference Include="Microsoft.Orleans.Core" Version="9.2.1"/>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1"/>
<PackageReference Include="NSwag.AspNetCore" Version="14.0.7"/>
<PackageReference Include="OrleansDashboard" Version="8.2.0"/>
<PackageReference Include="Sentry.AspNetCore" Version="5.5.1"/>
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1"/>
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.3.0"/>
<PackageReference Include="Serilog.Exceptions" Version="8.4.0"/>
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1"/>
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0"/>
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="10.0.0"/>
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.6.1"/>
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.6.1"/>
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.6.1"/>
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.6.1"/>
<PackageReference Include="xunit" Version="2.8.0"/>
<PackageReference Include="Polly" Version="8.4.0"/>
<PackageReference Include="Polly.Extensions.Http" Version="3.0.0"/>
<PackageReference Include="DotNetEnv" Version="3.1.1"/>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.Npgsql" Version="8.1.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="9.0.0" />
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
<PackageReference Include="Essential.LoggerProvider.Elasticsearch" Version="1.3.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.5" />
<PackageReference Include="Microsoft.Orleans.Core" Version="9.2.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="NSwag.AspNetCore" Version="14.0.7" />
<PackageReference Include="OrleansDashboard" Version="8.2.0" />
<PackageReference Include="Sentry.AspNetCore" Version="5.5.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.3.0" />
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="10.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.6.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.6.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.6.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.6.1" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="Polly" Version="8.4.0" />
<PackageReference Include="Polly.Extensions.Http" Version="3.0.0" />
<PackageReference Include="DotNetEnv" Version="3.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Managing.Bootstrap\Managing.Bootstrap.csproj"/>
<ProjectReference Include="..\Managing.Core\Managing.Core.csproj"/>
<ProjectReference Include="..\Managing.Bootstrap\Managing.Bootstrap.csproj" />
<ProjectReference Include="..\Managing.Core\Managing.Core.csproj" />
</ItemGroup>
<ItemGroup>
@@ -59,6 +60,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Extensions\"/>
<Folder Include="Extensions\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>05b5e3ae-42a0-4689-826a-9fe60d831704</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Managing.Api\Managing.Api.csproj" />
<ProjectReference Include="..\Managing.Workers\Managing.Workers.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,58 @@
using Aspire.Hosting;
var builder = DistributedApplication.CreateBuilder(args);
// Get task-specific configuration from environment variables
var taskId = Environment.GetEnvironmentVariable("TASK_ID") ?? "DEFAULT";
var portOffset = int.Parse(Environment.GetEnvironmentVariable("PORT_OFFSET") ?? "0");
var taskSlot = Environment.GetEnvironmentVariable("TASK_SLOT") ?? "1";
// Calculate ports based on task configuration
var apiPort = 5000 + portOffset;
var postgresPort = 5432 + portOffset;
var redisPort = 6379 + portOffset;
// Calculate Orleans ports from TASK_SLOT
var taskSlotInt = int.Parse(taskSlot);
var orleansSiloPort = 11111 + (taskSlotInt - 1) * 10;
var orleansGatewayPort = 30000 + (taskSlotInt - 1) * 10;
var orleansDashboardPort = 9999 + (taskSlotInt - 1);
// Database names
var dbName = $"managing_{taskId.ToLower()}";
var orleansDbName = $"orleans_{taskId.ToLower()}";
// Connection strings (using existing Docker containers managed by Docker Compose)
var postgresConnectionString = $"Host=localhost;Port={postgresPort};Database={dbName};Username=postgres;Password=postgres";
var postgresOrleansConnectionString = $"Host=localhost;Port={postgresPort};Database={orleansDbName};Username=postgres;Password=postgres";
var redisConnectionString = $"localhost:{redisPort}";
// Add API project
var api = builder.AddProject("api", "../Managing.Api/Managing.Api.csproj")
.WithHttpEndpoint(port: apiPort)
.WithEnvironment("TASK_ID", taskId)
.WithEnvironment("TASK_SLOT", taskSlot)
.WithEnvironment("PORT_OFFSET", portOffset.ToString())
.WithEnvironment("ASPNETCORE_ENVIRONMENT", "Development")
.WithEnvironment("EnableSwagger", "true")
.WithEnvironment("RUN_ORLEANS_GRAINS", "true")
.WithEnvironment("SILO_ROLE", "Trading")
.WithEnvironment("PostgreSql__ConnectionString", postgresConnectionString)
.WithEnvironment("PostgreSql__Orleans", postgresOrleansConnectionString)
.WithEnvironment("InfluxDb__Url", "http://localhost:8086/")
.WithEnvironment("InfluxDb__Token", "Fw2FPL2OwTzDHzSbR2Sd5xs0EKQYy00Q-hYKYAhr9cC1_q5YySONpxuf_Ck0PTjyUiF13xXmi__bu_pXH-H9zA==")
.WithEnvironment("ORLEANS_SILO_PORT", orleansSiloPort.ToString())
.WithEnvironment("ORLEANS_GATEWAY_PORT", orleansGatewayPort.ToString())
.WithEnvironment("ORLEANS_DASHBOARD_PORT", orleansDashboardPort.ToString());
// Add Workers project
var workers = builder.AddProject("workers", "../Managing.Workers/Managing.Workers.csproj")
.WithEnvironment("TASK_ID", taskId)
.WithEnvironment("TASK_SLOT", taskSlot)
.WithEnvironment("ASPNETCORE_ENVIRONMENT", "Development")
.WithEnvironment("PostgreSql__ConnectionString", postgresConnectionString)
.WithEnvironment("InfluxDb__Url", "http://localhost:8086/")
.WithEnvironment("InfluxDb__Token", "Fw2FPL2OwTzDHzSbR2Sd5xs0EKQYy00Q-hYKYAhr9cC1_q5YySONpxuf_Ck0PTjyUiF13xXmi__bu_pXH-H9zA==");
// Build and run
builder.Build().Run();

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}

View File

@@ -8,24 +8,25 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.11"/>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10"/>
<PackageReference Include="Sentry" Version="5.5.1"/>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.1.0"/>
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0"/>
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0"/>
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0"/>
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0"/>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.11" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
<PackageReference Include="Sentry" Version="5.5.1" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.1.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Managing.Bootstrap\Managing.Bootstrap.csproj"/>
<ProjectReference Include="..\Managing.Application\Managing.Application.csproj"/>
<ProjectReference Include="..\Managing.Application.Abstractions\Managing.Application.Abstractions.csproj"/>
<ProjectReference Include="..\Managing.Infrastructure.Database\Managing.Infrastructure.Databases.csproj"/>
<ProjectReference Include="..\Managing.Infrastructure.Exchanges\Managing.Infrastructure.Exchanges.csproj"/>
<ProjectReference Include="..\Managing.Common\Managing.Common.csproj"/>
<ProjectReference Include="..\Managing.Bootstrap\Managing.Bootstrap.csproj" />
<ProjectReference Include="..\Managing.Application\Managing.Application.csproj" />
<ProjectReference Include="..\Managing.Application.Abstractions\Managing.Application.Abstractions.csproj" />
<ProjectReference Include="..\Managing.Infrastructure.Database\Managing.Infrastructure.Databases.csproj" />
<ProjectReference Include="..\Managing.Infrastructure.Exchanges\Managing.Infrastructure.Exchanges.csproj" />
<ProjectReference Include="..\Managing.Common\Managing.Common.csproj" />
</ItemGroup>
</Project>

View File

@@ -70,6 +70,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Managing.Workers.Tests", "M
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Managing.Domain.Tests", "Managing.Domain.Tests\Managing.Domain.Tests.csproj", "{3F835B88-4720-49C2-A4A5-FED2C860C4C4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Managing.AppHost", "Managing.AppHost\Managing.AppHost.csproj", "{4712128B-F222-47C4-A347-AFF4E5BA02AE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -246,6 +248,14 @@ Global
{3F835B88-4720-49C2-A4A5-FED2C860C4C4}.Release|Any CPU.Build.0 = Release|Any CPU
{3F835B88-4720-49C2-A4A5-FED2C860C4C4}.Release|x64.ActiveCfg = Release|Any CPU
{3F835B88-4720-49C2-A4A5-FED2C860C4C4}.Release|x64.Build.0 = Release|Any CPU
{4712128B-F222-47C4-A347-AFF4E5BA02AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4712128B-F222-47C4-A347-AFF4E5BA02AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4712128B-F222-47C4-A347-AFF4E5BA02AE}.Debug|x64.ActiveCfg = Debug|Any CPU
{4712128B-F222-47C4-A347-AFF4E5BA02AE}.Debug|x64.Build.0 = Debug|Any CPU
{4712128B-F222-47C4-A347-AFF4E5BA02AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4712128B-F222-47C4-A347-AFF4E5BA02AE}.Release|Any CPU.Build.0 = Release|Any CPU
{4712128B-F222-47C4-A347-AFF4E5BA02AE}.Release|x64.ActiveCfg = Release|Any CPU
{4712128B-F222-47C4-A347-AFF4E5BA02AE}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE