chore: remove runtime config bootstrap and update local deploy docs

- stop copying config.example.yaml to config.yaml during app initialization
  - document the local config.yaml example directly in deploy.md
  - update Docker smoke test docs to mount configs/config.yaml
  - bump the K8s Postgres image from 13.16 to 17.5
This commit is contained in:
douxu 2026-06-26 16:01:32 +08:00
parent 35ff2f055a
commit 64f9423b68
3 changed files with 110 additions and 28 deletions

View File

@ -2,12 +2,10 @@ package app
import (
"context"
"errors"
"fmt"
"log"
"net/http"
"os"
"path/filepath"
"time"
"modelRT/config"
@ -35,30 +33,11 @@ import (
"gorm.io/gorm"
)
// provideConfig loads (and, if missing, bootstraps from the example file) the
// service configuration, then initializes the global logger. Because every other
// provider depends transitively on the config, initializing the logger here
// guarantees it is ready before any provider that logs. The returned cleanup
// flushes the logger on shutdown.
// provideConfig loads the service configuration, then initializes the global
// logger. Because every other provider depends transitively on the config,
// initializing the logger here guarantees it is ready before any provider that
// logs. The returned cleanup flushes the logger on shutdown.
func provideConfig(cli CLIArgs) (config.ModelRTConfig, func(), error) {
configPath := filepath.Join(cli.ConfigDir, cli.ConfigName+"."+cli.ConfigType)
if _, err := os.Stat(configPath); os.IsNotExist(err) {
log.Println("configuration file not found, checking for example file")
exampleConfigPath := filepath.Join(cli.ConfigDir, cli.ConfigName+".example."+cli.ConfigType)
configDir := filepath.Dir(configPath)
if err := os.MkdirAll(configDir, 0o755); err != nil {
return config.ModelRTConfig{}, nil, fmt.Errorf("failed to create config directory %s: %w", configDir, err)
}
if _, err := os.Stat(exampleConfigPath); err == nil {
if err := util.CopyFile(exampleConfigPath, configPath); err != nil {
return config.ModelRTConfig{}, nil, fmt.Errorf("failed to copy example config file: %w", err)
}
} else {
return config.ModelRTConfig{}, nil, errors.New("no config file and no config example file found")
}
}
cfg := config.ReadAndInitConfig(cli.ConfigDir, cli.ConfigName, cli.ConfigType)
logger.InitLoggerInstance(cfg.LoggerConfig)

View File

@ -444,6 +444,109 @@ go run deploy/redis-test-data/measurments-recommend/measurement_injection.go
| | `polling_api` | 轮询数据的 `API` 路径。 | `"datart/getPointData"` |
| | `polling_api_method` | 调用该 `API` 使用的 `HTTP` 方法。 | `"GET"` |
本地开发可参考以下示例创建 `configs/config.yaml`
```yaml
postgres:
host: "192.168.1.101"
port: 5432
database: "demo"
user: "postgres"
password: "coslight"
kafka:
servers: "127.0.0.1:9092"
port: 9092
group_id: "modelRT"
topic: ""
auto_offset_reset: "earliest"
enable_auto_commit: "false"
read_message_time_duration: 0.5
rabbitmq:
ca_cert_path: "./configs/certs/ca_certificate.pem"
client_key_path: "./configs/certs/modelrt_client_key.pem"
client_key_password: ""
client_cert_path: "./configs/certs/modelrt_client_cert.pem"
insecure_skip_verify: false
server_name: "rabbitmq-server"
user: ""
password: ""
host: "127.0.0.1"
port: 5671
# zap logger config
logger:
mode: "development"
level: "debug"
filepath: ""
maxsize: 100
maxbackups: 5
maxage: 30
compress: false
loki:
endpoint: "http://127.0.0.1:3100"
labels:
app: "model-rt"
otel:
endpoint: "127.0.0.1:4318"
insecure: true # Jaeger all-in-one 不启用 TLS生产环境改为 false
# ants config
ants:
parse_concurrent_quantity: 10
rtd_receive_concurrent_quantity: 10
# async task config
async_task:
worker_pool_size: 10
queue_consumer_count: 2
max_retry_count: 3
retry_initial_delay: 1s
retry_max_delay: 5m
health_check_interval: 30s
# redis config
locker_redis:
addr: "127.0.0.1:6379"
password: ""
db: 1
poolsize: 50
dial_timeout: 10
read_timeout: 10
write_timeout: 10
storage_redis:
addr: "127.0.0.1:6379"
password: ""
db: 0
poolsize: 50
dial_timeout: 10
read_timeout: 10
write_timeout: 10
# modelRT base config
base:
grid_id: 1
zone_id: 1
station_id: 1
# modelRT service config
service:
service_addr: ":8080"
service_name: "modelRT"
secret_key: "modelrt_key"
deploy_env: "development"
# dataRT api config
dataRT:
host: "http://127.0.0.1"
port: 8888
polling_api: "ws/points"
polling_api_method: "GET"
```
#### 3.2 编译 ModelRT 服务
```bash
@ -817,9 +920,9 @@ docker inspect coslight/modelrt:latest
# 验证二进制可执行(无 config 时程序报错退出属预期行为,说明镜像构建正常)
docker run --rm coslight/modelrt:latest
# 挂载示例配置做完整启动验证Ctrl+C 退出)
# 挂载本地配置做完整启动验证Ctrl+C 退出)
docker run --rm \
-v "$(pwd)/configs/config.example.yaml:/app/configs/config.yaml" \
-v "$(pwd)/configs/config.yaml:/app/configs/config.yaml" \
-p 8080:8080 \
coslight/modelrt:latest
```

View File

@ -17,7 +17,7 @@ spec:
spec:
containers:
- name: postgres
image: postgres:13.16
image: postgres:17.5
imagePullPolicy: IfNotPresent
ports:
- name: postgres