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();