diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..5e06b9d6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0 as build +WORKDIR /source +COPY . . +RUN dotnet restore src/iRLeagueApiCore.Server -r linux-x64 +RUN dotnet publish src/iRLeagueApiCore.Server -r linux-x64 -o /app --no-restore + +FROM mcr.microsoft.com/dotnet/aspnet:8.0-noble-chiseled-extra +WORKDIR /app +COPY --link --from=build /app . +USER $APP_UID +ENTRYPOINT ["./iRLeagueApiCore.Server"] \ No newline at end of file diff --git a/iRLeagueApiCore.sln b/iRLeagueApiCore.sln index 926619f2..385cb1bb 100644 --- a/iRLeagueApiCore.sln +++ b/iRLeagueApiCore.sln @@ -10,6 +10,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7F90E099-56DE-4FEF-8CA2-4F4610CDEF19}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig + Dockerfile = Dockerfile .github\workflows\dotnet_develop.yml = .github\workflows\dotnet_develop.yml .github\workflows\dotnet_main_pr.yml = .github\workflows\dotnet_main_pr.yml .github\workflows\dotnet_main_push.yml = .github\workflows\dotnet_main_push.yml @@ -30,8 +31,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "iRLeagueApiCore.Common", "s EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "iRLeagueDatabaseCore", "src\iRLeagueDatabaseCore\iRLeagueDatabaseCore.csproj", "{374D9358-C654-4882-AE9F-89DDB135A69D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "iRLeagueDatabaseCore.Migrations", "src\iRLeagueDatabaseCore.Migrations\iRLeagueDatabaseCore.Migrations.csproj", "{C335B0B3-B0AE-45EF-B620-87E9EBE257D3}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbIntegrationTests", "test\DbIntegrationTests\DbIntegrationTests.csproj", "{CBE19DF1-F112-4BCB-9DC4-BE33D971CCCC}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "test\UnitTests\UnitTests.csproj", "{FB4E0FC3-97A9-4456-93DB-F8335175FA47}" @@ -78,10 +77,6 @@ Global {374D9358-C654-4882-AE9F-89DDB135A69D}.Debug|Any CPU.Build.0 = Debug|Any CPU {374D9358-C654-4882-AE9F-89DDB135A69D}.Release|Any CPU.ActiveCfg = Release|Any CPU {374D9358-C654-4882-AE9F-89DDB135A69D}.Release|Any CPU.Build.0 = Release|Any CPU - {C335B0B3-B0AE-45EF-B620-87E9EBE257D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C335B0B3-B0AE-45EF-B620-87E9EBE257D3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C335B0B3-B0AE-45EF-B620-87E9EBE257D3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C335B0B3-B0AE-45EF-B620-87E9EBE257D3}.Release|Any CPU.Build.0 = Release|Any CPU {CBE19DF1-F112-4BCB-9DC4-BE33D971CCCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CBE19DF1-F112-4BCB-9DC4-BE33D971CCCC}.Debug|Any CPU.Build.0 = Debug|Any CPU {CBE19DF1-F112-4BCB-9DC4-BE33D971CCCC}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/src/iRLeagueApiCore.Client/iRLeagueApiCore.Client.csproj b/src/iRLeagueApiCore.Client/iRLeagueApiCore.Client.csproj index 41ab0439..5c032f2d 100644 --- a/src/iRLeagueApiCore.Client/iRLeagueApiCore.Client.csproj +++ b/src/iRLeagueApiCore.Client/iRLeagueApiCore.Client.csproj @@ -13,7 +13,7 @@ Library net8.0 iRLeagueApiCore.Client - 0.14.7 + 0.15.0 Simon Schulze Simon Schulze This package contains shared objects for all members of the iRLeagueDatabase-iRLeagueApi stack diff --git a/src/iRLeagueApiCore.Common/iRLeagueApiCore.Common.csproj b/src/iRLeagueApiCore.Common/iRLeagueApiCore.Common.csproj index 31a4f303..d860dfe2 100644 --- a/src/iRLeagueApiCore.Common/iRLeagueApiCore.Common.csproj +++ b/src/iRLeagueApiCore.Common/iRLeagueApiCore.Common.csproj @@ -18,7 +18,7 @@ Library net8.0 iRLeagueApiCore.Common - 0.14.7 + 0.15.0 Simon Schulze Simon Schulze enable diff --git a/src/iRLeagueApiCore.Server/Authentication/UserDbContext.cs b/src/iRLeagueApiCore.Server/Authentication/UserDbContext.cs index 9a509430..02fc0db8 100644 --- a/src/iRLeagueApiCore.Server/Authentication/UserDbContext.cs +++ b/src/iRLeagueApiCore.Server/Authentication/UserDbContext.cs @@ -9,6 +9,7 @@ public UserDbContext(DbContextOptions options) : base(options) { } + protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); diff --git a/src/iRLeagueApiCore.Server/Authentication/UserDbContextFactory.cs b/src/iRLeagueApiCore.Server/Authentication/UserDbContextFactory.cs index 703b9227..a12d691d 100644 --- a/src/iRLeagueApiCore.Server/Authentication/UserDbContextFactory.cs +++ b/src/iRLeagueApiCore.Server/Authentication/UserDbContextFactory.cs @@ -4,21 +4,21 @@ namespace iRLeagueApiCore.Server.Authentication; public sealed class UserDbContextFactory : IDbContextFactory { - private readonly IConfiguration _configuration; + private readonly DbContextOptions contextOptions; public UserDbContextFactory(IConfiguration configuration) { - _configuration = configuration; - } - - public UserDbContext CreateDbContext() - { - var dbConnectionString = _configuration.GetConnectionString("UserDb") ?? + // load the database configurations once at start - reloading is not enabled + var dbConnectionString = configuration.GetConnectionString("UserDb") ?? throw new InvalidConfigurationException("No connection string for 'UserDB' found in configuration"); var optionsBuilder = new DbContextOptionsBuilder(); optionsBuilder.UseMySQL(dbConnectionString); + contextOptions = optionsBuilder.Options; + } - var dbContext = new UserDbContext(optionsBuilder.Options); + public UserDbContext CreateDbContext() + { + var dbContext = new UserDbContext(contextOptions); dbContext.Database.EnsureCreated(); return dbContext; } diff --git a/src/iRLeagueApiCore.Server/Models/LeagueDbContextFactory.cs b/src/iRLeagueApiCore.Server/Models/LeagueDbContextFactory.cs index b45c0cdb..e30ea238 100644 --- a/src/iRLeagueApiCore.Server/Models/LeagueDbContextFactory.cs +++ b/src/iRLeagueApiCore.Server/Models/LeagueDbContextFactory.cs @@ -5,21 +5,29 @@ namespace iRLeagueApiCore.Server.Models; public sealed class LeagueDbContextFactory { - private readonly IConfiguration _configuration; + private readonly bool applyMigrations = false; + private readonly DbContextOptions contextOptions; + public LeagueDbContextFactory(IConfiguration configuration) { - _configuration = configuration; - } + applyMigrations = configuration.GetValue("ApplyDatabaseMigrations") == true; - public LeagueDbContext CreateDbContext(ILeagueProvider leagueProvider) - { - var dbConnectionString = _configuration.GetConnectionString("ModelDb") ?? + // load the database configurations once at start - reloading is not enabled + var dbConnectionString = configuration.GetConnectionString("ModelDb") ?? throw new InvalidConfigurationException("No connection string for 'ModelDb' found in configuration"); var optionsBuilder = new DbContextOptionsBuilder(); optionsBuilder.UseMySQL(dbConnectionString); + contextOptions = optionsBuilder.Options; + } - var dbContext = new LeagueDbContext(optionsBuilder.Options, leagueProvider); + public LeagueDbContext CreateDbContext(ILeagueProvider leagueProvider) + { + var dbContext = new LeagueDbContext(contextOptions, leagueProvider); + if (applyMigrations) + { + dbContext.Database.Migrate(); + } return dbContext; } } diff --git a/src/iRLeagueApiCore.Server/Startup.cs b/src/iRLeagueApiCore.Server/Startup.cs index e1f935e5..70298390 100644 --- a/src/iRLeagueApiCore.Server/Startup.cs +++ b/src/iRLeagueApiCore.Server/Startup.cs @@ -197,7 +197,6 @@ public void ConfigureServices(IServiceCollection services) // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger logger) { - app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto diff --git a/src/iRLeagueApiCore.Server/iRLeagueApiCore.Server.csproj b/src/iRLeagueApiCore.Server/iRLeagueApiCore.Server.csproj index aadd4549..2fa3cbae 100644 --- a/src/iRLeagueApiCore.Server/iRLeagueApiCore.Server.csproj +++ b/src/iRLeagueApiCore.Server/iRLeagueApiCore.Server.csproj @@ -78,7 +78,7 @@ true - 0.14.7 + 0.15.0 enable diff --git a/src/iRLeagueDatabaseCore/MigrationLeagueDbContextFactory.cs b/src/iRLeagueDatabaseCore/MigrationLeagueDbContextFactory.cs index e22cc559..ddbdc73d 100644 --- a/src/iRLeagueDatabaseCore/MigrationLeagueDbContextFactory.cs +++ b/src/iRLeagueDatabaseCore/MigrationLeagueDbContextFactory.cs @@ -8,10 +8,16 @@ internal class MigrationLeagueDbContextFactory : IDesignTimeDbContextFactory(); - optionsBuilder.UseMySQL(connectionString); + if (string.IsNullOrEmpty(connectionString)) + { + optionsBuilder.UseMySQL(); + } + else + { + optionsBuilder.UseMySQL(connectionString); + } var leagueProvider = Mock.Of(); var dbContext = new LeagueDbContext(optionsBuilder.Options, leagueProvider); diff --git a/src/iRLeagueDatabaseCore/iRLeagueDatabaseCore.csproj b/src/iRLeagueDatabaseCore/iRLeagueDatabaseCore.csproj index 375f8a7a..af84fb59 100644 --- a/src/iRLeagueDatabaseCore/iRLeagueDatabaseCore.csproj +++ b/src/iRLeagueDatabaseCore/iRLeagueDatabaseCore.csproj @@ -35,7 +35,7 @@ net8.0 12 iRLeagueDatabaseCore - 0.14.7 + 0.15.0 enable