From 17c7830655099ffdda1bf043c1e4c43127322c3d Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 15 Feb 2022 15:12:30 +0300 Subject: [PATCH 1/4] added gateway host builder extensions --- .../GatewayHostBuilderExtensions.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 shared/EShopOnAbp.Shared.Hosting.Gateways/GatewayHostBuilderExtensions.cs diff --git a/shared/EShopOnAbp.Shared.Hosting.Gateways/GatewayHostBuilderExtensions.cs b/shared/EShopOnAbp.Shared.Hosting.Gateways/GatewayHostBuilderExtensions.cs new file mode 100644 index 00000000..b53c608f --- /dev/null +++ b/shared/EShopOnAbp.Shared.Hosting.Gateways/GatewayHostBuilderExtensions.cs @@ -0,0 +1,24 @@ +using Microsoft.Extensions.Configuration; + +namespace Microsoft.Extensions.Hosting; + +public static class AbpHostingHostBuilderExtensions +{ + public const string AppOcelotJsonPath = "ocelot.json"; + + public static IHostBuilder AddOcelotJson( + this IHostBuilder hostBuilder, + bool optional = true, + bool reloadOnChange = true, + string path = AppOcelotJsonPath) + { + return hostBuilder.ConfigureAppConfiguration((_, builder) => + { + builder.AddJsonFile( + path: AppOcelotJsonPath, + optional: optional, + reloadOnChange: reloadOnChange + ); + }); + } +} \ No newline at end of file From 25e4f92e019960d12535de2082bc1bc21b7fb3ae Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 15 Feb 2022 15:12:46 +0300 Subject: [PATCH 2/4] added web-public gateway ocelot configuration --- .../EShopOnAbp.WebPublicGateway/Program.cs | 15 ++- .../appsettings.json | 99 +---------------- .../EShopOnAbp.WebPublicGateway/ocelot.json | 100 ++++++++++++++++++ 3 files changed, 114 insertions(+), 100 deletions(-) create mode 100644 gateways/web-public/src/EShopOnAbp.WebPublicGateway/ocelot.json diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Program.cs b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Program.cs index b7e61272..d60f0442 100644 --- a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Program.cs +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Program.cs @@ -3,6 +3,8 @@ using Serilog; using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; namespace EShopOnAbp.WebPublicGateway; @@ -17,10 +19,19 @@ public class Program try { Log.Information($"Starting {assemblyName}."); - var app = await ApplicationBuilderHelper.BuildApplicationAsync(args); + + var builder = WebApplication.CreateBuilder(args); + builder.Host + .AddAppSettingsSecretsJson() + .AddOcelotJson() + .UseAutofac() + .UseSerilog(); + + await builder.AddApplicationAsync(); + var app = builder.Build(); await app.InitializeApplicationAsync(); await app.RunAsync(); - + return 0; } catch (Exception ex) diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json index 1eee0654..dfe10330 100644 --- a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json @@ -17,104 +17,7 @@ } }, "AllowedHosts": "*", - "Routes": [ - { - "ServiceKey": "Account Service", - "DownstreamPathTemplate": "/api/account/{everything}", - "DownstreamScheme": "https", - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 44330 - } - ], - "UpstreamPathTemplate": "/api/account/{everything}", - "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] - }, - { - "ServiceKey": "Administration Service", - "DownstreamPathTemplate": "/api/abp/{everything}", - "DownstreamScheme": "https", - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 44353 - } - ], - "UpstreamPathTemplate": "/api/abp/{everything}", - "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ], - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 3000, - "TimeoutValue": 2500 - } - }, - { - "ServiceKey": "Catalog Service", - "DownstreamPathTemplate": "/api/catalog/{everything}", - "DownstreamScheme": "https", - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 44354 - } - ], - "UpstreamPathTemplate": "/api/catalog/{everything}", - "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ], - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 3000, - "TimeoutValue": 2500 - } - }, - { - "ServiceKey": "Basket Service", - "DownstreamPathTemplate": "/api/basket/{everything}", - "DownstreamScheme": "https", - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 44355 - } - ], - "UpstreamPathTemplate": "/api/basket/{everything}", - "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ], - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 3000, - "TimeoutValue": 2500 - } - }, - { - "ServiceKey": "Ordering Service", - "DownstreamPathTemplate": "/api/ordering/{everything}", - "DownstreamScheme": "https", - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 44356 - } - ], - "UpstreamPathTemplate": "/api/ordering/{everything}", - "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] - }, - { - "ServiceKey": "Payment Service", - "DownstreamPathTemplate": "/api/payment/{everything}", - "DownstreamScheme": "https", - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 44357 - } - ], - "UpstreamPathTemplate": "/api/payment/{everything}", - "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] - } - ], - "GlobalConfiguration": { - "BaseUrl": "https://localhost:44373" - }, + "Redis": { "Configuration": "localhost:6379" }, diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/ocelot.json b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/ocelot.json new file mode 100644 index 00000000..5c94283d --- /dev/null +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/ocelot.json @@ -0,0 +1,100 @@ +{ + "GlobalConfiguration": { + "BaseUrl": "https://localhost:44373" + }, + "Routes": [ + { + "ServiceKey": "Account Service", + "DownstreamPathTemplate": "/api/account/{everything}", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 44330 + } + ], + "UpstreamPathTemplate": "/api/account/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] + }, + { + "ServiceKey": "Administration Service", + "DownstreamPathTemplate": "/api/abp/{everything}", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 44353 + } + ], + "UpstreamPathTemplate": "/api/abp/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ], + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 3000, + "TimeoutValue": 2500 + } + }, + { + "ServiceKey": "Catalog Service", + "DownstreamPathTemplate": "/api/catalog/{everything}", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 44354 + } + ], + "UpstreamPathTemplate": "/api/catalog/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ], + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 3000, + "TimeoutValue": 2500 + } + }, + { + "ServiceKey": "Basket Service", + "DownstreamPathTemplate": "/api/basket/{everything}", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 44355 + } + ], + "UpstreamPathTemplate": "/api/basket/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ], + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 3000, + "TimeoutValue": 2500 + } + }, + { + "ServiceKey": "Ordering Service", + "DownstreamPathTemplate": "/api/ordering/{everything}", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 44356 + } + ], + "UpstreamPathTemplate": "/api/ordering/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] + }, + { + "ServiceKey": "Payment Service", + "DownstreamPathTemplate": "/api/payment/{everything}", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 44357 + } + ], + "UpstreamPathTemplate": "/api/payment/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] + } + ] +} \ No newline at end of file From 766fd511038d9089653156d99da05b1bcc94486a Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 15 Feb 2022 15:12:56 +0300 Subject: [PATCH 3/4] added web gateway ocelot configuration --- .../web/src/EShopOnAbp.WebGateway/Program.cs | 14 ++- .../EShopOnAbp.WebGateway/appsettings.json | 89 +----------------- .../web/src/EShopOnAbp.WebGateway/ocelot.json | 90 +++++++++++++++++++ 3 files changed, 103 insertions(+), 90 deletions(-) create mode 100644 gateways/web/src/EShopOnAbp.WebGateway/ocelot.json diff --git a/gateways/web/src/EShopOnAbp.WebGateway/Program.cs b/gateways/web/src/EShopOnAbp.WebGateway/Program.cs index 03378683..244114fe 100644 --- a/gateways/web/src/EShopOnAbp.WebGateway/Program.cs +++ b/gateways/web/src/EShopOnAbp.WebGateway/Program.cs @@ -3,6 +3,8 @@ using Serilog; using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; namespace EShopOnAbp.WebGateway; @@ -17,10 +19,18 @@ public class Program try { Log.Information($"Starting {assemblyName}."); - var app = await ApplicationBuilderHelper.BuildApplicationAsync(args); + var builder = WebApplication.CreateBuilder(args); + builder.Host + .AddAppSettingsSecretsJson() + .AddOcelotJson() + .UseAutofac() + .UseSerilog(); + + await builder.AddApplicationAsync(); + var app = builder.Build(); await app.InitializeApplicationAsync(); await app.RunAsync(); - + return 0; } catch (Exception ex) diff --git a/gateways/web/src/EShopOnAbp.WebGateway/appsettings.json b/gateways/web/src/EShopOnAbp.WebGateway/appsettings.json index 091f7419..dea2bd3b 100644 --- a/gateways/web/src/EShopOnAbp.WebGateway/appsettings.json +++ b/gateways/web/src/EShopOnAbp.WebGateway/appsettings.json @@ -17,94 +17,7 @@ } }, "AllowedHosts": "*", - "Routes": [ - { - "ServiceKey": "Identity Service", - "DownstreamPathTemplate": "/api/identity/{everything}", - "DownstreamScheme": "https", - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 44351 - } - ], - "UpstreamPathTemplate": "/api/identity/{everything}", - "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] - }, - { - "ServiceKey": "Account Service", - "DownstreamPathTemplate": "/api/account/{everything}", - "DownstreamScheme": "https", - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 44330 - } - ], - "UpstreamPathTemplate": "/api/account/{everything}", - "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] - }, - { - "ServiceKey": "Administration Service", - "DownstreamPathTemplate": "/api/abp/{everything}", - "DownstreamScheme": "https", - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 44353 - } - ], - "UpstreamPathTemplate": "/api/abp/{everything}", - "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ], - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 5000, - "TimeoutValue": 2500 - } - }, - { - "ServiceKey": "Administration Service", - "DownstreamPathTemplate": "/api/feature-management/{everything}", - "DownstreamScheme": "https", - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 44353 - } - ], - "UpstreamPathTemplate": "/api/feature-management/{everything}", - "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] - }, - { - "ServiceKey": "Administration Service", - "DownstreamPathTemplate": "/api/permission-management/{everything}", - "DownstreamScheme": "https", - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 44353 - } - ], - "UpstreamPathTemplate": "/api/permission-management/{everything}", - "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] - }, - { - "ServiceKey": "Administration Service", - "DownstreamPathTemplate": "/api/setting-management/{everything}", - "DownstreamScheme": "https", - "DownstreamHostAndPorts": [ - { - "Host": "localhost", - "Port": 44353 - } - ], - "UpstreamPathTemplate": "/api/setting-management/{everything}", - "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] - } - ], - "GlobalConfiguration": { - "BaseUrl": "https://localhost:44372" - }, + "Redis": { "Configuration": "localhost:6379" }, diff --git a/gateways/web/src/EShopOnAbp.WebGateway/ocelot.json b/gateways/web/src/EShopOnAbp.WebGateway/ocelot.json new file mode 100644 index 00000000..affe35be --- /dev/null +++ b/gateways/web/src/EShopOnAbp.WebGateway/ocelot.json @@ -0,0 +1,90 @@ +{ + "GlobalConfiguration": { + "BaseUrl": "https://localhost:44372" + }, + "Routes": [ + { + "ServiceKey": "Identity Service", + "DownstreamPathTemplate": "/api/identity/{everything}", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 44351 + } + ], + "UpstreamPathTemplate": "/api/identity/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] + }, + { + "ServiceKey": "Account Service", + "DownstreamPathTemplate": "/api/account/{everything}", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 44330 + } + ], + "UpstreamPathTemplate": "/api/account/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] + }, + { + "ServiceKey": "Administration Service", + "DownstreamPathTemplate": "/api/abp/{everything}", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 44353 + } + ], + "UpstreamPathTemplate": "/api/abp/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ], + "QoSOptions": { + "ExceptionsAllowedBeforeBreaking": 3, + "DurationOfBreak": 5000, + "TimeoutValue": 2500 + } + }, + { + "ServiceKey": "Administration Service", + "DownstreamPathTemplate": "/api/feature-management/{everything}", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 44353 + } + ], + "UpstreamPathTemplate": "/api/feature-management/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] + }, + { + "ServiceKey": "Administration Service", + "DownstreamPathTemplate": "/api/permission-management/{everything}", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 44353 + } + ], + "UpstreamPathTemplate": "/api/permission-management/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] + }, + { + "ServiceKey": "Administration Service", + "DownstreamPathTemplate": "/api/setting-management/{everything}", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 44353 + } + ], + "UpstreamPathTemplate": "/api/setting-management/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] + } + ] +} \ No newline at end of file From 083dfe37b5b521a0b7fecf2bd4f2ca5d9125a9df Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 15 Feb 2022 15:19:42 +0300 Subject: [PATCH 4/4] updated helm charts --- .../templates/gateway-web-public-configmap.yaml | 5 ++++- .../templates/gateway-web-public-deployment.yaml | 4 ++-- .../charts/gateway-web/templates/gateway-web-configmap.yaml | 5 ++++- .../charts/gateway-web/templates/gateway-web-deployment.yaml | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/etc/k8s/eshoponabp/charts/gateway-web-public/templates/gateway-web-public-configmap.yaml b/etc/k8s/eshoponabp/charts/gateway-web-public/templates/gateway-web-public-configmap.yaml index 809ea92d..27301408 100644 --- a/etc/k8s/eshoponabp/charts/gateway-web-public/templates/gateway-web-public-configmap.yaml +++ b/etc/k8s/eshoponabp/charts/gateway-web-public/templates/gateway-web-public-configmap.yaml @@ -3,8 +3,11 @@ kind: ConfigMap metadata: name: {{ .Release.Name }}-{{ .Chart.Name }}-configmap data: - appsettings.json: |- + ocelot.json: |- { + "GlobalConfiguration": { + "BaseUrl": "{{ .Values.config.globalConfigurationBaseUrl }}" + }, "Routes": [ { "ServiceKey": "Identity Service", diff --git a/etc/k8s/eshoponabp/charts/gateway-web-public/templates/gateway-web-public-deployment.yaml b/etc/k8s/eshoponabp/charts/gateway-web-public/templates/gateway-web-public-deployment.yaml index 910a6606..59db1066 100644 --- a/etc/k8s/eshoponabp/charts/gateway-web-public/templates/gateway-web-public-deployment.yaml +++ b/etc/k8s/eshoponabp/charts/gateway-web-public/templates/gateway-web-public-deployment.yaml @@ -22,8 +22,8 @@ spec: containerPort: 443 volumeMounts: - name: config-volume - mountPath: /app/appsettings.json - subPath: appsettings.json + mountPath: /app/ocelot.json + subPath: ocelot.json env: - name: App__SelfUrl value: "{{ .Values.config.selfUrl }}" diff --git a/etc/k8s/eshoponabp/charts/gateway-web/templates/gateway-web-configmap.yaml b/etc/k8s/eshoponabp/charts/gateway-web/templates/gateway-web-configmap.yaml index 22d1155e..ec349914 100644 --- a/etc/k8s/eshoponabp/charts/gateway-web/templates/gateway-web-configmap.yaml +++ b/etc/k8s/eshoponabp/charts/gateway-web/templates/gateway-web-configmap.yaml @@ -3,8 +3,11 @@ kind: ConfigMap metadata: name: {{ .Release.Name }}-{{ .Chart.Name }}-configmap data: - appsettings.json: |- + ocelot.json: |- { + "GlobalConfiguration": { + "BaseUrl": "{{ .Values.config.globalConfigurationBaseUrl }}" + }, "Routes": [ { "ServiceKey": "Identity Service", diff --git a/etc/k8s/eshoponabp/charts/gateway-web/templates/gateway-web-deployment.yaml b/etc/k8s/eshoponabp/charts/gateway-web/templates/gateway-web-deployment.yaml index 25b3f694..cf3a8a1b 100644 --- a/etc/k8s/eshoponabp/charts/gateway-web/templates/gateway-web-deployment.yaml +++ b/etc/k8s/eshoponabp/charts/gateway-web/templates/gateway-web-deployment.yaml @@ -22,8 +22,8 @@ spec: containerPort: 443 volumeMounts: - name: config-volume - mountPath: /app/appsettings.json - subPath: appsettings.json + mountPath: /app/ocelot.json + subPath: ocelot.json env: - name: App__SelfUrl value: "{{ .Values.config.selfUrl }}"