diff --git a/src/Services/Webhooks/Webhooks.API/Program.cs b/src/Services/Webhooks/Webhooks.API/Program.cs index b08a1c2da..b7ed97115 100644 --- a/src/Services/Webhooks/Webhooks.API/Program.cs +++ b/src/Services/Webhooks/Webhooks.API/Program.cs @@ -7,20 +7,15 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Webhooks.API; using Webhooks.API.Infrastructure; -namespace Webhooks.API -{ - public class Program - { - public static void Main(string[] args) - { - CreateWebHostBuilder(args).Build() - .MigrateDbContext((_,__) => { }) - .Run(); - } +CreateWebHostBuilder(args).Build() + .MigrateDbContext((_, __) => { }) + .Run(); - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + +IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup() .ConfigureAppConfiguration((builderContext, config) => @@ -33,6 +28,4 @@ namespace Webhooks.API builder.AddConsole(); builder.AddDebug(); builder.AddAzureWebAppDiagnostics(); - }); - } -} + }); \ No newline at end of file diff --git a/src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj b/src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj index 6624001c4..432aec4f0 100644 --- a/src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj +++ b/src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net5.0 InProcess Linux $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; diff --git a/src/Web/WebMVC/WebMVC.csproj b/src/Web/WebMVC/WebMVC.csproj index 1510eb0c9..29a619cf4 100644 --- a/src/Web/WebMVC/WebMVC.csproj +++ b/src/Web/WebMVC/WebMVC.csproj @@ -23,25 +23,25 @@ - - - - - - + + + + + + - - - - + + + + - + diff --git a/src/Web/WebSPA/Dockerfile b/src/Web/WebSPA/Dockerfile index 6ab6adb97..050528c93 100644 --- a/src/Web/WebSPA/Dockerfile +++ b/src/Web/WebSPA/Dockerfile @@ -1,5 +1,5 @@ ARG NODE_IMAGE=node:12.0 -FROM mcr.microsoft.com/dotnet/core/aspnet:5.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base WORKDIR /app EXPOSE 80 @@ -10,7 +10,7 @@ COPY Web/WebSPA/package-lock.json . COPY Web/WebSPA . RUN npm i npm@latest -g && npm update && npm install && npm run build:prod -FROM mcr.microsoft.com/dotnet/core/5.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build WORKDIR /src # It's important to keep lines from here down to "COPY . ." identical in all Dockerfiles diff --git a/src/Web/WebSPA/WebSPA.csproj b/src/Web/WebSPA/WebSPA.csproj index 2e09b7c4f..3ef697dbb 100644 --- a/src/Web/WebSPA/WebSPA.csproj +++ b/src/Web/WebSPA/WebSPA.csproj @@ -87,16 +87,16 @@ - - - - - + + + + + - + - + diff --git a/src/Web/WebStatus/Program.cs b/src/Web/WebStatus/Program.cs index cf648daa9..057caed52 100644 --- a/src/Web/WebStatus/Program.cs +++ b/src/Web/WebStatus/Program.cs @@ -7,119 +7,114 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; +using WebStatus; -namespace WebStatus +var configuration = GetConfiguration(); + +Log.Logger = CreateSerilogLogger(configuration); + +try { - public class Program - { - public static readonly string Namespace = typeof(Program).Namespace; - public static readonly string AppName = Namespace; + Log.Information("Configuring web host ({ApplicationContext})...", Program.AppName); + var host = BuildWebHost(configuration, args); - public static int Main(string[] args) - { - var configuration = GetConfiguration(); - - Log.Logger = CreateSerilogLogger(configuration); - - try - { - Log.Information("Configuring web host ({ApplicationContext})...", AppName); - var host = BuildWebHost(configuration, args); - - LogPackagesVersionInfo(); - - Log.Information("Starting web host ({ApplicationContext})...", AppName); - host.Run(); - - return 0; - } - catch (Exception ex) - { - Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", AppName); - return 1; - } - finally - { - Log.CloseAndFlush(); - } - } + LogPackagesVersionInfo(); - private static IWebHost BuildWebHost(IConfiguration configuration, string[] args) => - WebHost.CreateDefaultBuilder(args) - .CaptureStartupErrors(false) - .ConfigureAppConfiguration(x => x.AddConfiguration(configuration)) - .UseStartup() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseSerilog() - .Build(); + Log.Information("Starting web host ({ApplicationContext})...", Program.AppName); + host.Run(); - private static Serilog.ILogger CreateSerilogLogger(IConfiguration configuration) - { - var seqServerUrl = configuration["Serilog:SeqServerUrl"]; - var logstashUrl = configuration["Serilog:LogstashgUrl"]; - return new LoggerConfiguration() - .MinimumLevel.Verbose() - .Enrich.WithProperty("ApplicationContext", AppName) - .Enrich.FromLogContext() - .WriteTo.Console() - .WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl) - .WriteTo.Http(string.IsNullOrWhiteSpace(logstashUrl) ? "http://logstash:8080" : logstashUrl) - .ReadFrom.Configuration(configuration) - .CreateLogger(); - } + return 0; +} +catch (Exception ex) +{ + Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", Program.AppName); + return 1; +} +finally +{ + Log.CloseAndFlush(); +} + +IWebHost BuildWebHost(IConfiguration configuration, string[] args) => + WebHost.CreateDefaultBuilder(args) + .CaptureStartupErrors(false) + .ConfigureAppConfiguration(x => x.AddConfiguration(configuration)) + .UseStartup() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseSerilog() + .Build(); + +Serilog.ILogger CreateSerilogLogger(IConfiguration configuration) +{ + var seqServerUrl = configuration["Serilog:SeqServerUrl"]; + var logstashUrl = configuration["Serilog:LogstashgUrl"]; + return new LoggerConfiguration() + .MinimumLevel.Verbose() + .Enrich.WithProperty("ApplicationContext", Program.AppName) + .Enrich.FromLogContext() + .WriteTo.Console() + .WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl) + .WriteTo.Http(string.IsNullOrWhiteSpace(logstashUrl) ? "http://logstash:8080" : logstashUrl) + .ReadFrom.Configuration(configuration) + .CreateLogger(); +} + +IConfiguration GetConfiguration() +{ + var builder = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddEnvironmentVariables(); - private static IConfiguration GetConfiguration() - { - var builder = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) - .AddEnvironmentVariables(); - - var config = builder.Build(); - - if (config.GetValue("UseVault", false)) - { - builder.AddAzureKeyVault( - $"https://{config["Vault:Name"]}.vault.azure.net/", - config["Vault:ClientId"], - config["Vault:ClientSecret"]); - } - - return builder.Build(); - } + var config = builder.Build(); + + if (config.GetValue("UseVault", false)) + { + builder.AddAzureKeyVault( + $"https://{config["Vault:Name"]}.vault.azure.net/", + config["Vault:ClientId"], + config["Vault:ClientSecret"]); + } - private static string GetVersion(Assembly assembly) + return builder.Build(); +} + +string GetVersion(Assembly assembly) +{ + try + { + return $"{assembly.GetCustomAttribute()?.Version} ({assembly.GetCustomAttribute()?.InformationalVersion.Split()[0]})"; + } + catch + { + return string.Empty; + } +} + +void LogPackagesVersionInfo() +{ + var assemblies = new List(); + + foreach (var dependencyName in typeof(Program).Assembly.GetReferencedAssemblies()) + { + try { - try - { - return $"{assembly.GetCustomAttribute()?.Version} ({assembly.GetCustomAttribute()?.InformationalVersion.Split()[0]})"; - } - catch - { - return string.Empty; - } + // Try to load the referenced assembly... + assemblies.Add(Assembly.Load(dependencyName)); } - - private static void LogPackagesVersionInfo() + catch { - var assemblies = new List(); - - foreach (var dependencyName in typeof(Program).Assembly.GetReferencedAssemblies()) - { - try - { - // Try to load the referenced assembly... - assemblies.Add(Assembly.Load(dependencyName)); - } - catch - { - // Failed to load assembly. Skip it. - } - } - - var versionList = assemblies.Select(a => $"-{a.GetName().Name} - {GetVersion(a)}").OrderBy(value => value); - - Log.Logger.ForContext("PackageVersions", string.Join("\n", versionList)).Information("Package versions ({ApplicationContext})", AppName); + // Failed to load assembly. Skip it. } } + + var versionList = assemblies.Select(a => $"-{a.GetName().Name} - {GetVersion(a)}").OrderBy(value => value); + + Log.Logger.ForContext("PackageVersions", string.Join("\n", versionList)).Information("Package versions ({ApplicationContext})", Program.AppName); +} + +public class Program +{ + private static readonly string _namespace = typeof(Startup).Namespace; + public static readonly string AppName = _namespace.Substring(_namespace.LastIndexOf('.', _namespace.LastIndexOf('.') - 1) + 1); } \ No newline at end of file diff --git a/src/Web/WebStatus/WebStatus.csproj b/src/Web/WebStatus/WebStatus.csproj index ecdf92b15..790e5c06b 100644 --- a/src/Web/WebStatus/WebStatus.csproj +++ b/src/Web/WebStatus/WebStatus.csproj @@ -1,6 +1,6 @@  - netcoreapp3.1 + net5.0 $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; ..\..\..\docker-compose.dcproj true @@ -8,21 +8,21 @@ - - - - - - + + + + + + - - - - + + + + - + diff --git a/src/Web/WebhookClient/WebhookClient.csproj b/src/Web/WebhookClient/WebhookClient.csproj index 85b3d617e..866f2910a 100644 --- a/src/Web/WebhookClient/WebhookClient.csproj +++ b/src/Web/WebhookClient/WebhookClient.csproj @@ -14,8 +14,8 @@ - - + +