Fix docker environment issues (#694)

This commit is contained in:
Cédric Michel
2022-04-06 14:28:57 +02:00
committed by GitHub
parent a87f571ff2
commit 07d7275860
13 changed files with 96 additions and 87 deletions

View File

@@ -98,6 +98,27 @@ var app = builder.Build();
app.Logger.LogInformation("App created...");
app.Logger.LogInformation("Seeding Database...");
using (var scope = app.Services.CreateScope())
{
var scopedProvider = scope.ServiceProvider;
try
{
var catalogContext = scopedProvider.GetRequiredService<CatalogContext>();
await CatalogContextSeed.SeedAsync(catalogContext, app.Logger);
var userManager = scopedProvider.GetRequiredService<UserManager<ApplicationUser>>();
var roleManager = scopedProvider.GetRequiredService<RoleManager<IdentityRole>>();
var identityContext = scopedProvider.GetRequiredService<AppIdentityDbContext>();
await AppIdentityDbContextSeed.SeedAsync(identityContext, userManager, roleManager);
}
catch (Exception ex)
{
app.Logger.LogError(ex, "An error occurred seeding the DB.");
}
}
var catalogBaseUrl = builder.Configuration.GetValue(typeof(string), "CatalogBaseUrl") as string;
if (!string.IsNullOrEmpty(catalogBaseUrl))
{
@@ -126,7 +147,7 @@ app.UseHealthChecks("/health",
await context.Response.WriteAsync(result);
}
});
if (app.Environment.IsDevelopment())
if (app.Environment.IsDevelopment() || app.Environment.EnvironmentName == "Docker")
{
app.Logger.LogInformation("Adding Development middleware...");
app.UseDeveloperExceptionPage();
@@ -160,25 +181,5 @@ app.UseEndpoints(endpoints =>
endpoints.MapFallbackToFile("index.html");
});
app.Logger.LogInformation("Seeding Database...");
using (var scope = app.Services.CreateScope())
{
var scopedProvider = scope.ServiceProvider;
try
{
var catalogContext = scopedProvider.GetRequiredService<CatalogContext>();
await CatalogContextSeed.SeedAsync(catalogContext, app.Logger);
var userManager = scopedProvider.GetRequiredService<UserManager<ApplicationUser>>();
var roleManager = scopedProvider.GetRequiredService<RoleManager<IdentityRole>>();
await AppIdentityDbContextSeed.SeedAsync(userManager, roleManager);
}
catch (Exception ex)
{
app.Logger.LogError(ex, "An error occurred seeding the DB.");
}
}
app.Logger.LogInformation("LAUNCHING");
app.Run();

View File

@@ -20,20 +20,20 @@
<PackageReference Include="MediatR" Version="10.0.1" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="10.0.1" />
<PackageReference Include="BuildBundlerMinifier" Version="3.2.449" Condition="'$(Configuration)'=='Release'" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.2" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.161" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.1">
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.15.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.16.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\fonts\" />