forked from DevOps/deploy.stack
build(newapi): 切换 host 部署到 prod-dbs 网络并重构变量
- 复用 prod-postgres 与 Dev-Redis,移除宿主机直连 - 变量全部提供默认值,只需 env.cfg 填密码 - 容器名与网络引用同步调整
This commit is contained in:
+28
-20
@@ -1,40 +1,42 @@
|
||||
# path:: mkdir -pv /data/volumes/newapi/{data,logs}
|
||||
# pull:: docker compose -p newapi-host --env-file ./newapi/env.host.cfg -f ./newapi/stack.host.yml pull
|
||||
# run:: docker compose -p newapi-host --env-file ./newapi/env.host.cfg -f ./newapi/stack.host.yml up -d
|
||||
# disc:: 单容器部署:复用宿主机已有的 Redis 与 PostgreSQL,不启容器依赖
|
||||
# dist:: 通过 host.docker.internal 访问宿主机服务(Docker 20.10+ 默认支持)
|
||||
# dist:: 项目名 newapi-host,与 stack.yml 全栈部署互不冲突
|
||||
# dist:: 宿主机侧需确认:
|
||||
# dist:: - PG: listen_addresses 允许远程,pg_hba.conf 放通 Docker 网段
|
||||
# dist:: - Redis: bind 0.0.0.0,requirepass 与 REDIS_PASSWORD 一致
|
||||
# dist:: - 防火墙放通 3000 / 5432 / 6379
|
||||
# dist:: 第一个注册的账号自动成为管理员;生产务必修改 env.host.cfg 中的全部密码
|
||||
# pull:: docker compose -p newapi-host --env-file ./newapi/env.cfg -f ./newapi/stack.host.yml pull
|
||||
# run:: docker compose -p newapi-host --env-file ./newapi/env.cfg -f ./newapi/stack.host.yml up -d
|
||||
# disc:: 单容器部署:复用 prod-dbs 项目里的 prod-postgres(join 同一 docker 网络解析)
|
||||
# disc:: Redis 复用 dbSer/redis 的 Dev-Redis(172.22.10.205,固定 IP)
|
||||
# disc:: 项目名 newapi-host,与 stack.yml 全栈部署互不冲突
|
||||
# disc:: 启动顺序:先 up prod-dbs(确保 prod-dbs_default 网络存在),再 up newapi-host
|
||||
# disc:: 所有连接变量已内置默认值,复用 env.cfg 只需填密码即可
|
||||
# disc:: 第一个注册的账号自动成为管理员;生产务必修改 env.cfg 中的全部密码
|
||||
|
||||
services:
|
||||
newapi:
|
||||
image: ${IMAGE_TAG}
|
||||
container_name: newapi_app
|
||||
container_name: newapi_host_app
|
||||
restart: always
|
||||
command: --log-dir /app/logs
|
||||
ports:
|
||||
- "${PORT:-3000}:3000"
|
||||
networks:
|
||||
- prod-dbs_default # 加入 prod-dbs 默认网络,用 service 名 postgres 解析 prod-postgres
|
||||
volumes:
|
||||
- ${Volumes_Path}/data:/data
|
||||
- ${Volumes_Path}/logs:/app/logs
|
||||
- ${Volumes_Path:-/data/volumes/newapi}/data:/data
|
||||
- ${Volumes_Path:-/data/volumes/newapi}/logs:/app/logs
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
environment:
|
||||
# - SQL_DSN=postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
|
||||
# 本机 PG 无 TLS 时显式关闭 SSL:
|
||||
- SQL_DSN=postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=disable
|
||||
- REDIS_CONN_STRING=redis://:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}
|
||||
# 默认值:DB_HOST=postgres 指向 prod-dbs 项目的 postgres service
|
||||
# 本机 PG 无 TLS 时显式关闭 SSL(取消下行注释并注释上行):
|
||||
# - SQL_DSN=postgresql://${DB_USER:-newapi}:${DB_PASSWORD}@${DB_HOST:-postgres}:${DB_PORT:-5432}/${DB_NAME:-new_api}?sslmode=disable
|
||||
- SQL_DSN=postgresql://${DB_USER:-newapi}:${DB_PASSWORD}@${DB_HOST:-postgres}:${DB_PORT:-5432}/${DB_NAME:-new_api}
|
||||
# 默认值:REDIS_HOST=172.22.10.205 指向 Dev-Redis(dbSer/redis.yml部署,DevNet 网段固定 IP)
|
||||
- REDIS_CONN_STRING=redis://:${REDIS_PASSWORD}@${REDIS_HOST:-172.22.10.205}:${REDIS_PORT:-6379}
|
||||
- TZ=Asia/Shanghai
|
||||
- BATCH_UPDATE_ENABLED=true
|
||||
- ERROR_LOG_ENABLED=true
|
||||
- NODE_NAME=${NODE_NAME}
|
||||
- SESSION_SECRET=${SESSION_SECRET}
|
||||
- NODE_NAME=${NODE_NAME:-newapi-node-1}
|
||||
- SESSION_SECRET=${SESSION_SECRET:-}
|
||||
# 可选:独立日志库(PG 或 ClickHouse),不设则日志与业务同库
|
||||
# - LOG_SQL_DSN=postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}_log
|
||||
# - LOG_SQL_DSN=postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST:-postgres}:${DB_PORT:-5432}/${DB_NAME:-new_api}_log
|
||||
# 流式无响应超时(秒),默认 120,出现空补全时调大:
|
||||
# - STREAMING_TIMEOUT=300
|
||||
healthcheck:
|
||||
@@ -42,3 +44,9 @@ services:
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
networks:
|
||||
prod-dbs_default:
|
||||
# 引用 prod-dbs 项目自动创建的默认网络,不归本 compose 管
|
||||
external: true
|
||||
name: prod-dbs_default
|
||||
Reference in New Issue
Block a user