From 94494c1ca57a7b00e56acb99f50cfede30262d7c Mon Sep 17 00:00:00 2001 From: Luis Bauza Date: Wed, 17 Dec 2025 19:31:03 -0500 Subject: [PATCH] feat: update AI model in AskCommand and add Docker support files for improved deployment --- .dockerignore | 27 ++++++++ DOCKER.md | 155 +++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 28 ++++++++ commands/ask.js | 4 +- docker-compose.yml | 24 +++++++ 5 files changed, 235 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 DOCKER.md create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2af9807 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,27 @@ +node_modules +npm-debug.log +coverage +.git +.gitignore +.env +.env.local +.env.*.local +*.md +README.md +LICENSE +TESTING.md +PRIVACY.md +TERMS.md +SECURITY.md +ansible-README.md +__tests__ +jest.config.js +jest.setup.js +.eslintrc.* +.prettierrc +.vscode +.idea +*.log +.DS_Store +inventory.ini +playbook.yml diff --git a/DOCKER.md b/DOCKER.md new file mode 100644 index 0000000..a6a6490 --- /dev/null +++ b/DOCKER.md @@ -0,0 +1,155 @@ +# Docker Setup Guide + +## Prerequisites + +- Docker installed on your system +- Docker Compose (optional, but recommended) + +## Configuration + +1. Create a `.env` file in the project root with your Discord bot credentials: + + ```bash + cp .env.example .env + ``` + +2. Edit the `.env` file and add your Discord bot token and other credentials: + ``` + DISCORD_TOKEN=your_discord_bot_token_here + CLIENT_ID=your_client_id_here + OPENROUTER_API_KEY=your_openrouter_api_key_here + ``` + +## Running with Docker Compose (Recommended) + +### Start the bot: + +```bash +docker-compose up -d +``` + +### View logs: + +```bash +docker-compose logs -f +``` + +### Stop the bot: + +```bash +docker-compose down +``` + +### Restart the bot: + +```bash +docker-compose restart +``` + +### Rebuild and start (after code changes): + +```bash +docker-compose up -d --build +``` + +## Running with Docker directly + +### Build the image: + +```bash +docker build -t kekbot:latest . +``` + +### Run the container: + +```bash +docker run -d \ + --name kekbot \ + --env-file .env \ + --restart unless-stopped \ + kekbot:latest +``` + +### View logs: + +```bash +docker logs -f kekbot +``` + +### Stop the container: + +```bash +docker stop kekbot +docker rm kekbot +``` + +## Deploy Commands + +Before running the bot for the first time, you may need to deploy slash commands: + +```bash +# Using Docker Compose +docker-compose run --rm kekbot npm run deploy + +# Using Docker directly +docker run --rm --env-file .env kekbot:latest npm run deploy +``` + +## Troubleshooting + +### Check if container is running: + +```bash +docker ps +``` + +### View all containers (including stopped): + +```bash +docker ps -a +``` + +### Access container shell: + +```bash +docker exec -it kekbot sh +``` + +### View container resource usage: + +```bash +docker stats kekbot +``` + +## Production Considerations + +1. **Security**: Ensure your `.env` file is never committed to version control +2. **Logging**: Configure log rotation if using volume mounts for logs +3. **Updates**: Regularly update the base image and dependencies +4. **Monitoring**: Consider adding monitoring tools like Prometheus or Grafana +5. **Backups**: If you add persistent data, implement backup strategies + +## Multi-stage Build (Alternative) + +For a smaller production image, you can use the multi-stage Dockerfile variant: + +```dockerfile +# Development stage +FROM node:20-alpine AS development +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY . . + +# Production stage +FROM node:20-alpine AS production +WORKDIR /app +COPY package*.json ./ +RUN npm ci --only=production +COPY . . +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nodejs -u 1001 && \ + chown -R nodejs:nodejs /app +USER nodejs +CMD ["npm", "start"] +``` diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f3a73f9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# Use Node.js LTS version +FROM node:20-alpine + +# Set working directory +WORKDIR /app + +# Copy package files +COPY package*.json ./ + +# Install dependencies +RUN npm ci --only=production + +# Copy application files +COPY . . + +# Create a non-root user to run the application +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nodejs -u 1001 && \ + chown -R nodejs:nodejs /app + +# Switch to non-root user +USER nodejs + +# Expose port (if needed for health checks) +EXPOSE 3000 + +# Start the bot +CMD ["npm", "start"] diff --git a/commands/ask.js b/commands/ask.js index 3295fe0..2856b9a 100644 --- a/commands/ask.js +++ b/commands/ask.js @@ -48,9 +48,7 @@ export default class AskCommand extends Command { const response = await axios.post( 'https://openrouter.ai/api/v1/chat/completions', { - model: webSearchEnabled - ? 'google/gemma-3-27b-it:free:online' - : 'google/gemma-3-27b-it:free', + model: webSearchEnabled ? 'xiaomi/mimo-v2-flash:free:online' : 'xiaomi/mimo-v2-flash:free', messages: [ { role: 'system', diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4805fbb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +version: '3.8' + +services: + kekbot: + build: + context: . + dockerfile: Dockerfile + container_name: kekbot + restart: unless-stopped + env_file: + - .env + volumes: + # Mount logs directory if you want to persist logs + - ./logs:/app/logs + # Uncomment if you need to expose a port for health checks + # ports: + # - "3000:3000" + # Health check (optional) + healthcheck: + test: ["CMD", "node", "-e", "process.exit(0)"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s