Use uv and a multi-stage build for docker image

This commit is contained in:
Yiorgis Gozadinos 2025-10-15 13:58:14 +03:00
parent aa9b5f7b0c
commit 121c3cce90
No known key found for this signature in database
2 changed files with 33 additions and 23 deletions

View file

@ -19,8 +19,11 @@ wheels/
*.egg-info/ *.egg-info/
.installed.cfg .installed.cfg
*.egg *.egg
# Virtual environments (uv best practice)
.venv/ .venv/
venv/ venv/
env/
# Data # Data
*.lancedb/ *.lancedb/
@ -42,6 +45,11 @@ Thumbs.db
.git/ .git/
.gitignore .gitignore
# Development
tests/
.pytest_cache/
.coverage
htmlcov/
# Examples # Examples
examples/docker/data/ examples/
examples/docker/docs/

View file

@ -1,34 +1,36 @@
# Use Python 3.12 slim image # syntax=docker/dockerfile:1
FROM python:3.12-slim FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS builder
# Set working directory
WORKDIR /app WORKDIR /app
# Install system dependencies required for building Python packages # Enable bytecode compilation for faster startup
RUN apt-get update && apt-get install -y \ ENV UV_COMPILE_BYTECODE=1 \
build-essential \ UV_LINK_MODE=copy
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# Install uv for fast Python package management # Install dependencies into a venv
RUN curl -LsSf https://astral.sh/uv/install.sh | sh COPY pyproject.toml uv.lock ./
ENV PATH="/root/.local/bin:$PATH" RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-install-project --extra voyageai --extra mxbai --extra a2a
# Copy project files # Install the project itself
COPY . /app COPY . .
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-editable --extra voyageai --extra mxbai --extra a2a
# Install haiku.rag with all extras in development mode # Final layer
RUN uv pip install --system -e ".[voyageai,mxbai,a2a]" FROM python:3.13-slim
WORKDIR /app
# Create data directory for the database COPY --from=builder /app/.venv /app/.venv
RUN mkdir -p /data COPY --from=builder /app /app
# Set default data directory # Set default data directory
RUN mkdir -p /data
ENV DEFAULT_DATA_DIR=/data ENV DEFAULT_DATA_DIR=/data
ENV PATH="/app/.venv/bin:$PATH"
# Expose ports for MCP and A2A # Expose ports for MCP and A2A
EXPOSE 8000 8001 EXPOSE 8000 8001
# Default command runs all services (monitoring, MCP, A2A) # Run 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"] CMD ["python", "-m", "haiku.rag.cli", "serve", "--monitor", "--mcp", "--mcp-port", "8001", "--a2a", "--a2a-host", "0.0.0.0", "--a2a-port", "8000", "--db", "/data/haiku.rag.lancedb"]