diff --git a/src/Services/Basket/Basket.API/Startup.cs b/src/Services/Basket/Basket.API/Startup.cs index 79208b19b..46599c616 100644 --- a/src/Services/Basket/Basket.API/Startup.cs +++ b/src/Services/Basket/Basket.API/Startup.cs @@ -28,7 +28,6 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using RabbitMQ.Client; using StackExchange.Redis; -using Swashbuckle.AspNetCore.Swagger; using System; using System.Collections.Generic; using System.IdentityModel.Tokens.Jwt; @@ -191,24 +190,25 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API app.UsePathBase(pathBase); } - app.UseHealthChecks("/hc", new HealthCheckOptions() - { - Predicate = _ => true, - ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse - }); - - app.UseHealthChecks("/liveness", new HealthCheckOptions - { - Predicate = r => r.Name.Contains("self") - }); - app.UseStaticFiles(); app.UseCors("CorsPolicy"); ConfigureAuth(app); app.UseRouting(); - app.UseEndpoints(e => e.MapDefaultControllerRoute()); + app.UseEndpoints(endpoints => + { + endpoints.MapHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + endpoints.MapDefaultControllerRoute(); + }); app.UseSwagger() .UseSwaggerUI(c => @@ -225,13 +225,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API private void RegisterAppInsights(IServiceCollection services) { services.AddApplicationInsightsTelemetry(Configuration); - var orchestratorType = Configuration.GetValue("OrchestratorType"); - - if (orchestratorType?.ToUpper() == "K8S") - { - // Enable K8s telemetry initializer - services.AddApplicationInsightsKubernetesEnricher(); - } + services.AddApplicationInsightsKubernetesEnricher(); } private void ConfigureAuthService(IServiceCollection services) diff --git a/src/Services/Catalog/Catalog.API/Startup.cs b/src/Services/Catalog/Catalog.API/Startup.cs index 716e0f1ca..c34db7614 100644 --- a/src/Services/Catalog/Catalog.API/Startup.cs +++ b/src/Services/Catalog/Catalog.API/Startup.cs @@ -1,8 +1,11 @@ using Autofac; using Autofac.Extensions.DependencyInjection; +using Catalog.API.Grpc; using global::Catalog.API.Infrastructure.Filters; using global::Catalog.API.IntegrationEvents; +using HealthChecks.UI.Client; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -20,17 +23,14 @@ using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHa using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using RabbitMQ.Client; using System; using System.Data.Common; -using System.Reflection; -using HealthChecks.UI.Client; -using Microsoft.AspNetCore.Diagnostics.HealthChecks; -using Microsoft.Extensions.Diagnostics.HealthChecks; -using Catalog.API.Grpc; using System.IO; +using System.Reflection; namespace Microsoft.eShopOnContainers.Services.Catalog.API { @@ -89,10 +89,10 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API app.UseCors("CorsPolicy"); app.UseRouting(); - app.UseEndpoints(e => + app.UseEndpoints(endpoints => { - e.MapDefaultControllerRoute(); - e.MapGet("/_proto/", async ctx => + endpoints.MapDefaultControllerRoute(); + endpoints.MapGet("/_proto/", async ctx => { ctx.Response.ContentType = "text/plain"; using var fs = new FileStream(Path.Combine(env.ContentRootPath, "Proto", "catalog.proto"), FileMode.Open, FileAccess.Read); @@ -106,7 +106,16 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API } } }); - e.MapGrpcService(); + endpoints.MapGrpcService(); + endpoints.MapHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); }); app.UseSwagger() @@ -131,13 +140,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API public static IServiceCollection AddAppInsight(this IServiceCollection services, IConfiguration configuration) { services.AddApplicationInsightsTelemetry(configuration); - var orchestratorType = configuration.GetValue("OrchestratorType"); - - if (orchestratorType?.ToUpper() == "K8S") - { - // Enable K8s telemetry initializer - services.AddApplicationInsightsKubernetesEnricher(); - } + services.AddApplicationInsightsKubernetesEnricher(); return services; } diff --git a/src/Services/Identity/Identity.API/Startup.cs b/src/Services/Identity/Identity.API/Startup.cs index 6ea7e3888..009773b62 100644 --- a/src/Services/Identity/Identity.API/Startup.cs +++ b/src/Services/Identity/Identity.API/Startup.cs @@ -1,28 +1,26 @@ using Autofac; using Autofac.Extensions.DependencyInjection; +using HealthChecks.UI.Client; using IdentityServer4.Services; -using Microsoft.ApplicationInsights.Extensibility; -using Microsoft.ApplicationInsights.ServiceFabric; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.eShopOnContainers.Services.Identity.API.Certificates; using Microsoft.eShopOnContainers.Services.Identity.API.Data; +using Microsoft.eShopOnContainers.Services.Identity.API.Devspaces; using Microsoft.eShopOnContainers.Services.Identity.API.Models; using Microsoft.eShopOnContainers.Services.Identity.API.Services; -using Microsoft.eShopOnContainers.Services.Identity.API.Devspaces; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; using StackExchange.Redis; using System; using System.Reflection; -using HealthChecks.UI.Client; -using Microsoft.AspNetCore.Diagnostics.HealthChecks; -using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Microsoft.eShopOnContainers.Services.Identity.API { @@ -73,7 +71,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API .AddSqlServer(Configuration["ConnectionString"], name: "IdentityDB-check", tags: new string[] { "IdentityDB" }); - + services.AddTransient, EFLoginService>(); services.AddTransient(); @@ -179,19 +177,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API private void RegisterAppInsights(IServiceCollection services) { services.AddApplicationInsightsTelemetry(Configuration); - var orchestratorType = Configuration.GetValue("OrchestratorType"); - - if (orchestratorType?.ToUpper() == "K8S") - { - // Enable K8s telemetry initializer - services.AddApplicationInsightsKubernetesEnricher(); - } - if (orchestratorType?.ToUpper() == "SF") - { - // Enable SF telemetry initializer - services.AddSingleton((serviceProvider) => - new FabricTelemetryInitializer()); - } + services.AddApplicationInsightsKubernetesEnricher(); } } } diff --git a/src/Services/Location/Locations.API/Startup.cs b/src/Services/Location/Locations.API/Startup.cs index cfb9d7e22..7b4a391af 100644 --- a/src/Services/Location/Locations.API/Startup.cs +++ b/src/Services/Location/Locations.API/Startup.cs @@ -167,22 +167,23 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API app.UsePathBase(pathBase); } - app.UseHealthChecks("/liveness", new HealthCheckOptions - { - Predicate = r => r.Name.Contains("self") - }); - - app.UseHealthChecks("/hc", new HealthCheckOptions() - { - Predicate = _ => true, - ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse - }); - app.UseCors("CorsPolicy"); ConfigureAuth(app); - app.UseMvcWithDefaultRoute(); + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + }); app.UseSwagger() .UseSwaggerUI(c => @@ -199,13 +200,7 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API private void RegisterAppInsights(IServiceCollection services) { services.AddApplicationInsightsTelemetry(Configuration); - var orchestratorType = Configuration.GetValue("OrchestratorType"); - - if (orchestratorType?.ToUpper() == "K8S") - { - // Enable K8s telemetry initializer - services.AddApplicationInsightsKubernetesEnricher(); - } + services.AddApplicationInsightsKubernetesEnricher(); } private void ConfigureAuthService(IServiceCollection services) diff --git a/src/Services/Marketing/Marketing.API/Startup.cs b/src/Services/Marketing/Marketing.API/Startup.cs index 3e9c92324..289a9c351 100644 --- a/src/Services/Marketing/Marketing.API/Startup.cs +++ b/src/Services/Marketing/Marketing.API/Startup.cs @@ -190,23 +190,24 @@ app.UsePathBase(pathBase); } - app.UseHealthChecks("/hc", new HealthCheckOptions() - { - Predicate = _ => true, - ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse - }); - - app.UseHealthChecks("/liveness", new HealthCheckOptions - { - Predicate = r => r.Name.Contains("self") - }); - app.UseCors("CorsPolicy"); ConfigureAuth(app); app.UseRouting(); - app.UseEndpoints(e => e.MapDefaultControllerRoute()); + app.UseEndpoints(endpoints => + { + endpoints.MapHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + endpoints.MapDefaultControllerRoute(); + }); app.UseSwagger() .UseSwaggerUI(c => @@ -222,13 +223,7 @@ private void RegisterAppInsights(IServiceCollection services) { services.AddApplicationInsightsTelemetry(Configuration); - var orchestratorType = Configuration.GetValue("OrchestratorType"); - - if (orchestratorType?.ToUpper() == "K8S") - { - // Enable K8s telemetry initializer - services.AddApplicationInsightsKubernetesEnricher(); - } + services.AddApplicationInsightsKubernetesEnricher(); } private void ConfigureAuthService(IServiceCollection services) diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index e4193a5f2..de9a88af1 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -96,7 +96,19 @@ ConfigureAuth(app); app.UseRouting(); - app.UseEndpoints(e => e.MapDefaultControllerRoute()); + app.UseEndpoints(endpoints => + { + endpoints.MapHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + endpoints.MapDefaultControllerRoute(); + }); app.UseSwagger() .UseSwaggerUI(c => @@ -138,13 +150,7 @@ public static IServiceCollection AddApplicationInsights(this IServiceCollection services, IConfiguration configuration) { services.AddApplicationInsightsTelemetry(configuration); - var orchestratorType = configuration.GetValue("OrchestratorType"); - - if (orchestratorType?.ToUpper() == "K8S") - { - // Enable K8s telemetry initializer - services.AddApplicationInsightsKubernetesEnricher(); - } + services.AddApplicationInsightsKubernetesEnricher(); return services; } diff --git a/src/Services/Ordering/Ordering.BackgroundTasks/Startup.cs b/src/Services/Ordering/Ordering.BackgroundTasks/Startup.cs index 9d6a78e38..6035beaeb 100644 --- a/src/Services/Ordering/Ordering.BackgroundTasks/Startup.cs +++ b/src/Services/Ordering/Ordering.BackgroundTasks/Startup.cs @@ -1,7 +1,8 @@ using Autofac; using Autofac.Extensions.DependencyInjection; +using HealthChecks.UI.Client; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.Azure.ServiceBus; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; @@ -9,15 +10,13 @@ using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ; using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Ordering.BackgroundTasks.Configuration; using Ordering.BackgroundTasks.Tasks; using RabbitMQ.Client; using System; -using HealthChecks.UI.Client; -using Microsoft.AspNetCore.Diagnostics.HealthChecks; -using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Ordering.BackgroundTasks { @@ -106,15 +105,18 @@ namespace Ordering.BackgroundTasks // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { - app.UseHealthChecks("/hc", new HealthCheckOptions() + app.UseRouting(); + app.UseEndpoints(endpoints => { - Predicate = _ => true, - ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse - }); - - app.UseHealthChecks("/liveness", new HealthCheckOptions - { - Predicate = r => r.Name.Contains("self") + endpoints.MapHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); }); } diff --git a/src/Services/Ordering/Ordering.SignalrHub/Startup.cs b/src/Services/Ordering/Ordering.SignalrHub/Startup.cs index 23bca1977..78f10adb3 100644 --- a/src/Services/Ordering/Ordering.SignalrHub/Startup.cs +++ b/src/Services/Ordering/Ordering.SignalrHub/Startup.cs @@ -127,32 +127,28 @@ namespace Ordering.SignalrHub //loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); var pathBase = Configuration["PATH_BASE"]; + if (!string.IsNullOrEmpty(pathBase)) { loggerFactory.CreateLogger().LogDebug("Using PATH BASE '{pathBase}'", pathBase); app.UsePathBase(pathBase); } - app.UseHealthChecks("/hc", new HealthCheckOptions() - { - Predicate = _ => true, - ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse - }); - - app.UseHealthChecks("/liveness", new HealthCheckOptions - { - Predicate = r => r.Name.Contains("self") - }); - app.UseCors("CorsPolicy"); - app.UseAuthentication(); - app.UseRouting(); app.UseEndpoints(endpoints => { - endpoints.MapHub("/notificationhub", options => - options.Transports = Microsoft.AspNetCore.Http.Connections.HttpTransports.All); + endpoints.MapHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + endpoints.MapHub("/notificationhub", options => options.Transports = Microsoft.AspNetCore.Http.Connections.HttpTransports.All); }); ConfigureEventBus(app); diff --git a/src/Services/Payment/Payment.API/Startup.cs b/src/Services/Payment/Payment.API/Startup.cs index bd3b7241b..77b8d55fd 100644 --- a/src/Services/Payment/Payment.API/Startup.cs +++ b/src/Services/Payment/Payment.API/Startup.cs @@ -1,6 +1,8 @@ using Autofac; using Autofac.Extensions.DependencyInjection; +using HealthChecks.UI.Client; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.Azure.ServiceBus; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; @@ -8,14 +10,12 @@ using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ; using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; using Payment.API.IntegrationEvents.EventHandling; using Payment.API.IntegrationEvents.Events; using RabbitMQ.Client; using System; -using HealthChecks.UI.Client; -using Microsoft.AspNetCore.Diagnostics.HealthChecks; -using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Payment.API { @@ -77,7 +77,7 @@ namespace Payment.API return new DefaultRabbitMQPersistentConnection(factory, logger, retryCount); }); - } + } RegisterEventBus(services); @@ -98,31 +98,27 @@ namespace Payment.API app.UsePathBase(pathBase); } + ConfigureEventBus(app); - app.UseHealthChecks("/hc", new HealthCheckOptions() - { - Predicate = _ => true, - ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse - }); - - app.UseHealthChecks("/liveness", new HealthCheckOptions + app.UseRouting(); + app.UseEndpoints(endpoints => { - Predicate = r => r.Name.Contains("self") + endpoints.MapHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); }); - - ConfigureEventBus(app); } private void RegisterAppInsights(IServiceCollection services) { services.AddApplicationInsightsTelemetry(Configuration); - var orchestratorType = Configuration.GetValue("OrchestratorType"); - - if (orchestratorType?.ToUpper() == "K8S") - { - // Enable K8s telemetry initializer - services.AddApplicationInsightsKubernetesEnricher(); - } + services.AddApplicationInsightsKubernetesEnricher(); } private void RegisterEventBus(IServiceCollection services) @@ -136,7 +132,7 @@ namespace Payment.API var serviceBusPersisterConnection = sp.GetRequiredService(); var iLifetimeScope = sp.GetRequiredService(); var logger = sp.GetRequiredService>(); - var eventBusSubcriptionsManager = sp.GetRequiredService(); + var eventBusSubcriptionsManager = sp.GetRequiredService(); return new EventBusServiceBus(serviceBusPersisterConnection, logger, eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope); diff --git a/src/Web/WebMVC/Controllers/AccountController.cs b/src/Web/WebMVC/Controllers/AccountController.cs index f4562b169..de10770f5 100644 --- a/src/Web/WebMVC/Controllers/AccountController.cs +++ b/src/Web/WebMVC/Controllers/AccountController.cs @@ -1,13 +1,12 @@ -using System.Security.Claims; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication.Cookies; +using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Http.Authentication; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Authentication.OpenIdConnect; -using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.Extensions.Logging; using System; +using System.Security.Claims; +using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.WebMVC.Controllers { diff --git a/src/Web/WebMVC/Dockerfile b/src/Web/WebMVC/Dockerfile index 0e3445b57..c32a34295 100644 --- a/src/Web/WebMVC/Dockerfile +++ b/src/Web/WebMVC/Dockerfile @@ -1,8 +1,8 @@ -FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base +FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base WORKDIR /app EXPOSE 80 -FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build +FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build WORKDIR /src COPY scripts scripts/ diff --git a/src/Web/WebMVC/Startup.cs b/src/Web/WebMVC/Startup.cs index 52a311369..e9c0a519f 100644 --- a/src/Web/WebMVC/Startup.cs +++ b/src/Web/WebMVC/Startup.cs @@ -1,9 +1,7 @@ using Devspaces.Support; using HealthChecks.UI.Client; -using Microsoft.ApplicationInsights.Extensibility; -using Microsoft.ApplicationInsights.ServiceFabric; using Microsoft.AspNetCore.Authentication.Cookies; -using Microsoft.AspNetCore.Authentication.OpenIdConnect; +using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Diagnostics.HealthChecks; @@ -56,13 +54,6 @@ namespace Microsoft.eShopOnContainers.WebMVC //loggerFactory.AddAzureWebAppDiagnostics(); //loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); - - app.UseHealthChecks("/hc", new HealthCheckOptions() - { - Predicate = _ => true, - ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse - }); - if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); @@ -80,11 +71,6 @@ namespace Microsoft.eShopOnContainers.WebMVC app.UsePathBase(pathBase); } - app.UseHealthChecks("/liveness", new HealthCheckOptions - { - Predicate = r => r.Name.Contains("self") - }); - app.UseSession(); app.UseStaticFiles(); @@ -98,15 +84,20 @@ namespace Microsoft.eShopOnContainers.WebMVC WebContextSeed.Seed(app, env, loggerFactory); app.UseHttpsRedirection(); - app.UseMvc(routes => + app.UseRouting(); + app.UseEndpoints(endpoints => { - routes.MapRoute( - name: "default", - template: "{controller=Catalog}/{action=Index}/{id?}"); - - routes.MapRoute( - name: "defaultError", - template: "{controller=Error}/{action=Error}"); + endpoints.MapControllerRoute("default", "{controller=Catalog}/{action=Index}/{id?}"); + endpoints.MapControllerRoute("defaultError", "{controller=Error}/{action=Error}"); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + endpoints.MapHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); }); } } @@ -125,13 +116,6 @@ namespace Microsoft.eShopOnContainers.WebMVC services.AddApplicationInsightsKubernetesEnricher(); } - if (orchestratorType?.ToUpper() == "SF") - { - // Enable SF telemetry initializer - services.AddSingleton((serviceProvider) => - new FabricTelemetryInitializer()); - } - return services; } @@ -141,8 +125,8 @@ namespace Microsoft.eShopOnContainers.WebMVC .AddCheck("self", () => HealthCheckResult.Healthy()) .AddUrlGroup(new Uri(configuration["PurchaseUrlHC"]), name: "purchaseapigw-check", tags: new string[] { "purchaseapigw" }) .AddUrlGroup(new Uri(configuration["MarketingUrlHC"]), name: "marketingapigw-check", tags: new string[] { "marketingapigw" }) - .AddUrlGroup(new Uri(configuration["IdentityUrlHC"]), name: "identityapi-check", tags: new string[] { "identityapi" }); - + .AddUrlGroup(new Uri(configuration["IdentityUrlHC"]), name: "identityapi-check", tags: new string[] { "identityapi" }); + return services; } @@ -152,7 +136,7 @@ namespace Microsoft.eShopOnContainers.WebMVC services.Configure(configuration); services.AddMvc() - .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); + .SetCompatibilityVersion(CompatibilityVersion.Version_3_0); services.AddSession(); @@ -245,10 +229,10 @@ namespace Microsoft.eShopOnContainers.WebMVC services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; - options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) - .AddCookie(setup=>setup.ExpireTimeSpan = TimeSpan.FromMinutes(sessionCookieLifetime)) - .AddOpenIdConnect(options => + .AddCookie(setup => setup.ExpireTimeSpan = TimeSpan.FromMinutes(sessionCookieLifetime)) + .AddJwtBearer(options => { options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.Authority = identityUrl.ToString(); @@ -266,7 +250,34 @@ namespace Microsoft.eShopOnContainers.WebMVC options.Scope.Add("marketing"); options.Scope.Add("locations"); options.Scope.Add("webshoppingagg"); - options.Scope.Add("orders.signalrhub"); + options.Scope.Add("orders.signalrhub"); + + /*options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; + options.Authority = identityUrl.ToString(); + options.SignedOutRedirectUri = callBackUrl.ToString(); + options.ClientId = useLoadTest ? "mvctest" : "mvc"; + options.ClientSecret = "secret"; + + if (useLoadTest) + { + options.Configuration.ResponseTypesSupported.Add("code id_token token"); + } + else + { + options.Configuration.ResponseTypesSupported.Add("code id_token"); + } + + options.SaveToken = true; + options.GetClaimsFromUserInfoEndpoint = true; + options.RequireHttpsMetadata = false; + options.Configuration.ScopesSupported.Add("openid"); + options.Configuration.ScopesSupported.Add("profile"); + options.Configuration.ScopesSupported.Add("orders"); + options.Configuration.ScopesSupported.Add("basket"); + options.Configuration.ScopesSupported.Add("marketing"); + options.Configuration.ScopesSupported.Add("locations"); + options.Configuration.ScopesSupported.Add("webshoppingagg"); + options.Configuration.ScopesSupported.Add("orders.signalrhub");*/ }); return services; diff --git a/src/Web/WebMVC/WebMVC.csproj b/src/Web/WebMVC/WebMVC.csproj index 42f8f16dd..adfc5587e 100644 --- a/src/Web/WebMVC/WebMVC.csproj +++ b/src/Web/WebMVC/WebMVC.csproj @@ -5,6 +5,8 @@ aspnet-Microsoft.eShopOnContainers-946ae052-8305-4a99-965b-ec8636ddbae3 ..\..\..\docker-compose.dcproj 3.0 + false + 8.0 @@ -22,25 +24,25 @@ - + - - - - - + + + + + diff --git a/src/Web/WebSPA/Dockerfile b/src/Web/WebSPA/Dockerfile index d7cb7631c..14617aaa7 100644 --- a/src/Web/WebSPA/Dockerfile +++ b/src/Web/WebSPA/Dockerfile @@ -1,5 +1,5 @@ ARG NODE_IMAGE=node:8.11 -FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base +FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base WORKDIR /app EXPOSE 80 @@ -9,7 +9,7 @@ COPY src/Web/WebSPA . RUN npm install RUN npm run build:prod -FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build +FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build WORKDIR /src COPY scripts scripts/ diff --git a/src/Web/WebSPA/Startup.cs b/src/Web/WebSPA/Startup.cs index 0c1f37b3f..50e4dbef2 100644 --- a/src/Web/WebSPA/Startup.cs +++ b/src/Web/WebSPA/Startup.cs @@ -1,22 +1,19 @@ using eShopOnContainers.WebSPA; -using Microsoft.ApplicationInsights.Extensibility; -using Microsoft.ApplicationInsights.ServiceFabric; +using HealthChecks.UI.Client; using Microsoft.AspNetCore.Antiforgery; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; -using Newtonsoft.Json.Serialization; using StackExchange.Redis; using System; using System.IO; using WebSPA.Infrastructure; -using HealthChecks.UI.Client; -using Microsoft.AspNetCore.Diagnostics.HealthChecks; -using Microsoft.Extensions.Diagnostics.HealthChecks; namespace eShopConContainers.WebSPA { @@ -30,6 +27,7 @@ namespace eShopConContainers.WebSPA public IConfiguration Configuration { get; } private IHostingEnvironment _hostingEnv; + public Startup(IHostingEnvironment env) { _hostingEnv = env; @@ -48,7 +46,7 @@ namespace eShopConContainers.WebSPA .AddCheck("self", () => HealthCheckResult.Healthy()) .AddUrlGroup(new Uri(Configuration["PurchaseUrlHC"]), name: "purchaseapigw-check", tags: new string[] { "purchaseapigw" }) .AddUrlGroup(new Uri(Configuration["MarketingUrlHC"]), name: "marketingapigw-check", tags: new string[] { "marketingapigw" }) - .AddUrlGroup(new Uri(Configuration["IdentityUrlHC"]), name: "identityapi-check", tags: new string[] { "identityapi" }); + .AddUrlGroup(new Uri(Configuration["IdentityUrlHC"]), name: "identityapi-check", tags: new string[] { "identityapi" }); services.Configure(Configuration); @@ -67,7 +65,7 @@ namespace eShopConContainers.WebSPA .SetCompatibilityVersion(CompatibilityVersion.Version_3_0) .AddJsonOptions(options => { - options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + options.JsonSerializerOptions.PropertyNameCaseInsensitive = true; }); } @@ -86,18 +84,6 @@ namespace eShopConContainers.WebSPA // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } - - app.UseHealthChecks("/liveness", new HealthCheckOptions - { - Predicate = r => r.Name.Contains("self") - }); - - app.UseHealthChecks("/hc", new HealthCheckOptions() - { - Predicate = _ => true, - ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse - }); - // Configure XSRF middleware, This pattern is for SPA style applications where XSRF token is added on Index page // load and passed back token on every subsequent async request // app.Use(async (context, next) => @@ -128,34 +114,34 @@ namespace eShopConContainers.WebSPA // Rewrite request to use app root if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value) && !context.Request.Path.Value.StartsWith("/api")) { - context.Request.Path = "/index.html"; + context.Request.Path = "/index.html"; context.Response.StatusCode = 200; // Make sure we update the status code, otherwise it returns 404 await next(); } }); - + app.UseDefaultFiles(); app.UseStaticFiles(); - - app.UseMvcWithDefaultRoute(); + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapDefaultControllerRoute(); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + endpoints.MapHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + }); } private void RegisterAppInsights(IServiceCollection services) { services.AddApplicationInsightsTelemetry(Configuration); - var orchestratorType = Configuration.GetValue("OrchestratorType"); - - if (orchestratorType?.ToUpper() == "K8S") - { - // Enable K8s telemetry initializer - services.AddApplicationInsightsKubernetesEnricher(); - } - if (orchestratorType?.ToUpper() == "SF") - { - // Enable SF telemetry initializer - services.AddSingleton((serviceProvider) => - new FabricTelemetryInitializer()); - } + services.AddApplicationInsightsKubernetesEnricher(); } } } diff --git a/src/Web/WebSPA/WebSPA.csproj b/src/Web/WebSPA/WebSPA.csproj index 365b3205a..c2682716f 100644 --- a/src/Web/WebSPA/WebSPA.csproj +++ b/src/Web/WebSPA/WebSPA.csproj @@ -9,6 +9,7 @@ wwwroot/dist/** $(DefaultItemExcludes);$(GeneratedItemPatterns) 2.9 + 8.0 @@ -90,10 +91,9 @@ - - + diff --git a/src/Web/WebSPA/package.json b/src/Web/WebSPA/package.json index 41d25c640..ae4209a14 100644 --- a/src/Web/WebSPA/package.json +++ b/src/Web/WebSPA/package.json @@ -37,7 +37,7 @@ "@angular/platform-browser-dynamic": "^7.2.10", "@angular/platform-server": "^7.2.10", "@angular/router": "^7.2.10", - "@aspnet/signalr": "1.0.3", + "@aspnet/signalr": "3.0.0-preview6.19307.2", "@ng-bootstrap/ng-bootstrap": "3.3.0", "bootstrap": "4.3.1", "core-js": "^2.5.0", diff --git a/src/Web/WebStatus/Startup.cs b/src/Web/WebStatus/Startup.cs index 48875eab5..17f42de5c 100644 --- a/src/Web/WebStatus/Startup.cs +++ b/src/Web/WebStatus/Startup.cs @@ -56,11 +56,6 @@ namespace WebStatus app.UsePathBase(pathBase); } - app.UseHealthChecks("/liveness", new HealthCheckOptions - { - Predicate = r => r.Name.Contains("self") - }); - app.UseHealthChecksUI(config => { config.ResourcesPath = string.IsNullOrEmpty(pathBase) ? "/ui/resources" : $"{pathBase}/ui/resources"; @@ -74,19 +69,17 @@ namespace WebStatus app.UseEndpoints(endpoints => { endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); }); } private void RegisterAppInsights(IServiceCollection services) { services.AddApplicationInsightsTelemetry(Configuration); - var orchestratorType = Configuration.GetValue("OrchestratorType"); - - if (orchestratorType?.ToUpper() == "K8S") - { - // Enable K8s telemetry initializer - services.AddApplicationInsightsKubernetesEnricher(); - } + services.AddApplicationInsightsKubernetesEnricher(); } } } diff --git a/src/Web/WebStatus/WebStatus.csproj b/src/Web/WebStatus/WebStatus.csproj index 9364cd5e2..43462a55e 100644 --- a/src/Web/WebStatus/WebStatus.csproj +++ b/src/Web/WebStatus/WebStatus.csproj @@ -3,6 +3,7 @@ $(NetCoreTargetVersion) $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; ..\..\..\docker-compose.dcproj + 8.0 @@ -14,7 +15,7 @@ - + diff --git a/src/Web/WebhookClient/Controllers/AccountController.cs b/src/Web/WebhookClient/Controllers/AccountController.cs index 26fc4074e..461e3261d 100644 --- a/src/Web/WebhookClient/Controllers/AccountController.cs +++ b/src/Web/WebhookClient/Controllers/AccountController.cs @@ -3,9 +3,6 @@ using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; using System.Security.Claims; using System.Threading.Tasks; diff --git a/src/Web/WebhookClient/Dockerfile b/src/Web/WebhookClient/Dockerfile index 9143fd8e1..b756936f7 100644 --- a/src/Web/WebhookClient/Dockerfile +++ b/src/Web/WebhookClient/Dockerfile @@ -1,9 +1,9 @@ -FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base +FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base WORKDIR /app EXPOSE 80 EXPOSE 443 -FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build +FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build WORKDIR /src COPY scripts scripts/ diff --git a/src/Web/WebhookClient/WebhookClient.csproj b/src/Web/WebhookClient/WebhookClient.csproj index 95ec6e8fb..3e4eb8ed3 100644 --- a/src/Web/WebhookClient/WebhookClient.csproj +++ b/src/Web/WebhookClient/WebhookClient.csproj @@ -1,17 +1,20 @@ - + $(NetCoreTargetVersion) InProcess Linux 36215d41-f31a-4aa6-9929-bd67d650e7b5 + 8.0 - - - + + + + + diff --git a/src/_build/dependencies.props b/src/_build/dependencies.props index 809b3e08c..7914c41c7 100644 --- a/src/_build/dependencies.props +++ b/src/_build/dependencies.props @@ -32,10 +32,19 @@ 4.9.2 4.2.1 1.50.7 - 4.3.0 + 3.0.0-alpha1-10670 + 1.0.2105168 + 3.0.0-preview6-19319-03 + 3.0.0-preview6-19253-01 + 4.3.0 4.5.1 4.5.0 5.1.0 + 2.6.375 + 2.2.0-preview2-35157 + 5.2.7 + 15.9.20 + 1.0.172 3.0.0-alpha1-34847 5.1.0 2.2.1