From 74193ffbf07787a624cb6abaeac01ed4eb4d8c7e Mon Sep 17 00:00:00 2001 From: saopig1 Date: Mon, 30 Mar 2026 13:20:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Docker=20one-click=20deployment=20?= =?UTF-8?q?=E2=80=94=20all=20deps=20bundled,=20native=20modules,=20health?= =?UTF-8?q?=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Multi-stage build: builder installs backend + frontend deps, compiles - Production stage: npm ci --production rebuilds native modules (opus, sqlite3) - FFmpeg bundled via ffmpeg-static (no apt install ffmpeg) - .dockerignore prevents node_modules/dist from being copied - docker-compose uses host network for TS3 UDP connectivity - Named volume for persistent data - Health check endpoint Co-Authored-By: Claude Opus 4.6 (1M context) --- .dockerignore | 13 +++++++ scripts/docker/Dockerfile | 63 +++++++++++++++++++++++++------ scripts/docker/docker-compose.yml | 22 +++++++++-- 3 files changed, 82 insertions(+), 16 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9b8bbc0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +node_modules/ +web/node_modules/ +dist/ +web/dist/ +data/ +*.db +.env +config.json +cookies/ +.git/ +.claude/ +docs/superpowers/ +test-*.ts diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile index d133293..67a2691 100644 --- a/scripts/docker/Dockerfile +++ b/scripts/docker/Dockerfile @@ -1,24 +1,63 @@ +# ========================================== +# TSMusicBot Docker Image +# One-click deployment — all dependencies included +# ========================================== + +# --- Stage 1: Build backend + frontend --- FROM node:20-slim AS builder -WORKDIR /app -COPY package*.json ./ -RUN npm ci - -COPY . . -RUN npm run build - -FROM node:20-slim - -RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && \ +# Install build tools for native modules (opus, better-sqlite3) +RUN apt-get update && apt-get install -y --no-install-recommends \ + python3 make g++ && \ rm -rf /var/lib/apt/lists/* WORKDIR /app + +# Install backend dependencies +COPY package*.json ./ +RUN npm ci + +# Install frontend dependencies +COPY web/package*.json ./web/ +RUN cd web && npm ci + +# Copy source and build +COPY . . +RUN npm run build + +# --- Stage 2: Production image --- +FROM node:20-slim + +# Install only runtime native build tools (needed for native module rebuild) +RUN apt-get update && apt-get install -y --no-install-recommends \ + python3 make g++ && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# Copy built output COPY --from=builder /app/dist ./dist COPY --from=builder /app/web/dist ./web/dist COPY --from=builder /app/package*.json ./ -RUN npm ci --production -EXPOSE 3000 +# Install production dependencies (includes ffmpeg-static, opus, sqlite3) +# These need to compile native addons inside the container +RUN npm ci --production && npm cache clean --force + +# Remove build tools to reduce image size +RUN apt-get purge -y python3 make g++ && apt-get autoremove -y && \ + rm -rf /var/lib/apt/lists/* + +# FFmpeg is bundled via ffmpeg-static — no system ffmpeg needed + +# Data directory for database, cookies, logs +RUN mkdir -p /app/data VOLUME ["/app/data"] +EXPOSE 3000 + +# Health check +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \ + CMD node -e "fetch('http://localhost:3000/api/health').then(r=>r.ok?process.exit(0):process.exit(1)).catch(()=>process.exit(1))" + CMD ["node", "dist/index.js"] diff --git a/scripts/docker/docker-compose.yml b/scripts/docker/docker-compose.yml index bba69c3..0550319 100644 --- a/scripts/docker/docker-compose.yml +++ b/scripts/docker/docker-compose.yml @@ -1,4 +1,8 @@ -version: '3.8' +# TSMusicBot — Docker Compose +# 一键部署:docker-compose up -d +# +# 所有依赖已内置(Node.js, FFmpeg, Opus 编码器) +# 无需安装任何额外软件 services: tsmusicbot: @@ -6,10 +10,20 @@ services: context: ../.. dockerfile: scripts/docker/Dockerfile container_name: tsmusicbot - ports: - - "3000:3000" + # Use host network so the bot can reach TS3 server on LAN + # If your TS3 server is on the same machine, this is required + network_mode: host + # If you prefer port mapping instead of host network, comment out + # network_mode and uncomment ports: + # ports: + # - "3000:3000" # WebUI + # - "9987:9987/udp" # TS3 voice (only if TS3 server is in another container) volumes: - - ./data:/app/data + - tsmusicbot-data:/app/data restart: unless-stopped environment: - NODE_ENV=production + +volumes: + tsmusicbot-data: + driver: local