From f0475ecf36f31cbb1afb99d39c4cabc4fcaf0213 Mon Sep 17 00:00:00 2001 From: cnphpbb Date: Wed, 2 Sep 2026 19:14:53 +0800 Subject: [PATCH] =?UTF-8?q?build(newapi):=20=E5=88=87=E6=8D=A2=20host=20?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E5=88=B0=20prod-dbs=20=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E5=B9=B6=E9=87=8D=E6=9E=84=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 复用 prod-postgres 与 Dev-Redis,移除宿主机直连 - 变量全部提供默认值,只需 env.cfg 填密码 - 容器名与网络引用同步调整 --- newapi/stack.host.yml | 50 +++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/newapi/stack.host.yml b/newapi/stack.host.yml index ebac5fe..c5f7547 100644 --- a/newapi/stack.host.yml +++ b/newapi/stack.host.yml @@ -1,44 +1,52 @@ # 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: - 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 timeout: 10s retries: 3 + +networks: + prod-dbs_default: + # 引用 prod-dbs 项目自动创建的默认网络,不归本 compose 管 + external: true + name: prod-dbs_default \ No newline at end of file