From 21cfb0fe4e7db5e038ae3e50eaa1ed8247d2aa99 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Tue, 21 Oct 2025 18:57:47 +0100 Subject: [PATCH 1/2] added method to start keycloak --- ClientProxyBase/ClientProxyBase.cs | 43 +++++++++++++++---- .../GenericSteps.cs | 11 +++-- .../Shared.IntegrationTesting.Tests.csproj | 1 + Shared.IntegrationTesting/BaseDockerHelper.cs | 28 +++++++++++- Shared.IntegrationTesting/ContainerType.cs | 1 + Shared.IntegrationTesting/DockerHelper.cs | 28 +++++++----- Shared.IntegrationTesting/DockerPorts.cs | 2 + .../Shared.IntegrationTesting.csproj | 3 +- 8 files changed, 94 insertions(+), 23 deletions(-) diff --git a/ClientProxyBase/ClientProxyBase.cs b/ClientProxyBase/ClientProxyBase.cs index ff8b67f..adb3c0b 100644 --- a/ClientProxyBase/ClientProxyBase.cs +++ b/ClientProxyBase/ClientProxyBase.cs @@ -109,7 +109,8 @@ protected virtual async Task> SendGetRequest(String { HttpRequestMessage requestMessage = new(HttpMethod.Get, uri); - requestMessage.Headers.Authorization = new AuthenticationHeaderValue(AuthenticationSchemes.Bearer, accessToken); + if (String.IsNullOrEmpty(accessToken) == false) + requestMessage.Headers.Authorization = new AuthenticationHeaderValue(AuthenticationSchemes.Bearer, accessToken); // Make the Http Call here HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(requestMessage, cancellationToken); @@ -129,8 +130,15 @@ protected virtual async Task> SendPostRequest> SendPutRequest> SendPatchRequest> SendDeleteRequest(Str { HttpRequestMessage requestMessage = new(HttpMethod.Delete, uri); - requestMessage.Headers.Authorization = new AuthenticationHeaderValue(AuthenticationSchemes.Bearer, accessToken); + if (String.IsNullOrEmpty(accessToken) == false) + requestMessage.Headers.Authorization = new AuthenticationHeaderValue(AuthenticationSchemes.Bearer, accessToken); // Make the Http Call here HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(requestMessage, cancellationToken); diff --git a/Shared.IntegrationTesting.Tests/GenericSteps.cs b/Shared.IntegrationTesting.Tests/GenericSteps.cs index 85dcb70..12f3de0 100644 --- a/Shared.IntegrationTesting.Tests/GenericSteps.cs +++ b/Shared.IntegrationTesting.Tests/GenericSteps.cs @@ -1,6 +1,9 @@ -namespace Shared.IntegrationTesting.Tests; +using ClientProxyBase; + +namespace Shared.IntegrationTesting.Tests; using Logger; +using Microsoft.AspNetCore.Http; using NLog; using Reqnroll; @@ -43,8 +46,8 @@ public async Task StartSystem() { DockerServices services = DockerServices.EventStore | DockerServices.MessagingService | DockerServices.SecurityService | DockerServices.CallbackHandler | DockerServices.FileProcessor | DockerServices.TestHost | DockerServices.TransactionProcessor | - DockerServices.TransactionProcessorAcl; - + DockerServices.TransactionProcessorAcl | DockerServices.KeyCloak; + this.TestingContext.Logger = logger; this.TestingContext.Logger.LogInformation("About to Start Containers for Scenario Run"); this.TestingContext.DockerHelper.ScenarioName = scenarioName; @@ -52,6 +55,8 @@ public async Task StartSystem() { this.TestingContext.Logger.LogInformation("Containers for Scenario Run Started"); } + + [AfterScenario()] public async Task StopSystem(){ DockerServices sharedDockerServices = DockerServices.SqlServer; diff --git a/Shared.IntegrationTesting.Tests/Shared.IntegrationTesting.Tests.csproj b/Shared.IntegrationTesting.Tests/Shared.IntegrationTesting.Tests.csproj index c19603a..9b6d072 100644 --- a/Shared.IntegrationTesting.Tests/Shared.IntegrationTesting.Tests.csproj +++ b/Shared.IntegrationTesting.Tests/Shared.IntegrationTesting.Tests.csproj @@ -28,6 +28,7 @@ + diff --git a/Shared.IntegrationTesting/BaseDockerHelper.cs b/Shared.IntegrationTesting/BaseDockerHelper.cs index ce1a892..bf00686 100644 --- a/Shared.IntegrationTesting/BaseDockerHelper.cs +++ b/Shared.IntegrationTesting/BaseDockerHelper.cs @@ -106,9 +106,12 @@ public abstract class BaseDockerHelper{ protected List TestNetworks; protected String TransactionProcessorAclContainerName; - + protected Int32 TransactionProcessorAclPort; + protected String KeyCloakContainerName; + protected Int32 KeyCloakPort; + protected String TransactionProcessorContainerName; protected Int32 TransactionProcessorPort; @@ -146,6 +149,7 @@ protected BaseDockerHelper(Boolean skipHealthChecks=false) { this.ImageDetails.Add(ContainerType.TransactionProcessor, ("stuartferguson/transactionprocessorwindows:master", true)); this.ImageDetails.Add(ContainerType.FileProcessor, ("stuartferguson/fileprocessorwindows:master", true)); this.ImageDetails.Add(ContainerType.TransactionProcessorAcl, ("stuartferguson/transactionprocessoraclwindows:master", true)); + this.ImageDetails.Add(ContainerType.Keycloak, ("quay.io/keycloak/keycloak:26.4.1", true)); // Note: this may not work... } else{ if (FdOs.IsLinux()){ @@ -163,6 +167,7 @@ protected BaseDockerHelper(Boolean skipHealthChecks=false) { this.ImageDetails.Add(ContainerType.TransactionProcessor, ("stuartferguson/transactionprocessor:master", true)); this.ImageDetails.Add(ContainerType.FileProcessor, ("stuartferguson/fileprocessor:master", true)); this.ImageDetails.Add(ContainerType.TransactionProcessorAcl, ("stuartferguson/transactionprocessoracl:master", true)); + this.ImageDetails.Add(ContainerType.Keycloak, ("quay.io/keycloak/keycloak:26.4.1", true)); } this.HostPorts = new Dictionary(); @@ -320,6 +325,7 @@ public virtual void SetupContainerNames(){ this.MessagingServiceContainerName = $"messaging{this.TestId:N}"; this.TransactionProcessorContainerName = $"transaction{this.TestId:N}"; this.TransactionProcessorAclContainerName = $"transactionacl{this.TestId:N}"; + this.KeyCloakContainerName= $"keycloak{this.TestId:N}"; } public virtual ContainerBuilder SetupEventStoreContainer(){ @@ -368,6 +374,22 @@ public virtual ContainerBuilder SetupEventStoreContainer(){ return eventStoreContainerBuilder; } + public virtual ContainerBuilder SetupKeycloakContainer() + { + this.Trace("About to Start KeyCloak Container"); + + List environmentVariables = new(); + environmentVariables.Add("KC_BOOTSTRAP_ADMIN_USERNAME=admin"); + environmentVariables.Add("KC_BOOTSTRAP_ADMIN_PASSWORD=admin"); + + ContainerBuilder keycloakContainer = new Builder().UseContainer() + .WithName(this.KeyCloakContainerName).WithEnvironment(environmentVariables.ToArray()) + .UseImageDetails(this.GetImageDetails(ContainerType.Keycloak).Data).ExposePort(DockerPorts.KeyCloakDockerPort) + .Command("start-dev"); // 👈 equivalent to `docker run ... start-dev` + + return keycloakContainer; + } + public virtual ContainerBuilder SetupFileProcessorContainer(){ this.Trace("About to Start File Processor Container"); @@ -934,6 +956,7 @@ protected async Task StartContainer2(Func b DockerServices.TransactionProcessorAcl => ContainerType.TransactionProcessorAcl, DockerServices.EventStore=> ContainerType.EventStore, DockerServices.SqlServer => ContainerType.SqlServer, + DockerServices.KeyCloak => ContainerType.Keycloak, _ => ContainerType.NotSet }; @@ -1009,6 +1032,9 @@ Int32 GetPort(Int32 dockerPort) => case ContainerType.TransactionProcessorAcl: TransactionProcessorAclPort = GetPort(DockerPorts.TransactionProcessorAclDockerPort); break; + case ContainerType.Keycloak: + this.KeyCloakPort = GetPort(DockerPorts.KeyCloakDockerPort); + break; } } diff --git a/Shared.IntegrationTesting/ContainerType.cs b/Shared.IntegrationTesting/ContainerType.cs index 7035ecd..71c03bd 100644 --- a/Shared.IntegrationTesting/ContainerType.cs +++ b/Shared.IntegrationTesting/ContainerType.cs @@ -11,5 +11,6 @@ public enum ContainerType TransactionProcessor, FileProcessor, TransactionProcessorAcl, + Keycloak, NotSet } \ No newline at end of file diff --git a/Shared.IntegrationTesting/DockerHelper.cs b/Shared.IntegrationTesting/DockerHelper.cs index 3530641..b0d4055 100644 --- a/Shared.IntegrationTesting/DockerHelper.cs +++ b/Shared.IntegrationTesting/DockerHelper.cs @@ -1,12 +1,9 @@ -namespace Shared.IntegrationTesting; +using System.Net.Http; +using System.Text; +using System.Threading; + +namespace Shared.IntegrationTesting; -using System; -using System.Collections.Generic; -using System.Diagnostics.Metrics; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Threading.Tasks; using Ductus.FluentDocker; using Ductus.FluentDocker.Commands; using Ductus.FluentDocker.Common; @@ -16,6 +13,14 @@ using Ductus.FluentDocker.Services.Extensions; using Newtonsoft.Json; using Shouldly; +using System; +using System.Collections.Generic; +using System.Diagnostics.Metrics; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text.Json.Serialization; +using System.Threading.Tasks; [Flags] public enum DockerServices{ @@ -27,7 +32,9 @@ public enum DockerServices{ TestHost = 32, TransactionProcessor = 64, FileProcessor = 128, - TransactionProcessorAcl = 256 } + TransactionProcessorAcl = 256, + KeyCloak = 512 +} public abstract class DockerHelper : BaseDockerHelper { @@ -116,7 +123,8 @@ public override async Task StartContainersForScenarioRun(String scenarioName, Do await StartContainer2(this.SetupTransactionProcessorContainer, networks, DockerServices.TransactionProcessor); await StartContainer2(this.SetupFileProcessorContainer, networks, DockerServices.FileProcessor); await StartContainer2(this.SetupTransactionProcessorAclContainer, networks, DockerServices.TransactionProcessorAcl); - + await StartContainer2(this.SetupKeycloakContainer, networks, DockerServices.KeyCloak); + await this.LoadEventStoreProjections(); await this.CreateSubscriptions(); diff --git a/Shared.IntegrationTesting/DockerPorts.cs b/Shared.IntegrationTesting/DockerPorts.cs index a7564e8..8313af5 100644 --- a/Shared.IntegrationTesting/DockerPorts.cs +++ b/Shared.IntegrationTesting/DockerPorts.cs @@ -21,4 +21,6 @@ public static class DockerPorts public static readonly Int32 TransactionProcessorAclDockerPort = 5003; public static readonly Int32 TransactionProcessorDockerPort = 5002; + + public static readonly Int32 KeyCloakDockerPort = 8080; } \ No newline at end of file diff --git a/Shared.IntegrationTesting/Shared.IntegrationTesting.csproj b/Shared.IntegrationTesting/Shared.IntegrationTesting.csproj index a8d8920..04f8a7d 100644 --- a/Shared.IntegrationTesting/Shared.IntegrationTesting.csproj +++ b/Shared.IntegrationTesting/Shared.IntegrationTesting.csproj @@ -2,7 +2,7 @@ net9.0 - None + Full @@ -19,6 +19,7 @@ + From 2befc4f17442c551fe057b5f17c89e9cbe1a11da Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Wed, 22 Oct 2025 09:18:03 +0100 Subject: [PATCH 2/2] remove windows workflows --- .github/workflows/nightlybuild.yml | 68 ++++++++++----------- .github/workflows/pullrequest.yml | 96 +++++++++++++++--------------- 2 files changed, 82 insertions(+), 82 deletions(-) diff --git a/.github/workflows/nightlybuild.yml b/.github/workflows/nightlybuild.yml index 51fc1ef..b3cdfda 100644 --- a/.github/workflows/nightlybuild.yml +++ b/.github/workflows/nightlybuild.yml @@ -76,49 +76,49 @@ jobs: name: tracelogslinux path: /home/txnproc/trace/ - buildwindows: - name: "Nightly Build - Windows" - env: - ASPNETCORE_ENVIRONMENT: "Production" + # buildwindows: + # name: "Nightly Build - Windows" + # env: + # ASPNETCORE_ENVIRONMENT: "Production" - runs-on: windows-latest + # runs-on: windows-latest - steps: - - uses: actions/checkout@v1 + # steps: + # - uses: actions/checkout@v1 - - name: Install NET 9 - uses: actions/setup-dotnet@v4.0.1 - with: - dotnet-version: '9.0.x' + # - name: Install NET 9 + # uses: actions/setup-dotnet@v4.0.1 + # with: + # dotnet-version: '9.0.x' - - name: Build Windows SQL Server - run: | - cd SQLDocker - docker build -t mssqlserver:2022-ltsc2022 --build-arg SQL_VERSION=2022 --build-arg WIN_VERSION=ltsc2022 . + # - name: Build Windows SQL Server + # run: | + # cd SQLDocker + # docker build -t mssqlserver:2022-ltsc2022 --build-arg SQL_VERSION=2022 --build-arg WIN_VERSION=ltsc2022 . - - name: Restore Nuget Packages - run: dotnet restore Shared.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }} + # - name: Restore Nuget Packages + # run: dotnet restore Shared.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }} - - name: Build Code - run: dotnet build Shared.sln --configuration Release + # - name: Build Code + # run: dotnet build Shared.sln --configuration Release - - name: Run Event Store Tests - run: | - echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" - dotnet test "Shared.EventStoreContext.Tests\Shared.EventStoreContext.Tests.csproj" + # - name: Run Event Store Tests + # run: | + # echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" + # dotnet test "Shared.EventStoreContext.Tests\Shared.EventStoreContext.Tests.csproj" - - name: Run Integration Tests - env: - IsCI: true - run: | - echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" - dotnet test "Shared.IntegrationTesting.Tests\Shared.IntegrationTesting.Tests.csproj" + # - name: Run Integration Tests + # env: + # IsCI: true + # run: | + # echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" + # dotnet test "Shared.IntegrationTesting.Tests\Shared.IntegrationTesting.Tests.csproj" - - uses: actions/upload-artifact@v4.4.3 - if: ${{ failure() }} - with: - name: tracelogswindows - path: C:\\Users\\runneradmin\\txnproc + # - uses: actions/upload-artifact@v4.4.3 + # if: ${{ failure() }} + # with: + # name: tracelogswindows + # path: C:\\Users\\runneradmin\\txnproc # buildmacos: # name: "Nightly Build - Mac" diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index 5d39af9..0018f77 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -54,55 +54,55 @@ jobs: name: tracelogslinux path: /home/txnproc/trace/ - buildwindows: - name: "Build and Test Pull Requests - Windows" - env: - ASPNETCORE_ENVIRONMENT: "Production" - - runs-on: windows-latest - - steps: - - uses: actions/checkout@v1 - - - name: Install NET 9 - uses: actions/setup-dotnet@v4.0.1 - with: - dotnet-version: '9.0.x' - - - name: Build Windows SQL Server - run: | - cd SQLDocker - docker build -t mssqlserver:2022-ltsc2022 --build-arg SQL_VERSION=2022 --build-arg WIN_VERSION=ltsc2022 . - - - name: Restore Nuget Packages - run: dotnet restore Shared.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }} - - - name: Build Code - run: dotnet build Shared.sln --configuration Release - - - name: Run Unit Tests - run: | - echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" - dotnet test "Shared.Tests\Shared.Tests.csproj" - - - name: Run Event Store Tests - run: | - echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" - dotnet test "Shared.EventStore.Tests\Shared.EventStore.Tests.csproj" - dotnet test "Shared.EventStoreContext.Tests\Shared.EventStoreContext.Tests.csproj" - - - name: Run Integration Tests - env: - IsCI: true - run: | - echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" - dotnet test "Shared.IntegrationTesting.Tests\Shared.IntegrationTesting.Tests.csproj" + # buildwindows: + # name: "Build and Test Pull Requests - Windows" + # env: + # ASPNETCORE_ENVIRONMENT: "Production" - - uses: actions/upload-artifact@v4.4.3 - #if: ${{ failure() }} - with: - name: tracelogswindows - path: C:\\Users\\runneradmin\\txnproc + # runs-on: windows-latest + + # steps: + # - uses: actions/checkout@v1 + + # - name: Install NET 9 + # uses: actions/setup-dotnet@v4.0.1 + # with: + # dotnet-version: '9.0.x' + + # - name: Build Windows SQL Server + # run: | + # cd SQLDocker + # docker build -t mssqlserver:2022-ltsc2022 --build-arg SQL_VERSION=2022 --build-arg WIN_VERSION=ltsc2022 . + + # - name: Restore Nuget Packages + # run: dotnet restore Shared.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }} + + # - name: Build Code + # run: dotnet build Shared.sln --configuration Release + + # - name: Run Unit Tests + # run: | + # echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" + # dotnet test "Shared.Tests\Shared.Tests.csproj" + + # - name: Run Event Store Tests + # run: | + # echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" + # dotnet test "Shared.EventStore.Tests\Shared.EventStore.Tests.csproj" + # dotnet test "Shared.EventStoreContext.Tests\Shared.EventStoreContext.Tests.csproj" + + # - name: Run Integration Tests + # env: + # IsCI: true + # run: | + # echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" + # dotnet test "Shared.IntegrationTesting.Tests\Shared.IntegrationTesting.Tests.csproj" + + # - uses: actions/upload-artifact@v4.4.3 + # #if: ${{ failure() }} + # with: + # name: tracelogswindows + # path: C:\\Users\\runneradmin\\txnproc # buildmacos: # name: "Build and Test Pull Requests - Mac"