-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile.production
More file actions
209 lines (178 loc) · 6.12 KB
/
Copy pathDockerfile.production
File metadata and controls
209 lines (178 loc) · 6.12 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
201
202
203
204
205
206
207
208
209
# MUXI Runtime - Production Image with Services
# Includes PostgreSQL, FAISSx, and full service stack
FROM python:3.13-slim
LABEL maintainer="Ran Aroussi <ran@aroussi.com>"
LABEL description="MUXI Runtime - Production container with PostgreSQL and FAISSx"
LABEL version="1.0.0-production"
# Add PostgreSQL APT repository for version 17
RUN apt-get update && apt-get install -y gnupg wget lsb-release \
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/postgresql-keyring.gpg \
&& echo "deb [signed-by=/usr/share/keyrings/postgresql-keyring.gpg] http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
# Install system dependencies
RUN apt-get update && apt-get install -y \
# PostgreSQL 17 and pgvector extension
postgresql-17 \
postgresql-client-17 \
postgresql-17-pgvector \
# Build dependencies
build-essential \
gcc \
g++ \
make \
# System utilities
curl \
wget \
git \
supervisor \
netcat-openbsd \
# Image processing
poppler-utils \
tesseract-ocr \
# Audio/Video processing
ffmpeg \
# Magic file detection
libmagic1 \
&& rm -rf /var/lib/apt/lists/*
# Set PostgreSQL environment
ENV PGDATA=/var/lib/postgresql/17/main
ENV PATH="/usr/lib/postgresql/17/bin:${PATH}"
# Create necessary directories
RUN mkdir -p /app /data /logs /var/run/postgresql /var/lib/postgresql/17 \
&& chown -R postgres:postgres /var/lib/postgresql /var/run/postgresql /logs
# Set working directory
WORKDIR /app
# Copy requirements and source
COPY requirements.txt pyproject.toml setup.py ./
COPY src ./src
COPY e2e/assets/faissx-auth.json ./faissx-auth.json
# Note: schemas and context are symlinks outside build context
# They're not needed at runtime - only for development reference
# Install uv for faster package management
RUN pip install --no-cache-dir uv
# Install all Python packages
RUN uv pip install --system \
faissx \
fastapi \
uvicorn \
httpx \
aiofiles \
&& uv pip install --system -r requirements.txt \
&& uv pip install --system -e .
# Download spaCy model
RUN python -m spacy download en_core_web_sm || true
# Initialize PostgreSQL database
USER postgres
RUN rm -rf /var/lib/postgresql/17/main/* 2>/dev/null || true \
&& /usr/lib/postgresql/17/bin/initdb -D /var/lib/postgresql/17/main \
&& echo "listen_addresses = '*'" >> /var/lib/postgresql/17/main/postgresql.conf \
&& echo "max_connections = 200" >> /var/lib/postgresql/17/main/postgresql.conf \
&& echo "shared_buffers = 256MB" >> /var/lib/postgresql/17/main/postgresql.conf \
&& echo "host all all 0.0.0.0/0 trust" >> /var/lib/postgresql/17/main/pg_hba.conf \
&& echo "local all all trust" >> /var/lib/postgresql/17/main/pg_hba.conf \
&& /usr/lib/postgresql/17/bin/pg_ctl -D /var/lib/postgresql/17/main -l /tmp/postgres.log start \
&& sleep 5 \
&& createdb muxi \
&& createuser muxi \
&& psql -c "GRANT ALL PRIVILEGES ON DATABASE muxi TO muxi;" \
&& psql -d muxi -c "GRANT CREATE ON SCHEMA public TO muxi;" \
&& psql -d muxi -c "GRANT ALL ON SCHEMA public TO muxi;" \
&& psql -d muxi -c "CREATE EXTENSION IF NOT EXISTS vector;" \
&& /usr/lib/postgresql/17/bin/pg_ctl -D /var/lib/postgresql/17/main stop
USER root
# Create supervisor configuration
RUN cat > /etc/supervisor/conf.d/supervisord.conf <<'EOF'
[supervisord]
nodaemon=true
logfile=/logs/supervisord.log
pidfile=/var/run/supervisord.pid
[program:postgresql]
command=/usr/lib/postgresql/17/bin/postgres -D /var/lib/postgresql/17/main
user=postgres
autostart=true
autorestart=true
stdout_logfile=/logs/postgresql.log
stderr_logfile=/logs/postgresql.err
priority=1
[program:faissx-no-auth]
command=faissx.server run --port 45678
directory=/app
autostart=true
autorestart=true
stdout_logfile=/logs/faissx-no-auth.log
stderr_logfile=/logs/faissx-no-auth.err
priority=10
[program:faissx-with-auth]
command=faissx.server run --port 65432 --enable-auth --auth-file /app/faissx-auth.json
directory=/app
autostart=true
autorestart=true
stdout_logfile=/logs/faissx-with-auth.log
stderr_logfile=/logs/faissx-with-auth.err
priority=10
EOF
# Create health check script
RUN cat > /app/healthcheck.sh <<'EOF'
#!/bin/bash
# Check PostgreSQL
psql -U muxi -d muxi -c 'SELECT 1' > /dev/null 2>&1 || exit 1
# Check FAISSx ports are open
nc -z localhost 45678 || exit 1
nc -z localhost 65432 || exit 1
# Check if formation server is running (if started)
if pgrep -f "muxi.server" > /dev/null; then
curl -f http://localhost:8000/health || exit 1
fi
exit 0
EOF
RUN chmod +x /app/healthcheck.sh
# Create entrypoint script
RUN cat > /app/entrypoint.sh <<'EOF'
#!/bin/bash
set -e
echo "Starting MUXI Runtime (Production)..."
# Start supervisor in background
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf &
SUPERVISOR_PID=$!
# Wait for PostgreSQL
echo "Waiting for PostgreSQL..."
for i in {1..30}; do
if psql -U muxi -h localhost -d muxi -c 'SELECT 1' > /dev/null 2>&1; then
echo "✅ PostgreSQL is ready"
break
fi
sleep 2
done
# Wait for FAISSx
echo "Waiting for FAISSx..."
for i in {1..30}; do
if nc -z localhost 45678 && nc -z localhost 65432; then
echo "✅ FAISSx is ready"
break
fi
sleep 2
done
echo "✅ All services ready!"
# If command provided, run it; otherwise start formation server
if [ $# -gt 0 ]; then
exec "$@"
else
echo "Starting MUXI formation server..."
exec python -m muxi.server
fi
EOF
RUN chmod +x /app/entrypoint.sh
# Environment variables
ENV POSTGRES_URI=postgresql://muxi:muxi_password@localhost:5432/muxi
ENV FAISSX_NO_AUTH_URL=http://localhost:45678
ENV FAISSX_WITH_AUTH_URL=http://localhost:65432
ENV PYTHONPATH=/app/src:/app:$PYTHONPATH
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Expose ports
EXPOSE 5432 45678 65432 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD /app/healthcheck.sh
# Entrypoint
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["python", "-m", "muxi.server"]