fix: 统一 docker-compose 环境变量注入方式,修复 postgres/redis 配置读取问题
- postgres 和 redis 服务添加 env_file,统一从 /opt/camtalk/.env 读取配置
- 移除 postgres 中多余的 ${POSTGRES_USER/PASSWORD} 透传(env_file 已直接注入)
- 移除 backend 中多余的 CAMTALK_STORAGE_DSN 和 CAMTALK_REDIS_PASSWORD 透传
- postgres healthcheck 改用 $$POSTGRES_USER(容器内 shell 变量)替代 ${POSTGRES_USER}(compose 变量替换)
- 根本原因:environment 中的 ${VAR} 在 compose 解析时读取 shell 环境,为空时会覆盖 env_file 的值
This commit is contained in:
@@ -20,13 +20,11 @@ services:
|
|||||||
env_file:
|
env_file:
|
||||||
- /opt/camtalk/.env
|
- /opt/camtalk/.env
|
||||||
environment:
|
environment:
|
||||||
# 三级存储配置
|
# 三级存储配置(敏感信息通过 env_file 注入)
|
||||||
- CAMTALK_STORAGE_REDIS_ENABLED=${CAMTALK_STORAGE_REDIS_ENABLED:-true}
|
- CAMTALK_STORAGE_REDIS_ENABLED=${CAMTALK_STORAGE_REDIS_ENABLED:-true}
|
||||||
- CAMTALK_STORAGE_PERSISTENCE_ENABLED=${CAMTALK_STORAGE_PERSISTENCE_ENABLED:-true}
|
- CAMTALK_STORAGE_PERSISTENCE_ENABLED=${CAMTALK_STORAGE_PERSISTENCE_ENABLED:-true}
|
||||||
- CAMTALK_STORAGE_PERSISTENCE_DRIVER=${CAMTALK_STORAGE_PERSISTENCE_DRIVER:-postgres}
|
- CAMTALK_STORAGE_PERSISTENCE_DRIVER=${CAMTALK_STORAGE_PERSISTENCE_DRIVER:-postgres}
|
||||||
- CAMTALK_STORAGE_DSN=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/camtalk?sslmode=disable
|
|
||||||
- CAMTALK_REDIS_ADDR=redis:6379
|
- CAMTALK_REDIS_ADDR=redis:6379
|
||||||
- CAMTALK_REDIS_PASSWORD=${CAMTALK_REDIS_PASSWORD:-}
|
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
postgres:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -39,9 +37,9 @@ services:
|
|||||||
postgres:
|
postgres:
|
||||||
image: docker.m.daocloud.io/library/postgres:15-alpine
|
image: docker.m.daocloud.io/library/postgres:15-alpine
|
||||||
container_name: camtalk-postgres
|
container_name: camtalk-postgres
|
||||||
|
env_file:
|
||||||
|
- /opt/camtalk/.env
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: ${POSTGRES_USER}
|
|
||||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
|
||||||
POSTGRES_DB: camtalk
|
POSTGRES_DB: camtalk
|
||||||
volumes:
|
volumes:
|
||||||
- pgdata:/var/lib/postgresql/data
|
- pgdata:/var/lib/postgresql/data
|
||||||
@@ -49,7 +47,7 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- camtalk-net
|
- camtalk-net
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d camtalk"]
|
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d camtalk"]
|
||||||
interval: 5s
|
interval: 5s
|
||||||
timeout: 3s
|
timeout: 3s
|
||||||
retries: 10
|
retries: 10
|
||||||
@@ -58,6 +56,8 @@ services:
|
|||||||
redis:
|
redis:
|
||||||
image: docker.m.daocloud.io/library/redis:7-alpine
|
image: docker.m.daocloud.io/library/redis:7-alpine
|
||||||
container_name: camtalk-redis
|
container_name: camtalk-redis
|
||||||
|
env_file:
|
||||||
|
- /opt/camtalk/.env
|
||||||
command: >
|
command: >
|
||||||
sh -c '
|
sh -c '
|
||||||
if [ -n "$$CAMTALK_REDIS_PASSWORD" ]; then
|
if [ -n "$$CAMTALK_REDIS_PASSWORD" ]; then
|
||||||
@@ -65,8 +65,6 @@ services:
|
|||||||
else
|
else
|
||||||
exec redis-server --appendonly yes
|
exec redis-server --appendonly yes
|
||||||
fi'
|
fi'
|
||||||
environment:
|
|
||||||
CAMTALK_REDIS_PASSWORD: ${CAMTALK_REDIS_PASSWORD:-}
|
|
||||||
volumes:
|
volumes:
|
||||||
- redisdata:/data
|
- redisdata:/data
|
||||||
networks:
|
networks:
|
||||||
|
|||||||
Reference in New Issue
Block a user