Files
deploy.stack/newapi/stack.yml
T
cnphpbb 3ea11a9945 build(newapi): 添加 new-api 部署配置
添加 docker compose 栈与环境变量模板,使用宿主机 PostgreSQL 与自建 Redis,网络采用 host 模式
2026-09-02 12:25:15 +08:00

53 lines
2.3 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# path:: mkdir -pv /data/volumes/newapi/{data,logs}
# pull:: docker compose -p newapi --env-file ./newapi/env.cfg -f ./newapi/stack.yml pull
# run:: docker compose -p newapi --env-file ./newapi/env.cfg -f ./newapi/stack.yml up -d
# disc:: 数据库使用宿主机已有 PostgreSQL,需先建库建号(SQL 见 env.cfg.example),栈内不跑 PG
# disc:: new-api 与 redis 均为 host 网络:无 ports 映射,PG/Redis 经 127.0.0.1 直连,
# disc:: 宿主机 PG 保持默认 localhost 监听即可,无需改 listen_addresses / pg_hba.conf
# disc:: 第一个注册的账号自动成为管理员;公网只放行 80/4433000 由 Nginx/Caddy 反代,勿直接暴露
services:
newapi:
image: ${IMAGE_TAG}
container_name: newapi_app
restart: always
command: --log-dir /app/logs
network_mode: host
volumes:
- ${Volumes_Path}/data:/data
- ${Volumes_Path}/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}
# 本机无 TLS 的 PG 也可显式关闭 SSL:
# - SQL_DSN=postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=disable
- REDIS_CONN_STRING=redis://:${REDIS_PASSWORD}@127.0.0.1:6379
- TZ=Asia/Shanghai
- BATCH_UPDATE_ENABLED=true
- ERROR_LOG_ENABLED=true
- NODE_NAME=${NODE_NAME}
- SESSION_SECRET=${SESSION_SECRET}
# 可选:独立日志库(PG 或 ClickHouse),不设则日志与业务同库
# - LOG_SQL_DSN=postgresql://user:pass@127.0.0.1:5432/new_api_log
# 流式无响应超时(秒),默认 120,出现空补全时调大:
# - STREAMING_TIMEOUT=300
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://localhost:3000/api/status > /dev/null || exit 1"]
interval: 30s
timeout: 10s
retries: 3
redis:
image: ${REDIS_IMAGE_TAG}
container_name: newapi_redis
restart: always
network_mode: host
# 宿主网络下只绑 127.0.0.1,外部无法直连;宿主机 6379 已被占用时先处理冲突
command: ["redis-server", "--requirepass", "${REDIS_PASSWORD}", "--bind", "127.0.0.1"]
healthcheck:
test: ["CMD-SHELL", "redis-cli -a ${REDIS_PASSWORD} ping | grep -q PONG"]
interval: 10s
timeout: 5s
retries: 5