-
Notifications
You must be signed in to change notification settings - Fork 286
Adding Aspire!!!!!!!!!!!!!!!!!!!!!!!!!! #2797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maddymontaquila
wants to merge
9
commits into
Azure:main
Choose a base branch
from
maddymontaquila:maddy/aspire
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,003
−39
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b0227ed
HELP
maddymontaquila af9d3e7
OMG WE GOT THE HEALTH CHECK WORKING
DamianEdwards 8e3b98f
Update src/apphost/AppHost.cs
maddymontaquila d2cbdf2
Update .aspire/settings.json
maddymontaquila eff9d07
Update src/apphost/AppHost.cs
maddymontaquila 14ef69d
Update src/apphost/init-scripts/create-database.sql
maddymontaquila f8085ec
code review edits
maddymontaquila aa0fdff
Merge branch 'main' into maddy/aspire
tommasodotNET 4997015
adds launch profiles to switch between different db types
tommasodotNET File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "appHostPath": "../src/Aspire.AppHost/Aspire.AppHost.csproj" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| var aspireDB = Environment.GetEnvironmentVariable("ASPIRE_DATABASE_TYPE"); | ||
|
|
||
| var databaseConnectionString = Environment.GetEnvironmentVariable("ASPIRE_DATABASE_CONNECTION_STRING") ?? ""; | ||
|
|
||
| switch (aspireDB) | ||
| { | ||
| case "sql": | ||
| var sqlScript = File.ReadAllText("./init-scripts/sql/create-database.sql"); | ||
|
|
||
| IResourceBuilder<SqlServerDatabaseResource>? sqlDbContainer = null; | ||
|
|
||
| if(string.IsNullOrEmpty(databaseConnectionString)) | ||
| { | ||
| Console.WriteLine("No connection string provided, starting a local SQL Server container."); | ||
|
|
||
| sqlDbContainer = builder.AddSqlServer("sqlserver") | ||
| .WithDataVolume() | ||
| .WithLifetime(ContainerLifetime.Persistent) | ||
| .AddDatabase("msSqlDb", "Trek") | ||
| .WithCreationScript(sqlScript); | ||
| } | ||
|
|
||
| var mssqlService = builder.AddProject<Projects.Azure_DataApiBuilder_Service>("mssql-service", "Development") | ||
| .WithArgs("-f", "net8.0") | ||
| .WithEndpoint(endpointName: "https", (e) => e.Port = 1234) | ||
| .WithEndpoint(endpointName: "http", (e) => e.Port = 2345) | ||
| .WithEnvironment("db-type", "mssql") | ||
| .WithUrls((e) => | ||
| { | ||
| e.Urls.Clear(); | ||
| e.Urls.Add(new() { Url = "/swagger", DisplayText = "🔒Swagger", Endpoint = e.GetEndpoint("https") }); | ||
| e.Urls.Add(new() { Url = "/graphql", DisplayText = "🔒GraphQL", Endpoint = e.GetEndpoint("https") }); | ||
| }) | ||
| .WithHttpHealthCheck("/health"); | ||
|
|
||
| if (sqlDbContainer is null) | ||
| { | ||
| mssqlService.WithEnvironment("ConnectionStrings__Database", databaseConnectionString); | ||
| } | ||
| else | ||
| { | ||
| mssqlService.WithEnvironment("ConnectionStrings__Database", sqlDbContainer) | ||
| .WaitFor(sqlDbContainer); | ||
| } | ||
|
|
||
| break; | ||
| case "postgres": | ||
| var pgScript = File.ReadAllText("./init-scripts/pg/create-database-pg.sql"); | ||
|
|
||
| IResourceBuilder<PostgresDatabaseResource>? postgresDB = null; | ||
|
|
||
| if (!string.IsNullOrEmpty(databaseConnectionString)) | ||
| { | ||
| Console.WriteLine("No connection string provided, starting a local PostgreSQL container."); | ||
|
|
||
| postgresDB = builder.AddPostgres("postgres") | ||
| .WithPgAdmin() | ||
| .WithLifetime(ContainerLifetime.Persistent) | ||
| .AddDatabase("pgDb", "postgres") | ||
| .WithCreationScript(pgScript); | ||
| } | ||
|
|
||
| var pgService = builder.AddProject<Projects.Azure_DataApiBuilder_Service>("pg-service", "Development") | ||
| .WithArgs("-f", "net8.0") | ||
| .WithEndpoint(endpointName: "https", (e) => e.Port = 1234) | ||
| .WithEndpoint(endpointName: "http", (e) => e.Port = 2345) | ||
| .WithEnvironment("db-type", "postgresql") | ||
| .WithUrls((e) => | ||
| { | ||
| e.Urls.Clear(); | ||
| e.Urls.Add(new() { Url = "/swagger", DisplayText = "🔒Swagger", Endpoint = e.GetEndpoint("https") }); | ||
| e.Urls.Add(new() { Url = "/graphql", DisplayText = "🔒GraphQL", Endpoint = e.GetEndpoint("https") }); | ||
| }) | ||
| .WithHttpHealthCheck("/health"); | ||
|
|
||
| if (postgresDB is null) | ||
| { | ||
| pgService.WithEnvironment("ConnectionStrings__Database", databaseConnectionString); | ||
| } | ||
| else | ||
| { | ||
| pgService.WithEnvironment("ConnectionStrings__Database", postgresDB) | ||
| .WaitFor(postgresDB); | ||
| } | ||
|
|
||
| break; | ||
| default: | ||
| throw new Exception("Please set the ASPIRE_DATABASE environment variable to either 'sql' or 'postgre'."); | ||
| } | ||
|
|
||
| builder.Build().Run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <Sdk Name="Aspire.AppHost.Sdk" Version="9.4.0" /> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <UserSecretsId>f08719fd-267f-459e-9980-77b1c52c8755</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting.AppHost" /> | ||
| <PackageReference Include="Aspire.Hosting.SqlServer" /> | ||
| <PackageReference Include="Aspire.Hosting.PostgreSQL" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Service\Azure.DataApiBuilder.Service.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| using System.Diagnostics; | ||
|
|
||
| public static class DockerStatus | ||
| { | ||
| public static async Task<bool> IsDockerRunningAsync() | ||
| { | ||
| var psi = new ProcessStartInfo | ||
| { | ||
| FileName = "docker", | ||
| Arguments = "info", | ||
| RedirectStandardOutput = true, | ||
| RedirectStandardError = true, | ||
| UseShellExecute = false, | ||
| }; | ||
| try | ||
| { | ||
| using var process = Process.Start(psi)!; | ||
| await process.WaitForExitAsync(); | ||
| return process.ExitCode == 0; | ||
| } | ||
| catch | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| { | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "launchBrowser": true, | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21213", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22145" | ||
| }, | ||
| "dotnetRunMessages": true, | ||
| "applicationUrl": "https://localhost:17047;http://localhost:15161" | ||
| }, | ||
| "http": { | ||
| "commandName": "Project", | ||
| "launchBrowser": true, | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19015", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20166" | ||
| }, | ||
| "dotnetRunMessages": true, | ||
| "applicationUrl": "http://localhost:15161" | ||
| }, | ||
| "aspire-sql": { | ||
| "commandName": "Project", | ||
| "launchBrowser": true, | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21213", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22145", | ||
| "ASPIRE_DATABASE_TYPE": "sql", | ||
| "ASPIRE_DATABASE_CONNECTION_STRING": "" | ||
| }, | ||
| "dotnetRunMessages": true, | ||
| "applicationUrl": "https://localhost:17047;http://localhost:15161" | ||
| }, | ||
| "aspire-postgres": { | ||
| "commandName": "Project", | ||
| "launchBrowser": true, | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21213", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22145", | ||
| "ASPIRE_DATABASE_TYPE": "postgres", | ||
| "ASPIRE_DATABASE_CONNECTION_STRING": "" | ||
| }, | ||
| "dotnetRunMessages": true, | ||
| "applicationUrl": "https://localhost:17047;http://localhost:15161" | ||
| } | ||
| }, | ||
| "$schema": "https://json.schemastore.org/launchsettings.json" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Aspire Instructions | ||
|
|
||
| This project allows you to run DAB in debug mode using [Aspire](https://learn.microsoft.com/en-us/dotnet/aspire/get-started/aspire-overview). | ||
|
|
||
| ## Prerequisites | ||
| - [.NET SDK](https://dotnet.microsoft.com/download) (8.0 or later) | ||
| - [Docker](https://www.docker.com/products/docker-desktop) (optional, for containerized development) | ||
|
|
||
| ## Database Configuration | ||
|
|
||
| In the `launchProfile.json` file, you can configure the database connection string. If you don't, Aspire will start for you a local instance in a Docker container. | ||
|
|
||
| Simply provide a value for the `ASPIRE_DATABASE_CONNECTION_STRING` environment variable. | ||
|
|
||
| You can select to run Aspire with different databases selecting the appropriate launch profile: | ||
| - `aspire-sql` | ||
| - `aspire-postgres` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning", | ||
| "Aspire.Hosting.Dcp": "Warning" | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.