From 485e7d433e2891ec0277173fb66fc7b0c36cee5c Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 14 Nov 2024 01:31:08 -0800 Subject: [PATCH] Added sqlite data browser --- ...EfMigrationsExtensions.cs => Extensions.cs} | 5 ++++- TodoApi.AppHost/Program.cs | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) rename TodoApi.AppHost/{TodoApiEfMigrationsExtensions.cs => Extensions.cs} (84%) diff --git a/TodoApi.AppHost/TodoApiEfMigrationsExtensions.cs b/TodoApi.AppHost/Extensions.cs similarity index 84% rename from TodoApi.AppHost/TodoApiEfMigrationsExtensions.cs rename to TodoApi.AppHost/Extensions.cs index 23aacac..bb8b022 100644 --- a/TodoApi.AppHost/TodoApiEfMigrationsExtensions.cs +++ b/TodoApi.AppHost/Extensions.cs @@ -1,4 +1,4 @@ -internal static class TodoApiEfMigrationsExtensions +internal static class Extensions { public static IResourceBuilder? AddTodoDbMigration(this IDistributedApplicationBuilder builder) { @@ -28,4 +28,7 @@ public static IResourceBuilder AddEfMigration(this // TODO: Support passing a connection string return builder.AddExecutable(name, "dotnet", projectDirectory, "ef", "database", "update", "--no-build"); } + + public static string GetProjectDirectory(this IResourceBuilder project) => + Path.GetDirectoryName(project.Resource.GetProjectMetadata().ProjectPath)!; } diff --git a/TodoApi.AppHost/Program.cs b/TodoApi.AppHost/Program.cs index 6fa40db..105e97f 100644 --- a/TodoApi.AppHost/Program.cs +++ b/TodoApi.AppHost/Program.cs @@ -4,13 +4,25 @@ var todoapi = builder.AddProject("todoapi"); +builder.AddProject("todo-web-server") + .WithReference(todoapi); + +var dbDirectory = Path.Combine(todoapi.GetProjectDirectory(), ".db"); + +// Add sqlite-web to view the Todos.db database +var sqliteWeb = builder.AddContainer("sqliteweb", "tomdesinto/sqliteweb") + .WithHttpEndpoint(targetPort: 8080) + .WithBindMount(dbDirectory, "/db") + .WithArgs("Todos.db") + .ExcludeFromManifest(); + if (migrateOperation is not null) { - // Wait for the migration to complete before running the api + // Wait for the migration to complete before running the api and ui todoapi.WaitForCompletion(migrateOperation); + + sqliteWeb.WaitForCompletion(migrateOperation); } -builder.AddProject("todo-web-server") - .WithReference(todoapi); builder.Build().Run();