fix(docker): do not hardcode sqlite; allow env to override config.ini
Build and Deploy / build-and-push (push) Successful in 53s
Build and Deploy / build-and-push (push) Successful in 53s
This commit is contained in:
@@ -116,9 +116,8 @@ func LoadConfig(path string) (*AppConfig, error) {
|
||||
},
|
||||
}
|
||||
|
||||
// 检查配置文件是否存在
|
||||
// 检查配置文件是否存在:文件先加载,再用环境变量覆盖(compose 注入优先)
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
// 配置文件存在,从文件加载
|
||||
logger.Infof("[Config] 从文件加载配置: %s", path)
|
||||
cfg, err := ini.Load(path)
|
||||
if err != nil {
|
||||
@@ -128,10 +127,10 @@ func LoadConfig(path string) (*AppConfig, error) {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
// 配置文件不存在,使用环境变量
|
||||
logger.Info("[Config] 配置文件不存在,从环境变量加载")
|
||||
applyEnvOverrides()
|
||||
logger.Info("[Config] 配置文件不存在,使用默认值 + 环境变量")
|
||||
}
|
||||
// 环境变量始终可覆盖(便于 Docker Compose 注入 MySQL/Redis 等)
|
||||
applyEnvOverrides()
|
||||
|
||||
// 设置默认数据库路径
|
||||
if Config.Database.Path == "" {
|
||||
|
||||
+3
-1
@@ -15,7 +15,9 @@ stderr_logfile=/app/logs/backend.err.log
|
||||
stdout_logfile=/app/logs/backend.out.log
|
||||
stdout_logfile_maxbytes=10MB
|
||||
stderr_logfile_maxbytes=10MB
|
||||
environment=BH_SERVER_PORT="8052",BH_SERVER_HOST="0.0.0.0",BH_DB_TYPE="sqlite",BH_DB_PATH="/app/data/taskpool.db"
|
||||
# 不写死 BH_DB_*,避免覆盖 compose 注入的 MySQL/Postgres。
|
||||
# 仅在 compose 未设置时提供默认监听参数。
|
||||
environment=BH_SERVER_PORT="8052",BH_SERVER_HOST="0.0.0.0"
|
||||
|
||||
[program:nginx]
|
||||
command=nginx -g "daemon off;"
|
||||
|
||||
Reference in New Issue
Block a user