build(newapi): 切换 host 部署到 prod-dbs 网络并重构变量

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