forked from johnfkraus/docsray-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
155 lines (127 loc) · 4.96 KB
/
Dockerfile
File metadata and controls
155 lines (127 loc) · 4.96 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Multi-stage Dockerfile for Docsray MCP Server
# Best practices for containerized MCP servers
# ============================================================================
# Build stage
# ============================================================================
FROM python:3.11-slim AS builder
# Set build arguments
ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG TARGETARCH
# Install system dependencies required for building
RUN apt-get update && apt-get install -y \
build-essential \
gcc \
g++ \
git \
ca-certificates \
&& update-ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /build
# Copy dependency files first (for better caching)
COPY pyproject.toml ./
COPY README.md ./
COPY LICENSE ./
COPY src/ ./src/
# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Set pip trusted hosts for environments with SSL issues
ENV PIP_TRUSTED_HOST="pypi.org files.pythonhosted.org"
# Install Python dependencies
# Use --trusted-host as fallback for environments with SSL issues
RUN (pip install --no-cache-dir --upgrade pip setuptools wheel || \
pip install --trusted-host $PIP_TRUSTED_HOST --no-cache-dir --upgrade pip setuptools wheel) && \
(pip install --no-cache-dir -e . || \
pip install --trusted-host $PIP_TRUSTED_HOST --no-cache-dir -e .)
# ============================================================================
# Runtime stage
# ============================================================================
FROM python:3.11-slim AS runtime
# Set metadata labels
LABEL org.opencontainers.image.title="Docsray MCP Server"
LABEL org.opencontainers.image.description="AI-powered document perception and analysis MCP server"
LABEL org.opencontainers.image.version="0.3.3"
LABEL org.opencontainers.image.authors="Docsray Team <team@docsray.dev>"
LABEL org.opencontainers.image.url="https://docsray.dev"
LABEL org.opencontainers.image.source="https://github.com/xingh/docsray-mcp"
LABEL org.opencontainers.image.licenses="Apache-2.0"
# Install runtime system dependencies
RUN apt-get update && apt-get install -y \
# Essential runtime libraries
libgcc-s1 \
libstdc++6 \
# OCR dependencies (optional)
tesseract-ocr \
tesseract-ocr-eng \
poppler-utils \
# Image processing
libimage-exiftool-perl \
# PaddleOCR dependencies (for local builds)
libgl1 \
libglib2.0-0 \
# Networking and security
ca-certificates \
curl \
# Cleanup
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Create non-root user for security
RUN groupadd -r docsray && useradd -r -g docsray -d /app -s /bin/bash docsray
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Set pip trusted hosts for environments with SSL issues
ENV PIP_TRUSTED_HOST="pypi.org files.pythonhosted.org"
# Set working directory and copy source code
WORKDIR /app
COPY --chown=docsray:docsray . .
# Install the package in the runtime environment with optional dependencies
# Users can enable/disable providers via environment variables
# Use --trusted-host as fallback for environments with SSL issues
RUN pip install --no-cache-dir -e ".[ocr,ai,remote-ai]" || \
pip install --trusted-host $PIP_TRUSTED_HOST --no-cache-dir -e ".[ocr,ai,remote-ai]"
# Create directories for data and cache
RUN mkdir -p /app/data /app/cache /app/logs && \
chown -R docsray:docsray /app
# Switch to non-root user
USER docsray
# Set environment variables for production
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH="/app/src" \
DOCSRAY_CACHE_DIR="/app/cache" \
DOCSRAY_LOG_LEVEL="INFO" \
DOCSRAY_TRANSPORT="stdio"
# Expose port for HTTP mode (if needed)
EXPOSE 3000
# Health check for HTTP mode
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3000/health || exit 1
# Default command - can be overridden
CMD ["docsray", "start"]
# ============================================================================
# Development stage (optional)
# ============================================================================
FROM runtime AS development
# Switch back to root to install dev dependencies
USER root
# Install development tools
RUN apt-get update && apt-get install -y \
git \
vim \
nano \
htop \
&& rm -rf /var/lib/apt/lists/*
# Install development Python packages (including PaddleOCR for local testing)
# Use --trusted-host as fallback for environments with SSL issues
RUN (pip install --no-cache-dir -e ".[dev,ocr,ai,remote-ai]" || \
pip install --trusted-host $PIP_TRUSTED_HOST --no-cache-dir -e ".[dev,ocr,ai,remote-ai]") && \
(pip install --no-cache-dir paddleocr paddlepaddle pdf2image || \
pip install --trusted-host $PIP_TRUSTED_HOST --no-cache-dir paddleocr paddlepaddle pdf2image || true)
# Switch back to docsray user
USER docsray
# Override for development
ENV DOCSRAY_LOG_LEVEL="DEBUG"
CMD ["docsray", "start", "--verbose"]