From fe8c0f444d3eeb750c424bf0261cbf4d304f2327 Mon Sep 17 00:00:00 2001 From: Pc Date: Sat, 11 Mar 2023 19:45:02 +0330 Subject: [PATCH 1/3] refactor: refactor persist message processor --- .../PersistMessageProcessor/Extensions.cs | 37 ++++--------------- .../InfrastructureExtensions.cs | 2 +- .../InfrastructureExtensions.cs | 2 + .../InfrastructureExtensions.cs | 2 + .../InfrastructureExtensions.cs | 3 ++ 5 files changed, 15 insertions(+), 31 deletions(-) diff --git a/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs b/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs index 444a0ca..bfa6eb3 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs @@ -5,10 +5,8 @@ using Microsoft.Extensions.DependencyInjection; namespace BuildingBlocks.PersistMessageProcessor; -using EFCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Hosting; public static class Extensions { @@ -39,38 +37,17 @@ public static class Extensions return services; } - public static IApplicationBuilder UseMigration(this IApplicationBuilder app, IWebHostEnvironment env) + public static IApplicationBuilder UseMigrationPersistMessage(this IApplicationBuilder app, IWebHostEnvironment env) where TContext : DbContext, IPersistMessageDbContext { - MigrateDatabaseAsync(app.ApplicationServices).GetAwaiter().GetResult(); + using var scope = app.ApplicationServices.CreateScope(); - if (!env.IsEnvironment("test")) - { - SeedDataAsync(app.ApplicationServices).GetAwaiter().GetResult(); - } + var persistMessageContext = scope.ServiceProvider.GetRequiredService(); + persistMessageContext.Database.Migrate(); + + var context = scope.ServiceProvider.GetRequiredService(); + context.Database.Migrate(); return app; } - - private static async Task MigrateDatabaseAsync(IServiceProvider serviceProvider) - where TContext : DbContext, IPersistMessageDbContext - { - using var scope = serviceProvider.CreateScope(); - - var persistMessageContext = scope.ServiceProvider.GetRequiredService(); - await persistMessageContext.Database.MigrateAsync(); - - var context = scope.ServiceProvider.GetRequiredService(); - await context.Database.MigrateAsync(); - } - - private static async Task SeedDataAsync(IServiceProvider serviceProvider) - { - using var scope = serviceProvider.CreateScope(); - var seeders = scope.ServiceProvider.GetServices(); - foreach (var seeder in seeders) - { - await seeder.SeedAllAsync(); - } - } } diff --git a/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs index f3bee2a..471f1cc 100644 --- a/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -100,7 +100,7 @@ public static class InfrastructureExtensions }); app.UseCorrelationId(); app.UseHttpMetrics(); - app.UseMigration(env); + app.UseMigrationPersistMessage(env); app.UseCustomHealthCheck(); app.MapMetrics(); app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name)); diff --git a/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs index 588476b..e0bada3 100644 --- a/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -30,6 +30,7 @@ using Serilog; namespace Flight.Extensions.Infrastructure; +using BuildingBlocks.PersistMessageProcessor.Data; using Microsoft.AspNetCore.HttpOverrides; public static class InfrastructureExtensions @@ -105,6 +106,7 @@ public static class InfrastructureExtensions }); app.UseCorrelationId(); app.UseHttpMetrics(); + app.UseMigrationPersistMessage(env); app.UseMigration(env); app.MapMetrics(); app.UseCustomHealthCheck(); diff --git a/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs index 85c2e6b..ca65770 100644 --- a/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -26,6 +26,7 @@ using Serilog; namespace Identity.Extensions.Infrastructure; +using BuildingBlocks.PersistMessageProcessor.Data; using Configurations; using Microsoft.AspNetCore.HttpOverrides; @@ -101,6 +102,7 @@ public static class InfrastructureExtensions { options.EnrichDiagnosticContext = LogEnrichHelper.EnrichFromRequest; }); + app.UseMigrationPersistMessage(env); app.UseMigration(env); app.UseCorrelationId(); app.UseHttpMetrics(); diff --git a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs index c8cd27a..2228c13 100644 --- a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -28,6 +28,8 @@ using Serilog; namespace Passenger.Extensions.Infrastructure; +using BuildingBlocks.PersistMessageProcessor.Data; + public static class InfrastructureExtensions { public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder builder) @@ -95,6 +97,7 @@ public static class InfrastructureExtensions { options.EnrichDiagnosticContext = LogEnrichHelper.EnrichFromRequest; }); + app.UseMigrationPersistMessage(env); app.UseMigration(env); app.UseCorrelationId(); app.UseHttpMetrics(); From f10fc930d67d857356587a03f8dbcdedc7451c20 Mon Sep 17 00:00:00 2001 From: Pc Date: Sat, 11 Mar 2023 19:59:30 +0330 Subject: [PATCH 2/3] chore: try fo fix event-store in ci-cd --- .github/workflows/ci.yml | 192 +++++++++--------- src/BuildingBlocks/TestBase/TestContainers.cs | 1 - .../src/Booking.Api/appsettings.test.json | 3 - 3 files changed, 96 insertions(+), 100 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7a9fd6..d47c1bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,58 +12,58 @@ on: concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} cancel-in-progress: true - + jobs: ci: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - - name: Build and Test Flight - uses: ./.github/actions/build-test - if: success() - id: build-test-flight-step - with: - project-path: 'src/Services/Flight/src/Flight.Api' - tests-path: 'src/Services/Flight/tests/' - # wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory - # https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/ - # https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not - reports-path: ${{ github.workspace }}/**/*.cobertura.xml - reports-output-path: ${{ github.workspace }}/output/test-results - service-name: 'Flight' - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and Test Identity - uses: ./.github/actions/build-test - if: success() - id: build-test-identity-step - with: - project-path: 'src/Services/Identity/src/Identity.Api' - tests-path: 'src/Services/Identity/tests/' - # wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory - # https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/ - # https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not - reports-path: ${{ github.workspace }}/**/*.cobertura.xml - reports-output-path: ${{ github.workspace }}/output/test-results - service-name: 'Identity' - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and Test Passenger - uses: ./.github/actions/build-test - if: success() - id: build-test-passenger-step - with: - project-path: 'src/Services/Passenger/src/Passenger.Api' - tests-path: 'src/Services/Passenger/tests/' - # wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory - # https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/ - # https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not - reports-path: ${{ github.workspace }}/**/*.cobertura.xml - reports-output-path: ${{ github.workspace }}/output/test-results - service-name: 'Passenger' - token: ${{ secrets.GITHUB_TOKEN }} +# +# - name: Build and Test Flight +# uses: ./.github/actions/build-test +# if: success() +# id: build-test-flight-step +# with: +# project-path: 'src/Services/Flight/src/Flight.Api' +# tests-path: 'src/Services/Flight/tests/' +# # wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory +# # https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/ +# # https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not +# reports-path: ${{ github.workspace }}/**/*.cobertura.xml +# reports-output-path: ${{ github.workspace }}/output/test-results +# service-name: 'Flight' +# token: ${{ secrets.GITHUB_TOKEN }} +# +# - name: Build and Test Identity +# uses: ./.github/actions/build-test +# if: success() +# id: build-test-identity-step +# with: +# project-path: 'src/Services/Identity/src/Identity.Api' +# tests-path: 'src/Services/Identity/tests/' +# # wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory +# # https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/ +# # https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not +# reports-path: ${{ github.workspace }}/**/*.cobertura.xml +# reports-output-path: ${{ github.workspace }}/output/test-results +# service-name: 'Identity' +# token: ${{ secrets.GITHUB_TOKEN }} +# +# - name: Build and Test Passenger +# uses: ./.github/actions/build-test +# if: success() +# id: build-test-passenger-step +# with: +# project-path: 'src/Services/Passenger/src/Passenger.Api' +# tests-path: 'src/Services/Passenger/tests/' +# # wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory +# # https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/ +# # https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not +# reports-path: ${{ github.workspace }}/**/*.cobertura.xml +# reports-output-path: ${{ github.workspace }}/output/test-results +# service-name: 'Passenger' +# token: ${{ secrets.GITHUB_TOKEN }} - name: Build and Test Booking uses: ./.github/actions/build-test @@ -80,53 +80,53 @@ jobs: service-name: 'Booking' token: ${{ secrets.GITHUB_TOKEN }} - - name: Update Release Drafter - if: ${{ github.ref == 'refs/heads/main' && success() }} - id: last_release - uses: release-drafter/release-drafter@v5 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Release Version Info - run: - echo "Release version is:" ${{ steps.last_release.outputs.tag_name }} - - - name: Build and Publish Identity to Docker - if: ${{ github.ref == 'refs/heads/main' && success() }} - uses: ./.github/actions/docker-build-publish - with: - tag-name: ${{ steps.last_release.outputs.tag_name }} - registry-username: ${{ secrets.DOCKERHUB_USERNAME }} - registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} - dockerfile-path: 'src/Services/Identity/Dockerfile' - image-name: 'booking-microservices-identity' - - - name: Build and Publish Flight to Docker - if: ${{ github.ref == 'refs/heads/main' && success() }} - uses: ./.github/actions/docker-build-publish - with: - tag-name: ${{ steps.last_release.outputs.tag_name }} - registry-username: ${{ secrets.DOCKERHUB_USERNAME }} - registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} - dockerfile-path: 'src/Services/Flight/Dockerfile' - image-name: 'booking-microservices-flight' - - - name: Build and Publish Passenger to Docker - if: ${{ github.ref == 'refs/heads/main' && success() }} - uses: ./.github/actions/docker-build-publish - with: - tag-name: ${{ steps.last_release.outputs.tag_name }} - registry-username: ${{ secrets.DOCKERHUB_USERNAME }} - registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} - dockerfile-path: 'src/Services/Passenger/Dockerfile' - image-name: 'booking-microservices-passenger' - - - name: Build and Publish Booking to Docker - if: ${{ github.ref == 'refs/heads/main' && success() }} - uses: ./.github/actions/docker-build-publish - with: - tag-name: ${{ steps.last_release.outputs.tag_name }} - registry-username: ${{ secrets.DOCKERHUB_USERNAME }} - registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} - dockerfile-path: 'src/Services/Booking/Dockerfile' - image-name: 'booking-microservices-booking' +# - name: Update Release Drafter +# if: ${{ github.ref == 'refs/heads/main' && success() }} +# id: last_release +# uses: release-drafter/release-drafter@v5 +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# +# - name: Release Version Info +# run: +# echo "Release version is:" ${{ steps.last_release.outputs.tag_name }} +# +# - name: Build and Publish Identity to Docker +# if: ${{ github.ref == 'refs/heads/main' && success() }} +# uses: ./.github/actions/docker-build-publish +# with: +# tag-name: ${{ steps.last_release.outputs.tag_name }} +# registry-username: ${{ secrets.DOCKERHUB_USERNAME }} +# registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} +# dockerfile-path: 'src/Services/Identity/Dockerfile' +# image-name: 'booking-microservices-identity' +# +# - name: Build and Publish Flight to Docker +# if: ${{ github.ref == 'refs/heads/main' && success() }} +# uses: ./.github/actions/docker-build-publish +# with: +# tag-name: ${{ steps.last_release.outputs.tag_name }} +# registry-username: ${{ secrets.DOCKERHUB_USERNAME }} +# registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} +# dockerfile-path: 'src/Services/Flight/Dockerfile' +# image-name: 'booking-microservices-flight' +# +# - name: Build and Publish Passenger to Docker +# if: ${{ github.ref == 'refs/heads/main' && success() }} +# uses: ./.github/actions/docker-build-publish +# with: +# tag-name: ${{ steps.last_release.outputs.tag_name }} +# registry-username: ${{ secrets.DOCKERHUB_USERNAME }} +# registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} +# dockerfile-path: 'src/Services/Passenger/Dockerfile' +# image-name: 'booking-microservices-passenger' +# +# - name: Build and Publish Booking to Docker +# if: ${{ github.ref == 'refs/heads/main' && success() }} +# uses: ./.github/actions/docker-build-publish +# with: +# tag-name: ${{ steps.last_release.outputs.tag_name }} +# registry-username: ${{ secrets.DOCKERHUB_USERNAME }} +# registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} +# dockerfile-path: 'src/Services/Booking/Dockerfile' +# image-name: 'booking-microservices-booking' diff --git a/src/BuildingBlocks/TestBase/TestContainers.cs b/src/BuildingBlocks/TestBase/TestContainers.cs index c7ef2dd..222a665 100644 --- a/src/BuildingBlocks/TestBase/TestContainers.cs +++ b/src/BuildingBlocks/TestBase/TestContainers.cs @@ -97,7 +97,6 @@ public static class TestContainers var builder = baseBuilder .WithImage(EventStoreContainerConfiguration.ImageName) .WithName(EventStoreContainerConfiguration.Name) - .WithPortBinding(EventStoreContainerConfiguration.Port, true) .Build(); return builder; diff --git a/src/Services/Booking/src/Booking.Api/appsettings.test.json b/src/Services/Booking/src/Booking.Api/appsettings.test.json index 5645ffb..42d2109 100644 --- a/src/Services/Booking/src/Booking.Api/appsettings.test.json +++ b/src/Services/Booking/src/Booking.Api/appsettings.test.json @@ -18,9 +18,6 @@ "ConnectionString": "mongodb://localhost:27017", "DatabaseName": "booking-db-test" }, - "EventStore": { - "ConnectionString": "esdb://localhost:2113?tls=false" - }, "PersistMessageOptions": { "Interval": 30, "Enabled": true, From 4fee16e3b80e29bfd4e734a0c1c508c31ddd3e12 Mon Sep 17 00:00:00 2001 From: Pc Date: Sat, 11 Mar 2023 21:53:19 +0330 Subject: [PATCH 3/3] fix: Fix bug event-store for load configuration options --- .github/workflows/ci.yml | 190 +++++++++--------- src/BuildingBlocks/EventStoreDB/Config.cs | 15 +- src/BuildingBlocks/EventStoreDB/Extensions.cs | 4 + src/BuildingBlocks/TestBase/TestBase.cs | 2 +- .../src/Booking.Api/appsettings.docker.json | 2 +- .../Booking/src/Booking.Api/appsettings.json | 2 +- 6 files changed, 111 insertions(+), 104 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d47c1bc..fe4abd4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,51 +19,51 @@ jobs: steps: - uses: actions/checkout@v3 -# -# - name: Build and Test Flight -# uses: ./.github/actions/build-test -# if: success() -# id: build-test-flight-step -# with: -# project-path: 'src/Services/Flight/src/Flight.Api' -# tests-path: 'src/Services/Flight/tests/' -# # wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory -# # https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/ -# # https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not -# reports-path: ${{ github.workspace }}/**/*.cobertura.xml -# reports-output-path: ${{ github.workspace }}/output/test-results -# service-name: 'Flight' -# token: ${{ secrets.GITHUB_TOKEN }} -# -# - name: Build and Test Identity -# uses: ./.github/actions/build-test -# if: success() -# id: build-test-identity-step -# with: -# project-path: 'src/Services/Identity/src/Identity.Api' -# tests-path: 'src/Services/Identity/tests/' -# # wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory -# # https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/ -# # https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not -# reports-path: ${{ github.workspace }}/**/*.cobertura.xml -# reports-output-path: ${{ github.workspace }}/output/test-results -# service-name: 'Identity' -# token: ${{ secrets.GITHUB_TOKEN }} -# -# - name: Build and Test Passenger -# uses: ./.github/actions/build-test -# if: success() -# id: build-test-passenger-step -# with: -# project-path: 'src/Services/Passenger/src/Passenger.Api' -# tests-path: 'src/Services/Passenger/tests/' -# # wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory -# # https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/ -# # https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not -# reports-path: ${{ github.workspace }}/**/*.cobertura.xml -# reports-output-path: ${{ github.workspace }}/output/test-results -# service-name: 'Passenger' -# token: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Test Flight + uses: ./.github/actions/build-test + if: success() + id: build-test-flight-step + with: + project-path: 'src/Services/Flight/src/Flight.Api' + tests-path: 'src/Services/Flight/tests/' + # wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory + # https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/ + # https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not + reports-path: ${{ github.workspace }}/**/*.cobertura.xml + reports-output-path: ${{ github.workspace }}/output/test-results + service-name: 'Flight' + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Test Identity + uses: ./.github/actions/build-test + if: success() + id: build-test-identity-step + with: + project-path: 'src/Services/Identity/src/Identity.Api' + tests-path: 'src/Services/Identity/tests/' + # wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory + # https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/ + # https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not + reports-path: ${{ github.workspace }}/**/*.cobertura.xml + reports-output-path: ${{ github.workspace }}/output/test-results + service-name: 'Identity' + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Test Passenger + uses: ./.github/actions/build-test + if: success() + id: build-test-passenger-step + with: + project-path: 'src/Services/Passenger/src/Passenger.Api' + tests-path: 'src/Services/Passenger/tests/' + # wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory + # https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/ + # https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not + reports-path: ${{ github.workspace }}/**/*.cobertura.xml + reports-output-path: ${{ github.workspace }}/output/test-results + service-name: 'Passenger' + token: ${{ secrets.GITHUB_TOKEN }} - name: Build and Test Booking uses: ./.github/actions/build-test @@ -80,53 +80,53 @@ jobs: service-name: 'Booking' token: ${{ secrets.GITHUB_TOKEN }} -# - name: Update Release Drafter -# if: ${{ github.ref == 'refs/heads/main' && success() }} -# id: last_release -# uses: release-drafter/release-drafter@v5 -# env: -# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -# -# - name: Release Version Info -# run: -# echo "Release version is:" ${{ steps.last_release.outputs.tag_name }} -# -# - name: Build and Publish Identity to Docker -# if: ${{ github.ref == 'refs/heads/main' && success() }} -# uses: ./.github/actions/docker-build-publish -# with: -# tag-name: ${{ steps.last_release.outputs.tag_name }} -# registry-username: ${{ secrets.DOCKERHUB_USERNAME }} -# registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} -# dockerfile-path: 'src/Services/Identity/Dockerfile' -# image-name: 'booking-microservices-identity' -# -# - name: Build and Publish Flight to Docker -# if: ${{ github.ref == 'refs/heads/main' && success() }} -# uses: ./.github/actions/docker-build-publish -# with: -# tag-name: ${{ steps.last_release.outputs.tag_name }} -# registry-username: ${{ secrets.DOCKERHUB_USERNAME }} -# registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} -# dockerfile-path: 'src/Services/Flight/Dockerfile' -# image-name: 'booking-microservices-flight' -# -# - name: Build and Publish Passenger to Docker -# if: ${{ github.ref == 'refs/heads/main' && success() }} -# uses: ./.github/actions/docker-build-publish -# with: -# tag-name: ${{ steps.last_release.outputs.tag_name }} -# registry-username: ${{ secrets.DOCKERHUB_USERNAME }} -# registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} -# dockerfile-path: 'src/Services/Passenger/Dockerfile' -# image-name: 'booking-microservices-passenger' -# -# - name: Build and Publish Booking to Docker -# if: ${{ github.ref == 'refs/heads/main' && success() }} -# uses: ./.github/actions/docker-build-publish -# with: -# tag-name: ${{ steps.last_release.outputs.tag_name }} -# registry-username: ${{ secrets.DOCKERHUB_USERNAME }} -# registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} -# dockerfile-path: 'src/Services/Booking/Dockerfile' -# image-name: 'booking-microservices-booking' + - name: Update Release Drafter + if: ${{ github.ref == 'refs/heads/main' && success() }} + id: last_release + uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Release Version Info + run: + echo "Release version is:" ${{ steps.last_release.outputs.tag_name }} + + - name: Build and Publish Identity to Docker + if: ${{ github.ref == 'refs/heads/main' && success() }} + uses: ./.github/actions/docker-build-publish + with: + tag-name: ${{ steps.last_release.outputs.tag_name }} + registry-username: ${{ secrets.DOCKERHUB_USERNAME }} + registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} + dockerfile-path: 'src/Services/Identity/Dockerfile' + image-name: 'booking-microservices-identity' + + - name: Build and Publish Flight to Docker + if: ${{ github.ref == 'refs/heads/main' && success() }} + uses: ./.github/actions/docker-build-publish + with: + tag-name: ${{ steps.last_release.outputs.tag_name }} + registry-username: ${{ secrets.DOCKERHUB_USERNAME }} + registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} + dockerfile-path: 'src/Services/Flight/Dockerfile' + image-name: 'booking-microservices-flight' + + - name: Build and Publish Passenger to Docker + if: ${{ github.ref == 'refs/heads/main' && success() }} + uses: ./.github/actions/docker-build-publish + with: + tag-name: ${{ steps.last_release.outputs.tag_name }} + registry-username: ${{ secrets.DOCKERHUB_USERNAME }} + registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} + dockerfile-path: 'src/Services/Passenger/Dockerfile' + image-name: 'booking-microservices-passenger' + + - name: Build and Publish Booking to Docker + if: ${{ github.ref == 'refs/heads/main' && success() }} + uses: ./.github/actions/docker-build-publish + with: + tag-name: ${{ steps.last_release.outputs.tag_name }} + registry-username: ${{ secrets.DOCKERHUB_USERNAME }} + registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} + dockerfile-path: 'src/Services/Booking/Dockerfile' + image-name: 'booking-microservices-booking' diff --git a/src/BuildingBlocks/EventStoreDB/Config.cs b/src/BuildingBlocks/EventStoreDB/Config.cs index 14f8977..56c1afc 100644 --- a/src/BuildingBlocks/EventStoreDB/Config.cs +++ b/src/BuildingBlocks/EventStoreDB/Config.cs @@ -1,6 +1,5 @@ using System.Reflection; using BuildingBlocks.EventStoreDB.BackgroundWorkers; -using BuildingBlocks.EventStoreDB.Events; using BuildingBlocks.EventStoreDB.Projections; using BuildingBlocks.EventStoreDB.Repository; using BuildingBlocks.EventStoreDB.Subscriptions; @@ -11,26 +10,30 @@ using Microsoft.Extensions.Logging; namespace BuildingBlocks.EventStoreDB; -public class EventStoreDBConfig +using Web; + +public class EventStoreOptions { public string ConnectionString { get; set; } = default!; } + public record EventStoreDBOptions( bool UseInternalCheckpointing = true ); public static class EventStoreDBConfigExtensions { - private const string DefaultConfigKey = "EventStore"; - public static IServiceCollection AddEventStoreDB(this IServiceCollection services, IConfiguration config, EventStoreDBOptions? options = null) { - var eventStoreDBConfig = config.GetSection(DefaultConfigKey).Get(); services - .AddSingleton(new EventStoreClient(EventStoreClientSettings.Create(eventStoreDBConfig.ConnectionString))) + .AddSingleton(x=> + { + var eventStoreOptions = services.GetOptions(nameof(EventStoreOptions)); + return new EventStoreClient(EventStoreClientSettings.Create(eventStoreOptions.ConnectionString)); + }) .AddScoped(typeof(IEventStoreDBRepository<>), typeof(EventStoreDBRepository<>)) .AddTransient(); diff --git a/src/BuildingBlocks/EventStoreDB/Extensions.cs b/src/BuildingBlocks/EventStoreDB/Extensions.cs index 046c8e9..ea16d74 100644 --- a/src/BuildingBlocks/EventStoreDB/Extensions.cs +++ b/src/BuildingBlocks/EventStoreDB/Extensions.cs @@ -4,6 +4,8 @@ using Microsoft.Extensions.DependencyInjection; namespace BuildingBlocks.EventStoreDB; +using Web; + public static class Extensions { // ref: https://github.com/oskardudycz/EventSourcing.NetCore/tree/main/Sample/EventStoreDB/ECommerce @@ -13,6 +15,8 @@ public static class Extensions params Assembly[] assemblies ) { + services.AddValidateOptions(); + var assembliesToScan = assemblies.Length > 0 ? assemblies : new[] { Assembly.GetEntryAssembly()! }; return services diff --git a/src/BuildingBlocks/TestBase/TestBase.cs b/src/BuildingBlocks/TestBase/TestBase.cs index 7fcd694..93dbb38 100644 --- a/src/BuildingBlocks/TestBase/TestBase.cs +++ b/src/BuildingBlocks/TestBase/TestBase.cs @@ -278,7 +278,7 @@ public class TestFixture : IAsyncLifetime .ToString(NumberFormatInfo.InvariantInfo)), new("MongoOptions:ConnectionString", MongoDbTestContainer.GetConnectionString()), new("MongoOptions:DatabaseName", TestContainers.MongoContainerConfiguration.Name), - new("EventStore:ConnectionString", EventStoreDbTestContainer.GetConnectionString()) + new("EventStoreOptions:ConnectionString", EventStoreDbTestContainer.GetConnectionString()) }); } diff --git a/src/Services/Booking/src/Booking.Api/appsettings.docker.json b/src/Services/Booking/src/Booking.Api/appsettings.docker.json index 07011a2..8ad2a7d 100644 --- a/src/Services/Booking/src/Booking.Api/appsettings.docker.json +++ b/src/Services/Booking/src/Booking.Api/appsettings.docker.json @@ -11,7 +11,7 @@ "Enabled": true, "ConnectionString": "Server=postgres;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true" }, - "EventStore": { + "EventStoreOptions": { "ConnectionString": "esdb://eventstore:2113?tls=false" }, "MongoOptions": { diff --git a/src/Services/Booking/src/Booking.Api/appsettings.json b/src/Services/Booking/src/Booking.Api/appsettings.json index f382d23..d5084e8 100644 --- a/src/Services/Booking/src/Booking.Api/appsettings.json +++ b/src/Services/Booking/src/Booking.Api/appsettings.json @@ -48,7 +48,7 @@ "BreakDuration" : 30 } }, - "EventStore": { + "EventStoreOptions": { "ConnectionString": "esdb://localhost:2113?tls=false" }, "MongoOptions": {