From 799b527467e3fd8a895b56091a2faa0b94a660ef Mon Sep 17 00:00:00 2001 From: NoLogicAlan Date: Sun, 21 Jun 2026 21:14:36 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20add=20Docker=20support=20=E2=80=94=20Do?= =?UTF-8?q?ckerfile,=20docker-compose,=20entrypoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 10 ++++ README.md | 97 ++++++++++++++++++++++++++++++++++++- docker/.env.example | 26 ++++++++++ docker/Dockerfile | 43 ++++++++++++++++ docker/config_example.json | 74 ++++++++++++++++++++++++++++ docker/docker-compose.yml | 75 ++++++++++++++++++++++++++++ docker/docker-entrypoint.sh | 24 +++++++++ docker/nodelink.config.json | 25 ++++++++++ 8 files changed, 373 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 docker/.env.example create mode 100644 docker/Dockerfile create mode 100644 docker/config_example.json create mode 100644 docker/docker-compose.yml create mode 100644 docker/docker-entrypoint.sh create mode 100644 docker/nodelink.config.json diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d53bd1d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +node_modules +.git +.gitignore +*.md +!README.md +download/ +*.zip +config.json +docker/config.json +docker/.env diff --git a/README.md b/README.md index 72e6659..7b65dd6 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,95 @@ Below is the complete list of Remix's commands. The default prefix is `%`. If you prefer to host Remix yourself, please note: **You must make it clear that your bot is an instance of Remix.** Change the bot's name and give credit in the bot's profile (e.g., *"Powered by [Remix](https://github.com/remix-bot/fluxer)"*). -### Prerequisites +### Quick Start with Docker (Recommended) + +The fastest way to self-host Remix is with Docker. Everything — the bot, MySQL, Redis, and NodeLink — runs in containers with a single command. All Docker files live in the `docker/` folder. + +1. **Clone and configure:** + ```bash + git clone https://github.com/remix-bot/fluxer.git + cd fluxer/docker + cp .env.example .env + cp config_example.json config.json + ``` + +2. **Edit `.env`** — set your bot token and MySQL passwords. + +3. **Edit `config.json`** — fill in your bot token, Fluxer OAuth2 credentials (if using the dashboard), and any other settings. The Docker config already points MySQL/Redis/NodeLink at the correct service hostnames. + +4. **Start everything:** + ```bash + docker compose up -d + ``` + +5. **Check logs:** + ```bash + docker compose logs -f bot + ``` + +That's it. The bot will start, connect to MySQL (auto-creates the settings table), connect to NodeLink, and log in to Fluxer. + +#### Docker file structure + +``` +docker/ +├── Dockerfile # Multi-stage build (Node 22 + FFmpeg + tini) +├── docker-entrypoint.sh # Config validation on first boot +├── docker-compose.yml # bot + MySQL + Redis + NodeLink +├── config_example.json # Docker-friendly config template +├── .env.example # Secrets template +├── nodelink.config.json # NodeLink audio node config +├── config.json # You create this (gitignored) +└── .env # You create this (gitignored) +``` + +#### Docker services + +| Service | Container | Port | Purpose | +| :--- | :--- | :--- | :--- | +| `bot` | remix-bot | 8080 → 80 | The Remix bot + web dashboard | +| `mysql` | remix-mysql | — | Per-guild settings storage | +| `redis` | remix-redis | — | Dashboard sessions + pub/sub (optional) | +| `nodelink` | remix-nodelink | 3000 | Lavalink-compatible audio node | + +#### Useful Docker commands + +```bash +# Run from the docker/ folder +cd docker + +# Start all services +docker compose up -d + +# View live bot logs +docker compose logs -f bot + +# Restart the bot +docker compose restart bot + +# Stop everything +docker compose down + +# Stop and delete data volumes (full reset) +docker compose down -v + +# Rebuild after code changes +docker compose up -d --build bot +``` + +#### Using `CONFIG_JSON` env var instead of a mounted file + +If you prefer to keep your config in an environment variable (useful for CI/CD or secret managers), set `CONFIG_JSON` in your `.env`: + +```bash +CONFIG_JSON={"token":"YOUR_TOKEN","mysql":{"host":"mysql","port":3306,"user":"remix","password":"remix_pw","database":"remix"},"nodelink":{"host":"nodelink","port":3000,"password":"youshallnotpass"}} +``` + +The entrypoint will write it to `/app/config.json` on first boot if no config file is mounted. + +### Manual Installation (Without Docker) + +#### Prerequisites - **Node.js** >= 22.0.0 (required by moonlink.js v5) - **MySQL** 8.0+ with JSON column support @@ -354,6 +442,13 @@ fluxer/ │ ├── migrate.mjs # Legacy-to-remote settings migration script │ ├── runnables.mjs # Runnable task definitions │ └── README.md # Settings system documentation +├── docker/ # Docker self-hosting (Dockerfile, compose, configs) +│ ├── Dockerfile # Multi-stage build (Node 22 + FFmpeg + tini) +│ ├── docker-entrypoint.sh # Config validation on first boot +│ ├── docker-compose.yml # bot + MySQL + Redis + NodeLink +│ ├── config_example.json # Docker-friendly config template +│ ├── .env.example # Secrets template +│ └── nodelink.config.json # NodeLink audio node config └── storage/ ├── defaults.json # Default per-guild settings template ├── modules.json # Plugin module registry diff --git a/docker/.env.example b/docker/.env.example new file mode 100644 index 0000000..2bd5265 --- /dev/null +++ b/docker/.env.example @@ -0,0 +1,26 @@ +# Bot token from https://fluxer.app/developers +BOT_TOKEN=your_bot_token_here + +# MySQL credentials +MYSQL_ROOT_PASSWORD=change_me_root +MYSQL_DATABASE=remix +MYSQL_USER=remix +MYSQL_PASSWORD=change_me + +# Web dashboard port mapping (host:container) +WEB_PORT=8080 + +# NodeLink port mapping +NODELINK_PORT=3000 + +# Timezone +TZ=UTC + +# Optional: paste your entire config.json as a single line (base64 or raw JSON) +# If set, the entrypoint will write it to /app/config.json on first boot. +# CONFIG_JSON={"token":"...","mysql":{...}} + +# Fluxer OAuth2 (for dashboard) +FLUXER_OAUTH_ID= +FLUXER_OAUTH_SECRET= +FLUXER_OAUTH_REDIRECT_URI= diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..dafab17 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,43 @@ +# syntax=docker/dockerfile:1 + +# ---- Builder stage: install deps ---- +FROM node:22-bookworm-slim AS builder + +WORKDIR /app + +COPY package.json package-lock.json* ./ + +RUN npm ci --omit=dev 2>/dev/null || npm install --omit=dev + +COPY . . + +# ---- Runtime stage: minimal image with ffmpeg ---- +FROM node:22-bookworm-slim AS runtime + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + ffmpeg \ + tini \ + curl \ + && \ + rm -rf /var/lib/apt/lists/* + +RUN groupadd -r remix && useradd -r -g remix -d /app -s /sbin/nologin remix + +WORKDIR /app + +COPY --from=builder --chown=remix:remix /app ./ + +RUN chmod +x docker/docker-entrypoint.sh && \ + mkdir -p /app/storage && chown -R remix:remix /app + +USER remix + +EXPOSE 80 + +HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ + CMD pgrep -f "node index.mjs" >/dev/null 2>&1 || exit 1 + +ENTRYPOINT ["/usr/bin/tini", "--", "/app/docker/docker-entrypoint.sh"] + +CMD ["node", "index.mjs"] diff --git a/docker/config_example.json b/docker/config_example.json new file mode 100644 index 0000000..3034c16 --- /dev/null +++ b/docker/config_example.json @@ -0,0 +1,74 @@ +{ + "token": "YOUR_BOT_TOKEN_HERE", + "prefix": "%", + "embedColor": "0xe9196c", + "owners": [], + "mysql": { + "host": "mysql", + "port": 3306, + "user": "remix", + "password": "remix_pw", + "database": "remix" + }, + "nodelink": { + "host": "nodelink", + "port": 3000, + "password": "youshallnotpass", + "requestTimeout": 60000 + }, + "spotify": { + "clientId": "", + "clientSecret": "" + }, + "lastfm": { + "apiKey": "", + "apiSecret": "", + "scrobbleThreshold": 0.5, + "scrobbleMinMs": 240000 + }, + "dashboard": { + "enabled": false, + "redis": { + "url": "redis://redis:6379" + }, + "fluxer": { + "id": "", + "secret": "", + "redirectUri": "" + } + }, + "webPort": 80, + "logging": { + "enabled": true, + "warn": true, + "player": true, + "inactivity": false, + "aloneCheck": false, + "voice247": true, + "voiceState": false, + "voice": false, + "mediaplayer": false, + "commands": true, + "guild": true, + "recovery": true, + "settings": true, + "worker": false, + "moonlink": true, + "dashboard": false, + "redis": false + }, + "timers": { + "inactivityTimeout": 180000, + "aloneCheckInterval": 30000, + "aloneCheckDebounce": 500, + "rejoin247Delay": 3000, + "leave247RejoinDelay": 5000, + "intentionalLeaveTTL": 10000 + }, + "presenceInterval": 30000, + "presenceContents": [], + "fluxer.js": { + "timeout": 15000, + "retries": 3 + } +} diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..2e24169 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,75 @@ +services: + bot: + build: + context: .. + dockerfile: docker/Dockerfile + container_name: remix-bot + restart: unless-stopped + depends_on: + mysql: + condition: service_healthy + volumes: + - ./config.json:/app/config.json + - ../storage:/app/storage + environment: + - TZ=${TZ:-UTC} + ports: + - "${WEB_PORT:-8080}:80" + networks: + - remix-net + + mysql: + image: mysql:8.0 + container_name: remix-mysql + restart: unless-stopped + environment: + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-remix_root_pw} + MYSQL_DATABASE: ${MYSQL_DATABASE:-remix} + MYSQL_USER: ${MYSQL_USER:-remix} + MYSQL_PASSWORD: ${MYSQL_PASSWORD:-remix_pw} + volumes: + - mysql_data:/var/lib/mysql + healthcheck: + test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-remix_root_pw}"] + interval: 10s + timeout: 5s + retries: 10 + start_period: 30s + networks: + - remix-net + + redis: + image: redis:7-alpine + container_name: remix-redis + restart: unless-stopped + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 10s + timeout: 3s + retries: 5 + networks: + - remix-net + + nodelink: + image: node:22-bookworm-slim + container_name: remix-nodelink + restart: unless-stopped + working_dir: /nodelink + command: sh -c "if [ ! -f package.json ]; then npm init -y && npm install @performanc/nodelink; fi; node node_modules/@performanc/nodelink/index.js || node index.js" + environment: + - TZ=${TZ:-UTC} + volumes: + - nodelink_data:/nodelink + - ./nodelink.config.json:/nodelink/config.json:ro + ports: + - "${NODELINK_PORT:-3000}:3000" + networks: + - remix-net + +volumes: + mysql_data: + nodelink_data: + +networks: + remix-net: + driver: bridge diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh new file mode 100644 index 0000000..bfcac6b --- /dev/null +++ b/docker/docker-entrypoint.sh @@ -0,0 +1,24 @@ +#!/bin/sh +set -e + +CONFIG_FILE="/app/config.json" + +if [ ! -f "$CONFIG_FILE" ]; then + if [ -n "$CONFIG_JSON" ]; then + printf '%s' "$CONFIG_JSON" > "$CONFIG_FILE" + echo "[Docker] Generated config.json from CONFIG_JSON env var." + elif [ -f "/app/docker/config_example.json" ]; then + cp /app/docker/config_example.json "$CONFIG_FILE" + echo "[Docker] WARNING: config.json not found — copied from docker/config_example.json." + echo "[Docker] Edit the mounted config.json and restart the container." + else + echo "[Docker] FATAL: config.json not found and no template available." >&2 + exit 1 + fi +fi + +if [ "$1" = "node" ] && [ "$2" = "index.mjs" ]; then + echo "[Docker] Starting Remix bot..." +fi + +exec "$@" diff --git a/docker/nodelink.config.json b/docker/nodelink.config.json new file mode 100644 index 0000000..25c1bc7 --- /dev/null +++ b/docker/nodelink.config.json @@ -0,0 +1,25 @@ +{ + "server": { + "port": 3000, + "password": "youshallnotpass" + }, + "sources": { + "youtube": true, + "ytmusic": true, + "soundcloud": true, + "deezer": true, + "spotify": true, + "http": true + }, + "search": { + "defaultSource": "ytmusic", + "fallback": true + }, + "audio": { + "normalization": true + }, + "cache": { + "enabled": true, + "maxSize": 536870912 + } +}