Add Docker support
Docker configuration: - Dockerfile: Multi-stage build with non-root user, health checks - Dockerfile.migrations: Runs EF Core migrations on startup - docker-compose.yml: Full stack with SQL Server, Azurite, app - .dockerignore: Optimized build context - .env.example: Template for API keys Application changes: - Added /health endpoint with EF Core database check - Conditional HTTPS redirect (disabled in containers) - DOTNET_RUNNING_IN_CONTAINER environment detection Usage: cp .env.example .env # Add your API keys docker-compose up -d # Start all services Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -56,6 +56,10 @@ try
|
||||
builder.Services.AddCascadingAuthenticationState();
|
||||
builder.Services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<ApplicationUser>>();
|
||||
|
||||
// Add health checks
|
||||
builder.Services.AddHealthChecks()
|
||||
.AddDbContextCheck<ApplicationDbContext>("database");
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
@@ -66,7 +70,15 @@ try
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
// Only use HTTPS redirection when not running in Docker/container
|
||||
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER")))
|
||||
{
|
||||
// Running in container - skip HTTPS redirect (handled by reverse proxy)
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseHttpsRedirection();
|
||||
}
|
||||
|
||||
app.UseStaticFiles();
|
||||
app.UseAntiforgery();
|
||||
@@ -93,6 +105,9 @@ try
|
||||
return Results.Redirect("/");
|
||||
}).RequireAuthorization();
|
||||
|
||||
// Health check endpoint
|
||||
app.MapHealthChecks("/health");
|
||||
|
||||
app.MapRazorComponents<App>()
|
||||
.AddInteractiveServerRenderMode();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user