From 1d69de3f8fe5b913d90957b0aa30eb29fec4b1ab Mon Sep 17 00:00:00 2001 From: Rafi Al Attrach Date: Thu, 23 Oct 2025 22:45:30 +0200 Subject: [PATCH] Add Docker support for m3 - Add Dockerfile with multi-stage build (lite + bigquery targets) - Add .dockerignore to exclude webapp/benchmarks - Update README with Docker installation instructions - Supports both SQLite (baked-in demo DB) and BigQuery backends - Works from fresh clone (m3 init runs during build) - Tested: 51 existing tests pass, both Docker targets work --- .dockerignore | 16 ++++++++++++++++ Dockerfile | 35 +++++++++++++++++++++++++++++++++++ README.md | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c3d8450 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +.git +__pycache__ +*.pyc +.venv +.env +webapp/ +benchmarks/ +coverage.xml +.pytest_cache/ +dist/ +build/ +*.egg-info +# Keep only the demo DB +m3_data/** +!m3_data/databases/ +!m3_data/databases/mimic_iv_demo.db diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..99ef59e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +# syntax=docker/dockerfile:1 + +# Build stage: create wheel +FROM python:3.11-slim AS builder + +WORKDIR /build +COPY pyproject.toml uv.lock README.md ./ +COPY src ./src + +RUN pip install --no-cache-dir build && \ + python -m build --wheel + +# Base runtime: install m3 and baked SQLite DB +FROM python:3.11-slim AS base + +ENV PYTHONUNBUFFERED=1 \ + M3_BACKEND=sqlite \ + M3_DB_PATH=/root/m3_data/databases/mimic_iv_demo.db + +WORKDIR /app + +COPY --from=builder /build/dist/*.whl /tmp/ +RUN pip install --no-cache-dir /tmp/*.whl && rm /tmp/*.whl + +# Download and initialize demo DB using m3 init +RUN m3 init mimic-iv-demo + +# Lite: SQLite only +FROM base AS lite +CMD ["python", "-m", "m3.mcp_server"] + +# BigQuery: add GCP client +FROM base AS bigquery +RUN pip install --no-cache-dir google-cloud-bigquery +CMD ["python", "-m", "m3.mcp_server"] diff --git a/README.md b/README.md index 6bac964..48eae07 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,40 @@ source .venv/bin/activate # Windows: .venv\Scripts\activate pip install m3-mcp ``` -#### Option B: Install from Source +#### Option B: Docker + +```bash +# Clone repo first +git clone https://github.com/rafiattrach/m3.git && cd m3 + +# SQLite (demo DB) +docker build -t m3:lite --target lite . +docker run -d --name m3-server m3:lite tail -f /dev/null + +# BigQuery (full dataset - requires GCP credentials) +docker build -t m3:bigquery --target bigquery . +docker run -d --name m3-server \ + -e M3_BACKEND=bigquery \ + -e M3_PROJECT_ID=YOUR_PROJECT_ID \ + -v $HOME/.config/gcloud:/root/.config/gcloud:ro \ + m3:bigquery tail -f /dev/null +``` + +**MCP client config** (Claude Desktop, LM Studio, etc.): +```json +{ + "mcpServers": { + "m3": { + "command": "docker", + "args": ["exec", "-i", "m3-server", "python", "-m", "m3.mcp_server"] + } + } +} +``` + +Stop container: `docker stop m3-server && docker rm m3-server` + +#### Option C: Install from Source #### Using standard `pip` **Step 1: Clone and Navigate**