From 48dbf5ff59fd4b1d1a98b888447cd55ce21de5c0 Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Wed, 15 Oct 2025 12:30:55 +0300 Subject: [PATCH] Basic docker container building & example for running haiku.rag in docker compose --- docker/.dockerignore | 47 +++++++++++++++++++++++ docker/Dockerfile | 34 +++++++++++++++++ docker/README.md | 27 ++++++++++++++ examples/README.md | 11 ++++++ examples/docker/.env.example | 16 ++++++++ examples/docker/.gitignore | 8 ++++ examples/docker/README.md | 44 ++++++++++++++++++++++ examples/docker/docker-compose.yml | 60 ++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 9 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 docker/.dockerignore create mode 100644 docker/Dockerfile create mode 100644 docker/README.md create mode 100644 examples/docker/.env.example create mode 100644 examples/docker/.gitignore create mode 100644 examples/docker/README.md create mode 100644 examples/docker/docker-compose.yml diff --git a/docker/.dockerignore b/docker/.dockerignore new file mode 100644 index 00000000..808bad58 --- /dev/null +++ b/docker/.dockerignore @@ -0,0 +1,47 @@ +# Python +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +.venv/ +venv/ + +# Data +*.lancedb/ +data/ +docs/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS +.DS_Store +Thumbs.db + +# Git +.git/ +.gitignore + +# Examples +examples/docker/data/ +examples/docker/docs/ diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..5a86afe5 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,34 @@ +# Use Python 3.12 slim image +FROM python:3.12-slim + +# Set working directory +WORKDIR /app + +# Install system dependencies required for building Python packages +RUN apt-get update && apt-get install -y \ + build-essential \ + curl \ + git \ + && rm -rf /var/lib/apt/lists/* + +# Install uv for fast Python package management +RUN curl -LsSf https://astral.sh/uv/install.sh | sh +ENV PATH="/root/.local/bin:$PATH" + +# Copy project files +COPY . /app + +# Install haiku.rag with all extras in development mode +RUN uv pip install --system -e ".[voyageai,mxbai,a2a]" + +# Create data directory for the database +RUN mkdir -p /data + +# Default database path +ENV HAIKU_RAG_DB_PATH=/data/haiku.rag.lancedb + +# Expose ports for MCP and A2A +EXPOSE 8000 8001 + +# Default command runs all services (monitoring, MCP, A2A) +CMD ["haiku-rag", "serve", "--monitor", "--mcp", "--mcp-port", "8001", "--a2a", "--a2a-host", "0.0.0.0", "--a2a-port", "8000", "--db", "/data/haiku.rag.lancedb"] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..bc621886 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,27 @@ +# haiku.rag Docker Image + +Dockerfile for building haiku.rag with all extras (voyageai, mxbai, a2a). + +## Building + +```bash +docker build -f docker/Dockerfile -t haiku-rag . +``` + +## Running + +```bash +docker run -p 8000:8000 -p 8001:8001 \ + -v $(pwd)/data:/data \ + -e EMBEDDINGS_PROVIDER=ollama \ + -e EMBEDDINGS_MODEL=nomic-embed-text \ + -e QA_PROVIDER=ollama \ + -e QA_MODEL=qwen3\ + haiku-rag +``` + +Note: The environment variables above override the defaults. See [Configuration docs](https://ggozad.github.io/haiku.rag/configuration/) for all options. + +## Docker Compose + +See `examples/docker/` for a complete setup example. diff --git a/examples/README.md b/examples/README.md index 2e00c386..e3e3d7f0 100644 --- a/examples/README.md +++ b/examples/README.md @@ -2,6 +2,17 @@ This directory contains example scripts demonstrating various features of haiku.rag. +## Docker Example + +**Directory:** `docker/` + +Complete Docker setup for running haiku.rag with all services: +- File monitoring for automatic document indexing +- MCP server for AI assistant integration +- A2A agent for conversational interactions + +See `docker/README.md` for setup instructions. + ## A2A Security Examples **Directory:** `a2a-security/` diff --git a/examples/docker/.env.example b/examples/docker/.env.example new file mode 100644 index 00000000..8a4fe115 --- /dev/null +++ b/examples/docker/.env.example @@ -0,0 +1,16 @@ +# Database +HAIKU_RAG_DB_PATH=/data/haiku.rag.lancedb + +# File monitoring +MONITOR_DIRECTORIES=/docs + +# Default: Ollama on host +EMBEDDINGS_PROVIDER=ollama +EMBEDDINGS_MODEL=nomic-embed-text +QA_PROVIDER=ollama +QA_MODEL=qwen3 +OLLAMA_BASE_URL=http://host.docker.internal:11434 + +# For other providers, see: https://ggozad.github.io/haiku.rag/configuration/ + +ENV=production diff --git a/examples/docker/.gitignore b/examples/docker/.gitignore new file mode 100644 index 00000000..11476b40 --- /dev/null +++ b/examples/docker/.gitignore @@ -0,0 +1,8 @@ +# Data directory +data/ + +# Documents directory +docs/ + +# Environment file with secrets +.env diff --git a/examples/docker/README.md b/examples/docker/README.md new file mode 100644 index 00000000..239fede4 --- /dev/null +++ b/examples/docker/README.md @@ -0,0 +1,44 @@ +# haiku.rag Docker Compose Example + +Run haiku.rag with file monitoring, MCP server, and A2A agent. + +## Quick Start + +```bash +mkdir -p data docs +cp .env.example .env # Edit if needed +docker compose up -d +``` + +Place documents in `docs/` for automatic indexing. + +## Usage + +```bash +# Search +docker compose exec haiku-rag haiku-rag search "your query" + +# Ask questions +docker compose exec haiku-rag haiku-rag ask "What is haiku.rag?" + +# A2A interactive client +docker compose exec haiku-rag haiku-rag a2aclient --url http://localhost:8000 +``` + +## Ports + +- `8000` - A2A agent +- `8001` - MCP server + +## Configuration + +Edit `.env` or `docker-compose.yml` to configure providers. See the [Configuration documentation](https://ggozad.github.io/haiku.rag/configuration/) for all options. + +Default setup uses Ollama on the host (`host.docker.internal:11434`). + +## Documentation + +- [Configuration](https://ggozad.github.io/haiku.rag/configuration/) +- [CLI Commands](https://ggozad.github.io/haiku.rag/cli/) +- [MCP Server](https://ggozad.github.io/haiku.rag/mcp/) +- [A2A Agent](https://ggozad.github.io/haiku.rag/a2a/) diff --git a/examples/docker/docker-compose.yml b/examples/docker/docker-compose.yml new file mode 100644 index 00000000..45cb76d0 --- /dev/null +++ b/examples/docker/docker-compose.yml @@ -0,0 +1,60 @@ +services: + haiku-rag: + build: + context: ../.. + dockerfile: docker/Dockerfile + container_name: haiku-rag + ports: + - "8000:8000" # A2A server + - "8001:8001" # MCP server + volumes: + - ./data:/data # Persist database + - ./docs:/docs # Mount documents directory for monitoring + environment: + # Database + - HAIKU_RAG_DB_PATH=/data/haiku.rag.lancedb + + # File monitoring + - MONITOR_DIRECTORIES=/docs + + # Set the Ollama base url for Ollama defaults + - OLLAMA_BASE_URL=http://host.docker.internal:11434 + + # Embeddings provider (choose one) + # For OpenAI: + # - EMBEDDINGS_PROVIDER=openai + # - EMBEDDINGS_MODEL=text-embedding-3-small + # - OPENAI_API_KEY=your-key-here + + # For VoyageAI: + # - EMBEDDINGS_PROVIDER=voyageai + # - EMBEDDINGS_MODEL=voyage-3 + # - VOYAGE_API_KEY=your-key-here + + # QA provider (uses Pydantic AI) + # - QA_PROVIDER=ollama + + # For OpenAI: + # - QA_PROVIDER=openai + # - QA_MODEL=gpt-4o-mini + # - OPENAI_API_KEY=your-key-here + + # Reranking (optional) + # - RERANKING_PROVIDER=mxbai + # - RERANKING_MODEL=mixedbread-ai/mxbai-rerank-large-v1 + # - RERANKING_BASE_URL=http://host.docker.internal:11434 + + # Research agent (optional, defaults to QA provider/model) + # - RESEARCH_PROVIDER=openai + # - RESEARCH_MODEL=gpt-4o + + # Environment + - ENV=production + + restart: unless-stopped + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8000/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s diff --git a/pyproject.toml b/pyproject.toml index f04b8c82..8c61b7b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,7 @@ requires = ["hatchling"] build-backend = "hatchling.build" [tool.hatch.build] -exclude = ["/docs", "/examples", "/tests", "/.github"] +exclude = ["/docs", "/examples", "/tests", "/docker", "/.github"] [tool.hatch.build.targets.wheel] packages = ["src/haiku"]