f55e28ee1d
按用户选定方案: 1. 多阶段 Debian bookworm-slim - builder=rust:1.96-bookworm(含 pkg-config libsqlite3-dev libssl-dev) - runtime=debian:bookworm-slim(ffmpeg libsqlite3-0 libssl3 tini ca-certificates) - 利用 Docker 层缓存:先预编译 deps 再复制 src 2. yt-dlp standalone 二进制 - ARG YTDLP_VERSION=2026.03.17 - 用 ADD --checksum=sha256 校验 - 与 README 中版本一致便于锁版本 3. 全部 bind mount - ./config → /app/config:ro(配置只读) - ./data → /app/data(secret.bin / crypto.db / cache/) 4. 单服务 docker-compose - 重启策略 unless-stopped - 资源限制 2 CPU + 1G RAM - 健康检查 pgrep - MATRIX_BOT_SECRET_PASSPHRASE 从 .env 必填 - RUST_LOG 默认 info + matrix_music_bot=debug 安全要点: - 非 root 用户(bot:bot) - tini 作为 PID 1(正确转发 SIGTERM/SIGINT) - 健康检查:仅进程存活检测(bot 没有 health endpoint) .dockerignore 排除: - /target /data /config /tests /docs 等 - 减少 build context 大小(避免每次 build 重复传输) .env.example: - 模板文件,含 MATRIX_BOT_SECRET_PASSPHRASE 默认值 - RUST_LOG 默认值 下一步:补充 README.md + CLAUDE.md 的 Docker 部署章节
58 lines
1.7 KiB
YAML
58 lines
1.7 KiB
YAML
services:
|
||
matrix-music-bot:
|
||
build:
|
||
context: .
|
||
dockerfile: Dockerfile
|
||
args:
|
||
# yt-dlp 版本(与 README 中一致的版本,便于锁版本防止 API 变动)
|
||
YTDLP_VERSION: "2026.03.17"
|
||
image: matrix-music-bot:latest
|
||
container_name: matrix-music-bot
|
||
restart: unless-stopped
|
||
# 生产环境建议移除 tty / stdin
|
||
tty: true
|
||
stdin_open: false
|
||
|
||
# 必须设置:用于加密 secret.bin
|
||
# 推荐通过 .env 文件或 docker-compose --env-file 传入
|
||
environment:
|
||
# === 必须 ===
|
||
- MATRIX_BOT_SECRET_PASSPHRASE=${MATRIX_BOT_SECRET_PASSPHRASE:?必须设置此环境变量(≥8字符)}
|
||
# === 可选(日志级别:trace/debug/info/warn/error) ===
|
||
- RUST_LOG=${RUST_LOG:-info,matrix_music_bot=debug}
|
||
|
||
# bind mount(用户选定:最透明方案)
|
||
volumes:
|
||
# 配置目录:主机 ./config → 容器 /app/config
|
||
- ./config:/app/config:ro
|
||
# 数据目录:主机 ./data → 容器 /app/data
|
||
# 含 secret.bin / crypto.db / cache/
|
||
- ./data:/app/data
|
||
|
||
# 资源限制(按需调整)
|
||
deploy:
|
||
resources:
|
||
limits:
|
||
# 单 bot 进程上限(搜索 + 转码 + 下载 spike)
|
||
cpus: "2.0"
|
||
memory: 1G
|
||
reservations:
|
||
cpus: "0.5"
|
||
memory: 256M
|
||
|
||
# 健康检查(与 Dockerfile HEALTHCHECK 同步)
|
||
healthcheck:
|
||
test: ["CMD-SHELL", "pgrep -x matrix-music-bot > /dev/null || exit 1"]
|
||
interval: 60s
|
||
timeout: 10s
|
||
retries: 3
|
||
start_period: 30s
|
||
|
||
# 网络:默认 bridge 即可(bot 主动出站连接 homeserver)
|
||
networks:
|
||
- bot-net
|
||
|
||
networks:
|
||
bot-net:
|
||
driver: bridge
|
||
name: matrix-music-bot-net |