107 lines
4.3 KiB
YAML
107 lines
4.3 KiB
YAML
# Token Factory Docker Compose Configuration
|
||
#
|
||
# Quick Start(完整栈:main应用 + Redis + PostgreSQL):
|
||
# 0. cp .env.example .env # 复制后在 .env 中填写密码等敏感信息(.env 勿提交仓库)
|
||
# 1. docker compose up -d
|
||
# 2. Access at http://localhost:3000
|
||
#
|
||
# 本地仅数据库编排(含资源限制):
|
||
# docker compose -f docker-compose.local.yml up -d
|
||
#
|
||
# Using MySQL instead of PostgreSQL:
|
||
# 1. Comment out the postgres service and SQL_DSN (token-factory.environment)
|
||
# 2. Uncomment the mysql service and SQL_DSN for MySQL
|
||
# 3. Uncomment mysql in token-factory.depends_on
|
||
# 4. Map mysql_data to ./mysql_data in mysql service volumes (see mysql service)
|
||
#
|
||
# ⚠️ IMPORTANT: Change all default passwords before deploying to production!
|
||
|
||
services:
|
||
token-factory:
|
||
image: token-factory:latest
|
||
container_name: token-factory
|
||
restart: always
|
||
command: --log-dir /app/logs
|
||
ports:
|
||
- "3000:3000"
|
||
volumes:
|
||
- ./data:/data
|
||
- ./logs:/app/logs
|
||
environment:
|
||
# 与下方 postgres 的账号库名一致;密码勿含 : @ / # ? 等字符,否则需自行 URL 编码后写入 SQL_DSN
|
||
- SQL_DSN=postgresql://${POSTGRES_USER:-root}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-token-factory}
|
||
# - SQL_DSN=root:${MYSQL_ROOT_PASSWORD}@tcp(mysql:3306)/${MYSQL_DATABASE:-token-factory} # 使用 MySQL 时取消注释并配置 .env
|
||
- REDIS_CONN_STRING=redis://redis
|
||
- TZ=Asia/Shanghai
|
||
- ERROR_LOG_ENABLED=true # 是否启用错误日志记录 (Whether to enable error log recording)
|
||
- BATCH_UPDATE_ENABLED=true # 是否启用批量更新 (Whether to enable batch update)
|
||
# - STREAMING_TIMEOUT=300 # 流模式无响应超时时间,单位秒,默认120秒,如果出现空补全可以尝试改为更大值 (Streaming timeout in seconds, default is 120s. Increase if experiencing empty completions)
|
||
- SESSION_SECRET=fb7918be2d9bda0ac754004f27c7ec2b # 多机部署时设置,必须修改这个随机字符串!! (multi-node deployment, set this to a random string!!!!!!!)
|
||
# - SYNC_FREQUENCY=60 # Uncomment if regular database syncing is needed
|
||
# - GOOGLE_ANALYTICS_ID=G-XXXXXXXXXX # Google Analytics 的测量 ID (Google Analytics Measurement ID)
|
||
# - UMAMI_WEBSITE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # Umami 网站 ID (Umami Website ID)
|
||
# - UMAMI_SCRIPT_URL=https://analytics.umami.is/script.js # Umami 脚本 URL,默认为官方地址 (Umami Script URL, defaults to official URL)
|
||
|
||
depends_on:
|
||
- redis
|
||
- postgres
|
||
# - mysql # Uncomment if using MySQL
|
||
networks:
|
||
- token-factory-network
|
||
healthcheck:
|
||
test: ["CMD-SHELL", "wget -q -O - http://localhost:3000/api/status | grep -o '\"success\":\\s*true' || exit 1"]
|
||
interval: 30s
|
||
timeout: 10s
|
||
retries: 3
|
||
|
||
redis:
|
||
image: redis:latest
|
||
container_name: redis
|
||
restart: always
|
||
# 持久化:官方镜像默认将 RDB 写入 /data/dump.rdb;此处挂载卷并开启 AOF,
|
||
# 容器删除后数据仍在宿主机 ./redis_data(备份/迁移时复制该目录即可)。
|
||
command: >
|
||
redis-server
|
||
--appendonly yes
|
||
--appendfsync everysec
|
||
volumes:
|
||
- ./redis_data:/data
|
||
networks:
|
||
- token-factory-network
|
||
ports:
|
||
- "6379:6379"
|
||
|
||
postgres:
|
||
image: postgres:15
|
||
container_name: postgres
|
||
restart: always
|
||
environment:
|
||
POSTGRES_USER: ${POSTGRES_USER:-root}
|
||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?请在 .env 中设置 POSTGRES_PASSWORD,可参考 .env.example}
|
||
POSTGRES_DB: ${POSTGRES_DB:-token-factory}
|
||
volumes:
|
||
# 绑定到宿主机目录,便于备份与迁移(复制整个 postgres_data 目录即可)
|
||
- ./postgres_data:/var/lib/postgresql/data
|
||
networks:
|
||
- token-factory-network
|
||
ports:
|
||
- "5432:5432"
|
||
|
||
# mysql:
|
||
# image: mysql:8.2
|
||
# container_name: mysql
|
||
# restart: always
|
||
# environment:
|
||
# MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:?请在 .env 中设置 MYSQL_ROOT_PASSWORD}
|
||
# MYSQL_DATABASE: ${MYSQL_DATABASE:-token-factory}
|
||
# volumes:
|
||
# - ./mysql_data:/var/lib/mysql
|
||
# networks:
|
||
# - token-factory-network
|
||
# ports:
|
||
# - "3306:3306" # Uncomment if you need to access MySQL from outside Docker
|
||
|
||
networks:
|
||
token-factory-network:
|
||
driver: bridge
|