-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathDockerfile
More file actions
76 lines (59 loc) Β· 2.93 KB
/
Copy pathDockerfile
File metadata and controls
76 lines (59 loc) Β· 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# =============================================================================
# Chonkie OSS API β Dockerfile
# Multi-stage build: builder stage installs dependencies, final stage is lean.
# =============================================================================
# ---------------------------------------------------------------------------
# Stage 1 β builder
# ---------------------------------------------------------------------------
FROM python:3.11-slim AS builder
WORKDIR /build
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Copy pyproject.toml and src/ for installation
COPY pyproject.toml .
COPY src/ ./src/
# Create a virtual environment and install Chonkie with API dependencies
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN pip install --upgrade pip && \
pip install --no-cache-dir .[api,semantic,code,openai,catsu]
# ---------------------------------------------------------------------------
# Stage 2 β runtime
# ---------------------------------------------------------------------------
FROM python:3.11-slim AS runtime
WORKDIR /app
# Install only runtime system libraries (tree-sitter requires no extras)
RUN apt-get update && apt-get install -y --no-install-recommends \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# Copy the virtual environment from the builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Note: API is now included in the chonkie package installation from builder stage
# No separate COPY needed - chonkie.api is part of the installed package
# Create data directory for SQLite database
RUN mkdir -p /app/data
# Non-root user for security (no home dir, no shell for reduced attack surface)
RUN useradd --no-create-home --shell /sbin/nologin chonkie && \
chown -R chonkie:chonkie /app/data
USER chonkie
# Expose the default API port
EXPOSE 8000
# Health check so container orchestrators can verify the service is up
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"
# ---------------------------------------------------------------------------
# Runtime configuration (override with -e / docker-compose environment:)
# ---------------------------------------------------------------------------
ENV LOG_LEVEL="INFO"
ENV CORS_ORIGINS="*"
# Point HuggingFace cache into the mounted data volume so the non-root
# chonkie user (created with --no-create-home) has a writable cache dir.
ENV HF_HOME="/app/data/huggingface"
# OPENAI_API_KEY β required only if you use /v1/refine/embeddings
# ---------------------------------------------------------------------------
# Start the server
# ---------------------------------------------------------------------------
CMD ["uvicorn", "chonkie.api.main:app", "--host", "0.0.0.0", "--port", "8000"]