From 21c8c9c51da4c0caaae12e2dbc0a881c80b87506 Mon Sep 17 00:00:00 2001 From: HRiggs Date: Fri, 5 Dec 2025 21:40:02 -0500 Subject: [PATCH] Dockerize the bashar bot --- .dockerignore | 15 ++++++ .env.example | 6 +++ DOCKER_DEPLOYMENT.md | 107 +++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 31 +++++++++++++ docker-compose.yml | 31 +++++++++++++ 5 files changed, 190 insertions(+) create mode 100644 .dockerignore create mode 100644 .env.example create mode 100644 DOCKER_DEPLOYMENT.md create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..aa1cbee --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +.git +.gitignore +.env +.venv +__pycache__ +*.pyc +*.pyo +*.pyd +.Python +*.log +transcript.log +bot.log +README.md +.vscode +.idea diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d35fa7f --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +DISCORD_TOKEN=your_discord_token_here +WHISPER_MODEL_SIZE=small +LOG_LEVEL=INFO +TRANSCRIPT_LOG_ENABLED=true +HOTWORD_ENABLED=true +GOODBOY_USER_ID=94578724413902848 diff --git a/DOCKER_DEPLOYMENT.md b/DOCKER_DEPLOYMENT.md new file mode 100644 index 0000000..9a85e2c --- /dev/null +++ b/DOCKER_DEPLOYMENT.md @@ -0,0 +1,107 @@ +# Docker Deployment Guide + +## Quick Start + +1. **Copy environment file:** + ```bash + cp .env.example .env + ``` + +2. **Edit .env with your Discord token:** + ```bash + # Edit .env and add your DISCORD_TOKEN + ``` + +3. **Build and run with Docker Compose:** + ```bash + docker-compose up -d + ``` + +4. **View logs:** + ```bash + docker-compose logs -f basharbot + ``` + +## Portainer Deployment + +### Method 1: Using Portainer Stacks + +1. Log into Portainer +2. Go to **Stacks** → **Add stack** +3. Name it `basharbot` +4. Choose **Upload** and upload `docker-compose.yml` +5. Add environment variables in the **Environment variables** section: + - `DISCORD_TOKEN`: Your Discord bot token + - `WHISPER_MODEL_SIZE`: small (or tiny/base/medium/large) + - `LOG_LEVEL`: INFO +6. Click **Deploy the stack** + +### Method 2: Using Git Repository + +1. In Portainer, go to **Stacks** → **Add stack** +2. Choose **Repository** +3. Enter your Git repository URL +4. Set compose path: `docker-compose.yml` +5. Add environment variables +6. Click **Deploy the stack** + +## Configuration + +All configuration is done via environment variables in `.env`: + +- `DISCORD_TOKEN`: Your Discord bot token (required) +- `WHISPER_MODEL_SIZE`: Model size for speech recognition (tiny/small/base/medium/large) +- `LOG_LEVEL`: Logging level (DEBUG/INFO/WARNING/ERROR) +- `TRANSCRIPT_LOG_ENABLED`: Enable transcript logging (true/false) +- `HOTWORD_ENABLED`: Enable hotword detection (true/false) +- `GOODBOY_USER_ID`: Special user ID for goodboy audio + +## Volumes + +- `./logs`: Bot and transcript logs +- `./data`: Persistent data +- `whisper-models`: Cached Whisper AI models + +## Commands + +```bash +# Start the bot +docker-compose up -d + +# Stop the bot +docker-compose down + +# View logs +docker-compose logs -f + +# Restart the bot +docker-compose restart + +# Rebuild after code changes +docker-compose up -d --build + +# Remove everything including volumes +docker-compose down -v +``` + +## Troubleshooting + +**Bot won't start:** +- Check logs: `docker-compose logs basharbot` +- Verify DISCORD_TOKEN is set correctly in .env + +**Audio issues:** +- Ensure ffmpeg is installed in container (included in Dockerfile) +- Check opus library is available + +**High memory usage:** +- Use smaller Whisper model: `WHISPER_MODEL_SIZE=tiny` +- Reduce model compute type in stt.py + +## Updates + +To update the bot: +```bash +git pull +docker-compose up -d --build +``` diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..696a45d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +# Use Python 3.11 slim image +FROM python:3.11-slim + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + ffmpeg \ + libopus0 \ + libopus-dev \ + espeak \ + libespeak-dev \ + && rm -rf /var/lib/apt/lists/* + +# Set working directory +WORKDIR /app + +# Copy requirements first for better caching +COPY requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy application files +COPY bot.py . +COPY stt.py . +COPY goodboy.ogg . + +# Create volume mount points for logs and data +VOLUME ["/app/logs", "/app/data"] + +# Run the bot +CMD ["python", "-u", "bot.py"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6ee2fd0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,31 @@ +version: '3.8' + +services: + basharbot: + build: . + container_name: basharbot + restart: unless-stopped + environment: + - DISCORD_TOKEN=MTAxNDE5NDAxNzM0NjUzMTQxOQ.GY6P0P.jnCq9V4SbeO1HmkNuzWCSM47CnrIsdko_3sCCw + - WHISPER_MODEL_SIZE=small + - LOG_LEVEL=DEBUG + - TRANSCRIPT_LOG_ENABLED=true + - HOTWORD_ENABLED=true + - GOODBOY_USER_ID=94578724413902848 + - TRANSCRIPT_LOG_PATH=/app/logs/transcript.log + volumes: + - ./logs:/app/logs + - ./data:/app/data + - whisper-models:/root/.cache/huggingface + networks: + - bot-network + labels: + - "com.centurylinklabs.watchtower.enable=true" + +volumes: + whisper-models: + driver: local + +networks: + bot-network: + driver: bridge