🐛 fix: properly detect Docker container vs native execution
- Enhance getPostgresHost() to detect Docker environment - Check multiple Docker-specific indicators - Use container name when running inside Docker - Use localhost when running natively - Fix BDD test PostgreSQL connection issues Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -17,15 +17,27 @@ import (
|
||||
)
|
||||
|
||||
// getPostgresHost returns the appropriate PostgreSQL host based on environment
|
||||
// Uses DLC_DATABASE_HOST environment variable or defaults appropriately
|
||||
// Uses DLC_DATABASE_HOST environment variable or detects execution context
|
||||
func getPostgresHost() string {
|
||||
host := os.Getenv("DLC_DATABASE_HOST")
|
||||
if host != "" {
|
||||
return host
|
||||
}
|
||||
// Default to localhost for native execution, container name for Docker
|
||||
// When running natively but PostgreSQL is in Docker, use localhost (port mapping)
|
||||
// When running in Docker containers, use container name
|
||||
|
||||
// Detect if we're running inside a Docker container
|
||||
// Check for Docker-specific environment variables or files
|
||||
if os.Getenv("DOCKER_CONTAINER") != "" ||
|
||||
os.Getenv("KUBERNETES_SERVICE_HOST") != "" ||
|
||||
os.Getenv("container") == "docker" {
|
||||
return "dance-lessons-coach-postgres" // Use container name in Docker
|
||||
}
|
||||
|
||||
// Check for .dockerenv file (Docker-specific)
|
||||
if _, err := os.Stat("/.dockerenv"); err == nil {
|
||||
return "dance-lessons-coach-postgres" // Use container name in Docker
|
||||
}
|
||||
|
||||
// Default to localhost for native execution (PostgreSQL port mapping)
|
||||
return "localhost"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user