From fff35bf8e7968d919c248b58e10af76d9b14fc03 Mon Sep 17 00:00:00 2001 From: Privatech38 Date: Mon, 13 Jan 2025 18:46:15 +0100 Subject: [PATCH 1/6] Added if else for connection string depending on environment --- Vulkan2Blazor/Program.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Vulkan2Blazor/Program.cs b/Vulkan2Blazor/Program.cs index 329e790..23e8446 100644 --- a/Vulkan2Blazor/Program.cs +++ b/Vulkan2Blazor/Program.cs @@ -27,8 +27,19 @@ }) .AddIdentityCookies(); -builder.Services.AddDbContextFactory(options => - options.UseNpgsql(builder.Configuration.GetConnectionString("Vulkan2Context") ?? throw new InvalidOperationException("Connection string 'Vulkan2Context' not found."))); +if (builder.Environment.IsDevelopment()) +{ + builder.Services.AddDbContextFactory(options => + options.UseNpgsql(builder.Configuration.GetConnectionString("Vulkan2Context") ?? + throw new InvalidOperationException("Connection string 'Vulkan2Context' not found."))); +} +else +{ + builder.Services.AddDbContextFactory(options => + options.UseNpgsql(Environment.GetEnvironmentVariable("AZURE_POSTGRESQL_CONNECTIONSTRING") ?? + throw new InvalidOperationException("Connection string 'AZURE_POSTGRESQL_CONNECTIONSTRING' not found."))); +} +; builder.Services.AddQuickGridEntityFrameworkAdapter(); From 134277b0bd8f525995cf74a78a877b3ad02346d4 Mon Sep 17 00:00:00 2001 From: Privatech38 Date: Tue, 14 Jan 2025 14:51:36 +0100 Subject: [PATCH 2/6] First draft of compose --- Vulkan2Blazor.sln | 6 ++++++ compose.yaml | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 compose.yaml diff --git a/Vulkan2Blazor.sln b/Vulkan2Blazor.sln index 93fc6bc..5b6e961 100644 --- a/Vulkan2Blazor.sln +++ b/Vulkan2Blazor.sln @@ -2,6 +2,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vulkan2Blazor", "Vulkan2Blazor\Vulkan2Blazor.csproj", "{52A5CDEF-EFCB-4C24-82D0-2DCEC6E69FD3}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5DA684E1-853E-461D-AD1D-E7B14ADB7FB9}" + ProjectSection(SolutionItems) = preProject + compose.yaml = compose.yaml + db-password.txt = db-password.txt + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..61ebe73 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,36 @@ +services: + vulkan2blazor: + image: privatech/vulkan2:main + ports: + - "8080:80" + environment: + - ConnectionStrings__Vulkan2Context=Host=postgres;Port=5432;Database=vulkan;Username=postgres;Password_file=/run/secrets/db-password + depends_on: + postgres: + condition: service_healthy + + postgres: + image: postgres + restart: always + user: postgres + secrets: + - db-password + environment: + - POSTGRES_PASSWORD_FILE=/run/secrets/db-password + - POSTGRES_DB=vulkan + ports: + - "5432:5432" + volumes: + - postgres:/var/lib/postgresql/data + healthcheck: + test: ["CMD", "pg_isready"] + interval: 10s + timeout: 5s + retries: 5 + +volumes: + postgres: +secrets: + db-password: + file: db-password.txt + From 053e13b447f670edafa297f20847190ad5941bc7 Mon Sep 17 00:00:00 2001 From: Privatech38 Date: Tue, 14 Jan 2025 17:22:43 +0100 Subject: [PATCH 3/6] Fixed loading of css --- Vulkan2Blazor.sln | 2 +- Vulkan2Blazor/Components/App.razor | 2 +- Vulkan2Blazor/Program.cs | 19 ++++++++----------- compose.yaml | 24 +++++++++++++----------- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Vulkan2Blazor.sln b/Vulkan2Blazor.sln index 5b6e961..335cbd0 100644 --- a/Vulkan2Blazor.sln +++ b/Vulkan2Blazor.sln @@ -5,7 +5,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5DA684E1-853E-461D-AD1D-E7B14ADB7FB9}" ProjectSection(SolutionItems) = preProject compose.yaml = compose.yaml - db-password.txt = db-password.txt + .env = .env EndProjectSection EndProject Global diff --git a/Vulkan2Blazor/Components/App.razor b/Vulkan2Blazor/Components/App.razor index cc32d58..13c3b60 100644 --- a/Vulkan2Blazor/Components/App.razor +++ b/Vulkan2Blazor/Components/App.razor @@ -7,7 +7,7 @@ - + @* *@ diff --git a/Vulkan2Blazor/Program.cs b/Vulkan2Blazor/Program.cs index 23e8446..aa74b5c 100644 --- a/Vulkan2Blazor/Program.cs +++ b/Vulkan2Blazor/Program.cs @@ -27,19 +27,9 @@ }) .AddIdentityCookies(); -if (builder.Environment.IsDevelopment()) -{ - builder.Services.AddDbContextFactory(options => +builder.Services.AddDbContextFactory(options => options.UseNpgsql(builder.Configuration.GetConnectionString("Vulkan2Context") ?? throw new InvalidOperationException("Connection string 'Vulkan2Context' not found."))); -} -else -{ - builder.Services.AddDbContextFactory(options => - options.UseNpgsql(Environment.GetEnvironmentVariable("AZURE_POSTGRESQL_CONNECTIONSTRING") ?? - throw new InvalidOperationException("Connection string 'AZURE_POSTGRESQL_CONNECTIONSTRING' not found."))); -} -; builder.Services.AddQuickGridEntityFrameworkAdapter(); @@ -61,6 +51,13 @@ var app = builder.Build(); +// Apply migrations on startup +using (var scope = app.Services.CreateScope()) +{ + var dbContext = scope.ServiceProvider.GetRequiredService(); + dbContext.Database.Migrate(); +} + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/compose.yaml b/compose.yaml index 61ebe73..406a419 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,23 +1,27 @@ services: vulkan2blazor: - image: privatech/vulkan2:main + image: vulkan2blazor + build: + context: . + dockerfile: Vulkan2Blazor/Dockerfile ports: - - "8080:80" + - "8080:8080" environment: - - ConnectionStrings__Vulkan2Context=Host=postgres;Port=5432;Database=vulkan;Username=postgres;Password_file=/run/secrets/db-password + ASPNETCORE_ENVIRONMENT: "Production" +# ASPNETCORE_URLS: "https://localhost:443;http://localhost:80" + ConnectionStrings__Vulkan2Context: 'Host=postgres;Port=5432;Database=${POSTGRES_DB};Username=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}' depends_on: postgres: condition: service_healthy +# volumes: +# - vulkan2:/home/app/.aspnet/DataProtection-Keys postgres: image: postgres restart: always user: postgres - secrets: - - db-password - environment: - - POSTGRES_PASSWORD_FILE=/run/secrets/db-password - - POSTGRES_DB=vulkan + env_file: + - .env ports: - "5432:5432" volumes: @@ -30,7 +34,5 @@ volumes: postgres: -secrets: - db-password: - file: db-password.txt +# vulkan2: From f800b04c3285b3252d486d213bedb63bcae96bc2 Mon Sep 17 00:00:00 2001 From: Privatech38 Date: Tue, 14 Jan 2025 17:32:39 +0100 Subject: [PATCH 4/6] Fixd, now deploys correctly --- Vulkan2Blazor/Components/App.razor | 2 +- compose.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Vulkan2Blazor/Components/App.razor b/Vulkan2Blazor/Components/App.razor index 13c3b60..cc32d58 100644 --- a/Vulkan2Blazor/Components/App.razor +++ b/Vulkan2Blazor/Components/App.razor @@ -7,7 +7,7 @@ - @* *@ + diff --git a/compose.yaml b/compose.yaml index 406a419..100534c 100644 --- a/compose.yaml +++ b/compose.yaml @@ -7,8 +7,8 @@ ports: - "8080:8080" environment: - ASPNETCORE_ENVIRONMENT: "Production" -# ASPNETCORE_URLS: "https://localhost:443;http://localhost:80" + ASPNETCORE_ENVIRONMENT: "Development" +# ASPNETCORE_URLS: "http://localhost:8080" ConnectionStrings__Vulkan2Context: 'Host=postgres;Port=5432;Database=${POSTGRES_DB};Username=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}' depends_on: postgres: From 92d8287f8b4258e80992b65f5878e3eb9035629e Mon Sep 17 00:00:00 2001 From: Privatech38 Date: Tue, 14 Jan 2025 17:46:32 +0100 Subject: [PATCH 5/6] Fixed controllers not working --- Vulkan2Blazor/Program.cs | 4 ++++ Vulkan2Blazor/Vulkan2Blazor.csproj | 1 + 2 files changed, 5 insertions(+) diff --git a/Vulkan2Blazor/Program.cs b/Vulkan2Blazor/Program.cs index aa74b5c..964da7d 100644 --- a/Vulkan2Blazor/Program.cs +++ b/Vulkan2Blazor/Program.cs @@ -49,6 +49,8 @@ builder.Services.AddSingleton, IdentityNoOpEmailSender>(); +builder.Services.AddControllers(); + var app = builder.Build(); // Apply migrations on startup @@ -79,6 +81,8 @@ app.MapStaticAssets(); app.MapRazorComponents() .AddInteractiveServerRenderMode(); +app.MapBlazorHub(); +app.MapControllers(); // Add additional endpoints required by the Identity /Account Razor components. app.MapAdditionalIdentityEndpoints(); diff --git a/Vulkan2Blazor/Vulkan2Blazor.csproj b/Vulkan2Blazor/Vulkan2Blazor.csproj index 9616c12..6ab61d7 100644 --- a/Vulkan2Blazor/Vulkan2Blazor.csproj +++ b/Vulkan2Blazor/Vulkan2Blazor.csproj @@ -16,6 +16,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + From 15acd79e843c46d6d38264864a047dc6eca0b86b Mon Sep 17 00:00:00 2001 From: Privatech38 Date: Tue, 14 Jan 2025 18:12:14 +0100 Subject: [PATCH 6/6] Added separate yaml file for dev purposes --- Vulkan2Blazor.sln | 1 + compose-dev.yml | 38 ++++++++++++++++++++++++++++++++++++++ compose.yaml | 5 +---- 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 compose-dev.yml diff --git a/Vulkan2Blazor.sln b/Vulkan2Blazor.sln index 335cbd0..3d7fa8d 100644 --- a/Vulkan2Blazor.sln +++ b/Vulkan2Blazor.sln @@ -6,6 +6,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ProjectSection(SolutionItems) = preProject compose.yaml = compose.yaml .env = .env + compose-dev.yml = compose-dev.yml EndProjectSection EndProject Global diff --git a/compose-dev.yml b/compose-dev.yml new file mode 100644 index 0000000..070544c --- /dev/null +++ b/compose-dev.yml @@ -0,0 +1,38 @@ +services: + vulkan2blazor: + image: vulkan2blazor + build: + context: . + dockerfile: Vulkan2Blazor/Dockerfile + ports: + - "8080:8080" + environment: + ASPNETCORE_ENVIRONMENT: "Development" + # ASPNETCORE_URLS: "http://localhost:8080" + ConnectionStrings__Vulkan2Context: 'Host=postgres;Port=5432;Database=${POSTGRES_DB};Username=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}' + depends_on: + postgres: + condition: service_healthy + # volumes: + # - vulkan2:/home/app/.aspnet/DataProtection-Keys + + postgres: + image: postgres + restart: always + user: postgres + env_file: + - .env + ports: + - "5432:5432" + volumes: + - postgres:/var/lib/postgresql/data + healthcheck: + test: ["CMD", "pg_isready"] + interval: 10s + timeout: 5s + retries: 5 + +volumes: + postgres: +# vulkan2: + diff --git a/compose.yaml b/compose.yaml index 100534c..c7e7359 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,9 +1,6 @@ services: vulkan2blazor: - image: vulkan2blazor - build: - context: . - dockerfile: Vulkan2Blazor/Dockerfile + image: vulkan2blazor:latest ports: - "8080:8080" environment: