diff --git a/Sample/Helpdesk/Helpdesk.Api/.dockerignore b/Sample/Helpdesk/Helpdesk.Api/.dockerignore index c8a50845c..b48a1fe79 100644 --- a/Sample/Helpdesk/Helpdesk.Api/.dockerignore +++ b/Sample/Helpdesk/Helpdesk.Api/.dockerignore @@ -2,5 +2,5 @@ **/obj/ **/out/ **/TestResults/ -**/Internal/Generated +**/Internal/ Dockerfile diff --git a/Sample/Helpdesk/Helpdesk.Api/Dockerfile b/Sample/Helpdesk/Helpdesk.Api/Dockerfile index 6608373d2..c7018320f 100644 --- a/Sample/Helpdesk/Helpdesk.Api/Dockerfile +++ b/Sample/Helpdesk/Helpdesk.Api/Dockerfile @@ -21,7 +21,10 @@ RUN dotnet restore ./${project_name}.csproj COPY ./ ./ # Run code generation depending on the build argument -RUN if [ "run_codegen" = true ] ; then dotnet run -- codegen write & dotnet run -- codegen test; else echo "skipping code generation"; fi +RUN if [ "${run_codegen}" = true ] ; then dotnet run -- codegen write & dotnet run -- codegen test; else echo "skipping code generation"; fi + +RUN ls +RUN ls -R Internal # Build project with Release configuration # and no restore, as we did it already @@ -29,12 +32,12 @@ RUN dotnet build -c Release --no-restore ./${project_name}.csproj ## Test project with Release configuration ## and no build, as we did it already -#RUN dotnet test -c Release --no-build ./Sample/Tickets/Tickets.Api/Tickets.Api.csproj +# RUN dotnet test -c Release --no-build ./Sample/Tickets/Tickets.Api/Tickets.Api.csproj # Publish project to output folder # and no build, as we did it already WORKDIR /app/ -RUN ls + RUN dotnet publish -c Release --no-build -o out ######################################## diff --git a/Sample/Helpdesk/Helpdesk.Api/Incidents/GetCustomerIncidentsSummary/IncidentSummary.cs b/Sample/Helpdesk/Helpdesk.Api/Incidents/GetCustomerIncidentsSummary/IncidentSummary.cs index df7d45544..b01d227bb 100644 --- a/Sample/Helpdesk/Helpdesk.Api/Incidents/GetCustomerIncidentsSummary/IncidentSummary.cs +++ b/Sample/Helpdesk/Helpdesk.Api/Incidents/GetCustomerIncidentsSummary/IncidentSummary.cs @@ -24,6 +24,7 @@ public CustomerIncidentsSummaryProjection() public void Apply(IncidentLogged logged, CustomerIncidentsSummary current) { + current.Id = logged.CustomerId; current.Pending++; } diff --git a/Sample/Helpdesk/Helpdesk.Api/Program.cs b/Sample/Helpdesk/Helpdesk.Api/Program.cs index f0a971aa0..69e186ffd 100644 --- a/Sample/Helpdesk/Helpdesk.Api/Program.cs +++ b/Sample/Helpdesk/Helpdesk.Api/Program.cs @@ -15,6 +15,7 @@ using Marten.Events.Projections; using Marten.Pagination; using Marten.Schema.Identity; +using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; using Oakton; @@ -27,7 +28,7 @@ var builder = WebApplication.CreateBuilder(args); - +builder.WebHost.UseUrls("http://*:5248"); builder.Services .AddEndpointsApiExplorer() .AddSwaggerGen() @@ -53,15 +54,25 @@ options.Projections.Add(ProjectionLifecycle.Inline); options.Projections.Add(ProjectionLifecycle.Async); + options.ApplicationAssembly = typeof(CustomerIncidentsSummaryProjection).Assembly; + return options; }) .AddSubscriptionWithServices(ServiceLifetime.Singleton) .AddSubscriptionWithServices>(ServiceLifetime.Singleton) .OptimizeArtifactWorkflow(TypeLoadMode.Static) + .ApplyAllDatabaseChangesOnStartup() .UseLightweightSessions() - .AddAsyncDaemon(DaemonMode.Solo); + .AddAsyncDaemon(DaemonMode.HotCold); +// Header forwarding to enable Swagger in Nginx +builder.Services.Configure(options => +{ + options.ForwardedHeaders = + ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; +}); + builder.Services .AddCors(options => options.AddPolicy("ClientPermission", policy => @@ -235,11 +246,9 @@ await documentSession.GetAndUpdate(incidentId, ToExpectedVersion(eTag) querySession.Json.WriteById(customerId, context) ); -if (app.Environment.IsDevelopment()) -{ - app.UseSwagger() - .UseSwaggerUI(); -} +app.UseSwagger() + .UseSwaggerUI() + .UseForwardedHeaders(); // Header forwarding to enable Swagger in Nginx app.UseCors("ClientPermission"); diff --git a/Sample/Helpdesk/Helpdesk.Api/docker-compose.yml b/Sample/Helpdesk/Helpdesk.Api/docker-compose.yml new file mode 100644 index 000000000..19a662aff --- /dev/null +++ b/Sample/Helpdesk/Helpdesk.Api/docker-compose.yml @@ -0,0 +1,40 @@ +version: "3.8" +services: + nginx: + restart: always + image: nginx:alpine + ports: + - 8089:80 + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf +# - ./nginx.conf:/etc/nginx/conf.d/default.conf + depends_on: + - backend + + backend: + build: + dockerfile: Dockerfile + context: . + args: + project_name: Helpdesk.Api + run_codegen: true + deploy: + replicas: 3 + depends_on: + postgres: + condition: service_healthy + restart: always + + postgres: + image: postgres:15.1-alpine + container_name: postgres + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + environment: + - POSTGRES_DB=postgres + - POSTGRES_PASSWORD=Password12! + ports: + - "5432:5432" diff --git a/Sample/Helpdesk/Helpdesk.Api/nginx.conf b/Sample/Helpdesk/Helpdesk.Api/nginx.conf new file mode 100644 index 000000000..ca6310350 --- /dev/null +++ b/Sample/Helpdesk/Helpdesk.Api/nginx.conf @@ -0,0 +1,26 @@ +worker_processes auto; + +events { + worker_connections 1024; +} + +http { + map $http_connection $connection_upgrade { + "~*Upgrade" $http_connection; + default keep-alive; + } + + server { + listen 80; + location / { + proxy_pass http://backend:5248/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + } +}