-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathdockerfile
More file actions
200 lines (171 loc) · 6.2 KB
/
dockerfile
File metadata and controls
200 lines (171 loc) · 6.2 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# syntax=docker/dockerfile:1
# Purpose: Production Docker image for Morphik Core
# This file builds the official Morphik image that gets published to ghcr.io
# It includes all dependencies and uses start_server.py which reads config from morphik.toml
# Used by: GitHub Actions (docker-publish.yml) and developers building locally
# Build stage
FROM python:3.11.12-slim AS builder
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Set working directory
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
cmake \
python3-dev \
git \
&& rm -rf /var/lib/apt/lists/*
# Install Rust using the simpler method
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
# Activating cargo env for this RUN instruction and subsequent ones in this stage.
ENV PATH="/root/.cargo/bin:${PATH}"
# Set uv environment variables
ENV UV_LINK_MODE=copy
ENV UV_CACHE_DIR=/root/.cache/uv
ENV VIRTUAL_ENV=/app/.venv
ENV PATH="/app/.venv/bin:${PATH}"
# Copy project definition and lock file
COPY pyproject.toml uv.lock ./
COPY fde ./fde
COPY morphik_rust ./morphik_rust
# Create venv and install dependencies from lockfile (excluding the project itself initially for better caching)
# This also creates the /app/.venv directory
# morphik-rust is a required dependency - Rust toolchain installed above
RUN --mount=type=cache,target=${UV_CACHE_DIR} \
uv sync --verbose --locked --no-install-project
# Copy the rest of the application code
# Assuming start_server.py is at the root or handled by pyproject.toml structure.
COPY . .
# Copy the UI component (including it in the image for optional use)
# This ensures the UI is available when users want to enable it
COPY ee/ui-component /app/ee/ui-component
# Install the project itself into the venv in non-editable mode
RUN --mount=type=cache,target=${UV_CACHE_DIR} \
uv sync --verbose --locked --no-editable
# Enable backports and install GCC 11+ for Debian Bookworm
RUN echo "deb http://deb.debian.org/debian bookworm-backports main" > /etc/apt/sources.list.d/backports.list && \
apt-get update && \
apt-get install -y -t bookworm-backports gcc-11 g++-11 && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
# Production stage
FROM python:3.11.12-slim
# Set working directory
WORKDIR /app
# Install runtime dependencies
# Note: tesseract-ocr removed - docling uses rapidocr (pure Python) instead
# LibreOffice needed for ColPali processing of Office docs (docx/xlsx/pptx -> PDF -> images)
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
libsm6 \
libxext6 \
libmagic1 \
libcairo2 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libpangoft2-1.0-0 \
libgdk-pixbuf-2.0-0 \
libffi8 \
libxml2 \
libxslt1.1 \
libjpeg62-turbo \
libopenjp2-7 \
fonts-dejavu-core \
postgresql-client \
poppler-utils \
gcc \
g++ \
cmake \
python3-dev \
git \
libreoffice-writer \
libreoffice-calc \
libreoffice-impress \
&& rm -rf /var/lib/apt/lists/*
# Copy the virtual environment from the builder stage
COPY --from=builder /app/.venv /app/.venv
# Copy uv binaries from the builder stage
COPY --from=builder /bin/uv /bin/uv
COPY --from=builder /bin/uvx /bin/uvx
## copy fde package to avoid error at server startup
COPY --from=builder /app/fde ./fde
## copy morphik_rust package (path dependency in pyproject.toml)
COPY --from=builder /app/morphik_rust ./morphik_rust
# Create necessary directories
RUN mkdir -p storage logs
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV VIRTUAL_ENV=/app/.venv
ENV PATH="/app/.venv/bin:/usr/local/bin:${PATH}"
# Create default configuration
COPY morphik.docker.toml /app/morphik.toml.default
# Create startup script
RUN echo '#!/bin/bash\n\
set -e\n\
\n\
# Copy default config if none exists\n\
if [ ! -f /app/morphik.toml ]; then\n\
cp /app/morphik.toml.default /app/morphik.toml\n\
fi\n\
\n\
# Function to check PostgreSQL\n\
check_postgres() {\n\
if [ -n "$POSTGRES_URI" ]; then\n\
echo "Waiting for PostgreSQL..."\n\
max_retries=30\n\
retries=0\n\
until PGPASSWORD=$PGPASSWORD pg_isready -h postgres -U morphik -d morphik; do\n\
retries=$((retries + 1))\n\
if [ $retries -eq $max_retries ]; then\n\
echo "Error: PostgreSQL did not become ready in time"\n\
exit 1\n\
fi\n\
echo "Waiting for PostgreSQL... (Attempt $retries/$max_retries)"\n\
sleep 2\n\
done\n\
echo "PostgreSQL is ready!"\n\
\n\
# Verify database connection\n\
if ! PGPASSWORD=$PGPASSWORD psql -h postgres -U morphik -d morphik -c "SELECT 1" > /dev/null 2>&1; then\n\
echo "Error: Could not connect to PostgreSQL database"\n\
exit 1\n\
fi\n\
echo "PostgreSQL connection verified!"\n\
fi\n\
}\n\
\n\
# Check PostgreSQL\n\
check_postgres\n\
\n\
# Check if command arguments were passed ($# is the number of arguments)\n\
if [ $# -gt 0 ]; then\n\
# If arguments exist, execute them (e.g., execute "arq core.workers...")\n\
exec "$@"\n\
else\n\
# Otherwise, execute the default command (uv run start_server.py)\n\
exec uv run start_server.py --skip-redis-check\n\
fi\n\
' > /app/docker-entrypoint.sh && chmod +x /app/docker-entrypoint.sh
# Copy application code
# pyproject.toml is needed for uv to identify the project context for `uv run`
COPY pyproject.toml uv.lock ./
## copy the fde package also to fix distribution not found error
COPY fde ./fde
COPY core ./core
COPY ee ./ee
COPY utils ./utils
COPY README.md LICENSE ./
# Assuming start_server.py is at the root of your project
COPY start_server.py ./
# Labels for the image
LABEL org.opencontainers.image.title="Morphik Core"
LABEL org.opencontainers.image.description="Morphik Core - A powerful document processing and retrieval system"
LABEL org.opencontainers.image.source="https://github.com/morphik-org/morphik-core"
LABEL org.opencontainers.image.version="1.0.0"
LABEL org.opencontainers.image.licenses="MIT"
# Expose port
EXPOSE 8000
# Set the entrypoint
ENTRYPOINT ["/app/docker-entrypoint.sh"]