diff --git a/.github/workflows/deploy-self-hosted.yml b/.github/workflows/deploy-self-hosted.yml index 706ba052..d20aa017 100644 --- a/.github/workflows/deploy-self-hosted.yml +++ b/.github/workflows/deploy-self-hosted.yml @@ -12,19 +12,19 @@ jobs: runs-on: ubuntu-latest environment: name: 'self-hosted-backend' - url: 'https://vps-sitenexusmods.aragas.org' + url: 'https://vps2-sitenexusmods.aragas.org' steps: - name: multiple command uses: appleboy/ssh-action@master with: #host: ${{ secrets.HOST }} - host: ${{ secrets.HOST_2 }} + host: ${{ secrets.HOST_3 }} #username: ${{ secrets.USERNAME }} - username: ${{ secrets.USERNAME_2 }} + username: ${{ secrets.USERNAME_3 }} #password: ${{ secrets.PASSWORD }} - password: ${{ secrets.PASSWORD_2 }} + password: ${{ secrets.PASSWORD_3 }} #port: ${{ secrets.PORT }} - port: ${{ secrets.PORT_2 }} + port: ${{ secrets.PORT_3 }} script: | docker image pull ghcr.io/butr/sitenexusmods2; docker stack deploy --prune --resolve-image always -c /deploy/sitenexusmods2/docker-compose.yml sitenexusmods2; diff --git a/src/BUTR.Site.NexusMods.Client/wwwroot/appsettings.json b/src/BUTR.Site.NexusMods.Client/wwwroot/appsettings.json index 56459607..1ce78df5 100644 --- a/src/BUTR.Site.NexusMods.Client/wwwroot/appsettings.json +++ b/src/BUTR.Site.NexusMods.Client/wwwroot/appsettings.json @@ -1,5 +1,5 @@ { "Backend": { - "Endpoint": "https://vps-sitenexusmods.aragas.org/" + "Endpoint": "https://vps2-sitenexusmods.aragas.org/" } } diff --git a/src/BUTR.Site.NexusMods.Server/BUTR.Site.NexusMods.Server.csproj b/src/BUTR.Site.NexusMods.Server/BUTR.Site.NexusMods.Server.csproj index bb0f03f0..99c37fe2 100644 --- a/src/BUTR.Site.NexusMods.Server/BUTR.Site.NexusMods.Server.csproj +++ b/src/BUTR.Site.NexusMods.Server/BUTR.Site.NexusMods.Server.csproj @@ -32,7 +32,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - @@ -53,6 +52,11 @@ + + + + + diff --git a/src/BUTR.Site.NexusMods.Server/Program.cs b/src/BUTR.Site.NexusMods.Server/Program.cs index 37eb0578..28079b93 100644 --- a/src/BUTR.Site.NexusMods.Server/Program.cs +++ b/src/BUTR.Site.NexusMods.Server/Program.cs @@ -6,12 +6,10 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; using Npgsql; using OpenTelemetry.Exporter; -using OpenTelemetry.Logs; using OpenTelemetry.Metrics; using OpenTelemetry.ResourceDetectors.Container; using OpenTelemetry.Resources; @@ -19,6 +17,9 @@ using Quartz; +using Serilog; +using Serilog.Events; + using System; using System.Threading.Tasks; @@ -35,22 +36,41 @@ private static void PreBulkSaveChanges(DbContext context) public static async Task Main(string[] args) { - Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkInsert = PreBulkOperation; - Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkDelete = PreBulkOperation; - Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkMerge = PreBulkOperation; - Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkUpdate = PreBulkOperation; - Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkSynchronize = PreBulkOperation; - Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkSaveChanges = PreBulkSaveChanges; - Z.EntityFramework.Extensions.EntityFrameworkManager.ContextFactory = context => context switch + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Override("Microsoft", LogEventLevel.Information) + .Enrich.FromLogContext() + .WriteTo.Console() + .CreateBootstrapLogger(); + + try { - AppDbContextRead appDbContextRead => appDbContextRead.New(), - AppDbContextWrite appDbContextWrite => appDbContextWrite.New(), - _ => null - }; + Log.Information("Starting web application"); + + Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkInsert = PreBulkOperation; + Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkDelete = PreBulkOperation; + Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkMerge = PreBulkOperation; + Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkUpdate = PreBulkOperation; + Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkSynchronize = PreBulkOperation; + Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkSaveChanges = PreBulkSaveChanges; + Z.EntityFramework.Extensions.EntityFrameworkManager.ContextFactory = context => context switch + { + AppDbContextRead appDbContextRead => appDbContextRead.New(), + AppDbContextWrite appDbContextWrite => appDbContextWrite.New(), + _ => null + }; - var host = CreateHostBuilder(args).Build(); + var host = CreateHostBuilder(args).Build(); - await host.SeedDbContext().RunAsync(); + await host.SeedDbContext().RunAsync(); + } + catch (Exception ex) + { + Log.Fatal(ex, "Application terminated unexpectedly"); + } + finally + { + await Log.CloseAndFlushAsync(); + } } public static IHostBuilder CreateHostBuilder(string[] args) => Host @@ -139,25 +159,10 @@ public static IHostBuilder CreateHostBuilder(string[] args) => Host { webBuilder.UseStartup(); }) - .ConfigureLogging((ctx, builder) => + .UseSerilog((context, services, configuration) => { - var oltpSection = ctx.Configuration.GetSection("Oltp"); - if (oltpSection == null!) return; - - var loggingEndpoint = oltpSection.GetValue("LoggingEndpoint"); - if (loggingEndpoint is null) return; - var loggingProtocol = oltpSection.GetValue("LoggingProtocol"); - - builder.AddOpenTelemetry(o => - { - o.IncludeScopes = true; - o.ParseStateValues = true; - o.IncludeFormattedMessage = true; - o.AddOtlpExporter((options, processorOptions) => - { - options.Endpoint = new Uri(loggingEndpoint); - options.Protocol = loggingProtocol; - }); - }); + configuration + .ReadFrom.Configuration(context.Configuration) + .ReadFrom.Services(services); }); } \ No newline at end of file diff --git a/src/BUTR.Site.NexusMods.Server/appsettings.json b/src/BUTR.Site.NexusMods.Server/appsettings.json index c5390457..d5fd411a 100644 --- a/src/BUTR.Site.NexusMods.Server/appsettings.json +++ b/src/BUTR.Site.NexusMods.Server/appsettings.json @@ -1,4 +1,20 @@ { + "Serilog": { + "Enrich": [ + "FromLogContext" + ], + "WriteTo": [ + { + "Name": "Async", + "Args": { + "configure": [ + { "Name": "Console" } + ] + } + } + ] + }, + "Logging": { "LogLevel": { "Default": "Information", @@ -8,12 +24,12 @@ }, "CrashReporter": { - "Endpoint": "https://report.butr.link/", + "Endpoint": "https://report.butr.link/" }, "NexusMods": { "Endpoint": "https://nexusmods.com/", - "APIEndpoint": "https://api.nexusmods.com/", + "APIEndpoint": "https://api.nexusmods.com/" }, "DepotDownloader": {