feat: migrate to DragonflyDB and clean up environment configuration

- Replace Redis with DragonflyDB for better performance and memory efficiency
- Remove redundant environment variables (POSTGRES_*, ENCRYPTION_KEY, OAUTH_SERVICE_URL)
- Consolidate database configuration to use single DB_* variables
- Use JWT_SECRET for both JWT tokens and encryption
- Remove PORT variable redundancy, use BACKEND_PORT consistently
- Clean up docker-compose configurations for dev/prod consistency
- Add DragonflyDB configuration with optimized memory usage
- Remove redis.conf as it's no longer needed
- Update health checks to use Redis-compatible CLI for DragonflyDB
- Add missing VITE_API_URL to production frontend
- Fix GitHub Actions to use correct go.sum path
- Clean up development directories and unused files
This commit is contained in:
Tomas Dvorak
2026-03-05 23:51:34 +01:00
parent f3a835caa2
commit 954a1a1080
146 changed files with 5801 additions and 25847 deletions
+27 -10
View File
@@ -2,12 +2,12 @@ package config
import (
"fmt"
"log"
"os"
"github.com/trackeep/backend/migrations"
"go.uber.org/zap"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
var DB *gorm.DB
@@ -26,12 +26,20 @@ func getJWTSecret() string {
// InitDatabase initializes the database connection
func InitDatabase() {
// Initialize logger first
InitLogger()
logger := GetLogger()
// Check if demo mode is enabled
if os.Getenv("VITE_DEMO_MODE") == "true" {
logger.Info("Demo mode enabled - skipping database initialization")
return
}
var err error
// Configure GORM logger
gormConfig := &gorm.Config{
Logger: logger.Default.LogMode(logger.Info),
}
// Configure GORM
gormConfig := &gorm.Config{}
dbType := os.Getenv("DB_TYPE")
if dbType == "" {
@@ -49,19 +57,28 @@ func InitDatabase() {
os.Getenv("DB_SSL_MODE"),
)
DB, err = gorm.Open(postgres.Open(dsn), gormConfig)
log.Println("Using PostgreSQL database")
logger.Info("Using PostgreSQL database")
default:
log.Fatal("Unsupported database type: " + dbType)
logger.Fatal("Unsupported database type", zap.String("type", dbType))
}
if err != nil {
log.Fatal("Failed to connect to database:", err)
logger.Fatal("Failed to connect to database", zap.Error(err))
}
log.Println("Database connected successfully")
logger.Info("Database connected successfully")
// Run database migrations
if err := migrations.RunMigrations(); err != nil {
logger.Fatal("Failed to run database migrations", zap.Error(err))
}
}
// GetDB returns the database instance
func GetDB() *gorm.DB {
// In demo mode, return nil since no database is available
if os.Getenv("VITE_DEMO_MODE") == "true" {
return nil
}
return DB
}
+84
View File
@@ -0,0 +1,84 @@
package config
import (
"os"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var Logger *zap.Logger
// InitLogger initializes the Zap logger
func InitLogger() {
// Get log level from environment
logLevel := os.Getenv("LOG_LEVEL")
if logLevel == "" {
logLevel = "info"
}
// Parse log level
var level zapcore.Level
switch logLevel {
case "debug":
level = zapcore.DebugLevel
case "info":
level = zapcore.InfoLevel
case "warn":
level = zapcore.WarnLevel
case "error":
level = zapcore.ErrorLevel
default:
level = zapcore.InfoLevel
}
// Check if we're in production mode
isProduction := os.Getenv("GIN_MODE") == "release"
// Configure encoder
var encoder zapcore.Encoder
encoderConfig := zap.NewProductionEncoderConfig()
encoderConfig.TimeKey = "timestamp"
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
encoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
if isProduction {
encoder = zapcore.NewJSONEncoder(encoderConfig)
} else {
encoder = zapcore.NewConsoleEncoder(encoderConfig)
}
// Configure output
writeSyncer := zapcore.AddSync(os.Stdout)
// Create core
core := zapcore.NewCore(encoder, writeSyncer, level)
// Create logger
Logger = zap.New(core, zap.AddCaller(), zap.AddStacktrace(zapcore.ErrorLevel))
// Replace global logger
zap.ReplaceGlobals(Logger)
Logger.Info("Logger initialized",
zap.String("level", logLevel),
zap.Bool("production", isProduction),
)
}
// GetLogger returns the configured logger instance
func GetLogger() *zap.Logger {
if Logger == nil {
// Fallback to default logger if not initialized
logger, _ := zap.NewProduction()
return logger
}
return Logger
}
// SyncLogger flushes any buffered log entries
func SyncLogger() {
if Logger != nil {
_ = Logger.Sync()
}
}