Update docker
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# Use the official Microsoft ASP.NET Core runtime as the base image (required for Host.CreateDefaultBuilder)
|
# Use the official Microsoft .NET runtime as the base image (for worker service, not API)
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Use the official Microsoft .NET SDK image to build the code.
|
# Use the official Microsoft .NET SDK image to build the code.
|
||||||
|
|||||||
@@ -23,8 +23,11 @@ Console.WriteLine($" ASPNETCORE_ENVIRONMENT: {aspnetcoreEnv ?? "(not set)"}");
|
|||||||
Console.WriteLine($" Selected Environment: {environment}");
|
Console.WriteLine($" Selected Environment: {environment}");
|
||||||
Console.WriteLine("═══════════════════════════════════════════════════════════");
|
Console.WriteLine("═══════════════════════════════════════════════════════════");
|
||||||
|
|
||||||
var host = Host.CreateDefaultBuilder(args)
|
var hostBuilder = new HostBuilder()
|
||||||
.UseEnvironment(environment) // Explicitly set the environment
|
.UseEnvironment(environment)
|
||||||
|
.UseContentRoot(AppContext.BaseDirectory);
|
||||||
|
|
||||||
|
var host = hostBuilder
|
||||||
.ConfigureAppConfiguration((hostingContext, config) =>
|
.ConfigureAppConfiguration((hostingContext, config) =>
|
||||||
{
|
{
|
||||||
var detectedEnv = hostingContext.HostingEnvironment.EnvironmentName;
|
var detectedEnv = hostingContext.HostingEnvironment.EnvironmentName;
|
||||||
@@ -50,9 +53,21 @@ var host = Host.CreateDefaultBuilder(args)
|
|||||||
Console.WriteLine($" ✓ Loaded: {envFile} (optional)");
|
Console.WriteLine($" ✓ Loaded: {envFile} (optional)");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Environment variables and user secrets (highest priority)
|
// 3. Environment variables (highest priority)
|
||||||
config.AddEnvironmentVariables()
|
config.AddEnvironmentVariables();
|
||||||
.AddUserSecrets<Program>();
|
|
||||||
|
// 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("═══════════════════════════════════════════════════════════");
|
Console.WriteLine("═══════════════════════════════════════════════════════════");
|
||||||
})
|
})
|
||||||
@@ -86,7 +101,7 @@ var host = Host.CreateDefaultBuilder(args)
|
|||||||
p => p.Contains('=') ? p.Substring(p.IndexOf('=') + 1).Trim() : string.Empty,
|
p => p.Contains('=') ? p.Substring(p.IndexOf('=') + 1).Trim() : string.Empty,
|
||||||
StringComparer.OrdinalIgnoreCase);
|
StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
var host = connectionParts.GetValueOrDefault("Host", "unknown");
|
var dbHost = connectionParts.GetValueOrDefault("Host", "unknown");
|
||||||
var port = connectionParts.GetValueOrDefault("Port", "unknown");
|
var port = connectionParts.GetValueOrDefault("Port", "unknown");
|
||||||
var database = connectionParts.GetValueOrDefault("Database", "unknown");
|
var database = connectionParts.GetValueOrDefault("Database", "unknown");
|
||||||
var username = connectionParts.GetValueOrDefault("Username", "unknown");
|
var username = connectionParts.GetValueOrDefault("Username", "unknown");
|
||||||
@@ -96,7 +111,7 @@ var host = Host.CreateDefaultBuilder(args)
|
|||||||
Console.WriteLine("═══════════════════════════════════════════════════════════");
|
Console.WriteLine("═══════════════════════════════════════════════════════════");
|
||||||
Console.WriteLine("📊 PostgreSQL Database Configuration");
|
Console.WriteLine("📊 PostgreSQL Database Configuration");
|
||||||
Console.WriteLine("═══════════════════════════════════════════════════════════");
|
Console.WriteLine("═══════════════════════════════════════════════════════════");
|
||||||
Console.WriteLine($" Host: {host}");
|
Console.WriteLine($" Host: {dbHost}");
|
||||||
Console.WriteLine($" Port: {port}");
|
Console.WriteLine($" Port: {port}");
|
||||||
Console.WriteLine($" Database: {database}");
|
Console.WriteLine($" Database: {database}");
|
||||||
Console.WriteLine($" Username: {username}");
|
Console.WriteLine($" Username: {username}");
|
||||||
|
|||||||
Reference in New Issue
Block a user