Update docker

This commit is contained in:
2025-11-09 05:02:13 +07:00
parent 009de85240
commit 57d4f2ce1c
2 changed files with 24 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
# Use the official Microsoft ASP.NET Core runtime as the base image (required for Host.CreateDefaultBuilder)
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
# Use the official Microsoft .NET runtime as the base image (for worker service, not API)
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
WORKDIR /app
# Use the official Microsoft .NET SDK image to build the code.

View File

@@ -23,8 +23,11 @@ Console.WriteLine($" ASPNETCORE_ENVIRONMENT: {aspnetcoreEnv ?? "(not set)"}");
Console.WriteLine($" Selected Environment: {environment}");
Console.WriteLine("═══════════════════════════════════════════════════════════");
var host = Host.CreateDefaultBuilder(args)
.UseEnvironment(environment) // Explicitly set the environment
var hostBuilder = new HostBuilder()
.UseEnvironment(environment)
.UseContentRoot(AppContext.BaseDirectory);
var host = hostBuilder
.ConfigureAppConfiguration((hostingContext, config) =>
{
var detectedEnv = hostingContext.HostingEnvironment.EnvironmentName;
@@ -50,9 +53,21 @@ var host = Host.CreateDefaultBuilder(args)
Console.WriteLine($" ✓ Loaded: {envFile} (optional)");
}
// 3. Environment variables and user secrets (highest priority)
config.AddEnvironmentVariables()
.AddUserSecrets<Program>();
// 3. Environment variables (highest priority)
config.AddEnvironmentVariables();
// User secrets only in development (requires ASP.NET Core, so we skip in production)
if (detectedEnv == "Development")
{
try
{
config.AddUserSecrets<Program>();
}
catch
{
// User secrets not available, skip silently
}
}
Console.WriteLine("═══════════════════════════════════════════════════════════");
})
@@ -86,7 +101,7 @@ var host = Host.CreateDefaultBuilder(args)
p => p.Contains('=') ? p.Substring(p.IndexOf('=') + 1).Trim() : string.Empty,
StringComparer.OrdinalIgnoreCase);
var host = connectionParts.GetValueOrDefault("Host", "unknown");
var dbHost = connectionParts.GetValueOrDefault("Host", "unknown");
var port = connectionParts.GetValueOrDefault("Port", "unknown");
var database = connectionParts.GetValueOrDefault("Database", "unknown");
var username = connectionParts.GetValueOrDefault("Username", "unknown");
@@ -96,7 +111,7 @@ var host = Host.CreateDefaultBuilder(args)
Console.WriteLine("═══════════════════════════════════════════════════════════");
Console.WriteLine("📊 PostgreSQL Database Configuration");
Console.WriteLine("═══════════════════════════════════════════════════════════");
Console.WriteLine($" Host: {host}");
Console.WriteLine($" Host: {dbHost}");
Console.WriteLine($" Port: {port}");
Console.WriteLine($" Database: {database}");
Console.WriteLine($" Username: {username}");