-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
140 lines (115 loc) · 5.37 KB
/
Dockerfile
File metadata and controls
140 lines (115 loc) · 5.37 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
# MUXI Runtime - Optimized Multi-Stage Build
# This creates a much smaller image by separating build and runtime stages
# ============================================================================
# Stage 1: Builder - Install dependencies and compile
# ============================================================================
FROM python:3.10-slim AS builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
build-essential \
gcc \
g++ \
git \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /build
# Install uv for fast package management
RUN pip install --no-cache-dir uv
# Copy dependency files
COPY requirements.txt pyproject.toml setup.py ./
# Install PyTorch CPU-only version first (avoids 4GB+ CUDA dependencies)
# This must be done before other requirements to prevent CUDA version from being pulled
RUN uv pip install --prefix=/install --no-cache \
torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
# Install all dependencies to a temporary location
# This includes compiling binary extensions
RUN uv pip install --prefix=/install --no-cache -r requirements.txt
# Copy source and install MUXI
COPY src ./src
RUN uv pip install --prefix=/install --no-cache -e .
# Fix sqlite-vec: the published aarch64 wheel ships a 32-bit ARM binary.
# Compile the correct 64-bit shared library from the amalgamation source.
# Need libsqlite3-dev for sqlite3ext.h header.
RUN ARCH=$(uname -m) && \
if [ "$ARCH" = "aarch64" ]; then \
echo "Compiling sqlite-vec for aarch64..." && \
apt-get update && apt-get install -y --no-install-recommends libsqlite3-dev && \
VEC_VERSION="0.1.7-alpha.10" && \
python -c "import urllib.request; urllib.request.urlretrieve('https://github.com/asg017/sqlite-vec/releases/download/v${VEC_VERSION}/sqlite-vec-${VEC_VERSION}-amalgamation.tar.gz', 'sqlite-vec.tar.gz')" && \
echo "c50a6caef46eb32e99f69f1b26808a2e28043b358c9513fed3846ce4776e5ee1 sqlite-vec.tar.gz" | sha256sum -c - && \
tar xzf sqlite-vec.tar.gz && \
gcc -O2 -fPIC -shared sqlite-vec.c -o vec0.so && \
PYVER=$(python -c "import sys; print(f'python{sys.version_info.major}.{sys.version_info.minor}')") && \
cp vec0.so /install/lib/${PYVER}/site-packages/sqlite_vec/vec0.so && \
echo "sqlite-vec compiled and installed for aarch64" && \
rm -f sqlite-vec.tar.gz sqlite-vec.c sqlite-vec.h vec0.so && \
apt-get purge -y libsqlite3-dev && apt-get autoremove -y && rm -rf /var/lib/apt/lists/*; \
else \
echo "sqlite-vec: skipping recompilation for $ARCH"; \
fi
# Note: Skipping spaCy model download to save ~45MB
# Can be downloaded at runtime if needed: python -m spacy download en_core_web_sm
# ============================================================================
# Stage 2: Runtime - Minimal runtime environment
# ============================================================================
FROM python:3.10-slim
LABEL maintainer="Ran Aroussi <ran@aroussi.com>"
LABEL description="MUXI Runtime - Optimized container for AI agent formations"
LABEL version="1.0.0"
# Install ONLY runtime system dependencies (no build tools!)
RUN apt-get update && apt-get install -y \
# Runtime utilities (not build tools)
curl \
wget \
# Image processing (runtime only)
poppler-utils \
tesseract-ocr \
# Media processing
ffmpeg \
# File type detection
libmagic1 \
# Clean up
&& rm -rf /var/lib/apt/lists/* \
&& apt-get autoremove -y \
&& apt-get clean
# Set working directory
WORKDIR /app
# Copy Python packages from builder
COPY --from=builder /install /usr/local
# Copy MUXI source
COPY --from=builder /build/src ./src
# Clean up to reduce image size
# Note: numpy._core.tests is imported at runtime by numpy 2.x (for pd_NA),
# so we must preserve it while removing other test directories.
RUN find /usr/local -name "*.pyc" -delete \
&& find /usr/local -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true \
&& find /usr/local -name "*.pyo" -delete \
&& find /usr/local -name "tests" -type d -not -path "*/numpy/_core/tests" -exec rm -rf {} + 2>/dev/null || true \
&& rm -rf /root/.cache /tmp/*
# Pre-download the sentence-transformers model used by OneLLM cache.
# Without this, the first formation startup downloads ~118MB from HuggingFace,
# adding ~80s to cold-start time inside SIF containers.
# Stored in /opt/hf-cache (not /root/.cache) because Singularity mounts the
# host home directory over /root, hiding anything baked into the image there.
ENV HF_HOME=/opt/hf-cache
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('paraphrase-multilingual-MiniLM-L12-v2'); SentenceTransformer('all-MiniLM-L6-v2')"
# Create necessary directories
RUN mkdir -p /data /logs /formations ~/.muxi
# Copy entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Set environment variables
ENV PYTHONPATH="/app/src:/app"
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
# Expose default port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Use entrypoint script
ENTRYPOINT ["docker-entrypoint.sh"]
# Default: show usage (user must provide formation path)
CMD []