1- # Production-Optimized Dockerfile for MOSO AI
2- # Multi-stage build with layer caching and minimal runtime image
1+ # MOSO AI — Production Dockerfile
2+ # Multi-stage build: builder (compile) → runtime (minimal)
33
4- FROM python:3.11-slim AS builder
4+ # ── Stage 1: Builder ──────────────────────────────────────────
5+ FROM python:3.12-slim AS builder
56
67WORKDIR /build
78
8- # Install only essential build dependencies (layer caches separately)
99RUN apt-get update && apt-get install -y --no-install-recommends \
1010 build-essential \
1111 libopenblas-dev \
1212 gfortran \
1313 && rm -rf /var/lib/apt/lists/*
1414
15- # Copy requirements first (cache before code changes)
16- COPY moso_core/requirements.txt backend/requirements.txt ./
15+ COPY moso_core/requirements.txt ./
1716
18- # Create isolated virtual environment
1917RUN python -m venv /opt/venv
2018ENV PATH="/opt/venv/bin:$PATH"
2119
22- # Upgrade pip to latest
2320RUN pip install --upgrade pip setuptools wheel
2421
25- # Install Python packages (split into layers for better caching)
26- RUN pip install --no-cache-dir \
27- pydantic>=2.6.0 \
28- numpy>=1.24.0
22+ # Core dependencies
23+ RUN pip install --no-cache-dir -r requirements.txt
2924
30- RUN pip install --no-cache-dir \
31- llama-cpp-python>=0.2.60 \
32- onnxruntime>=1.17.0 \
33- transformers>=4.36.0 \
34- tokenizers>=0.15.0
25+ # API server
26+ RUN pip install --no-cache-dir fastapi uvicorn[standard]
3527
36- RUN pip install --no-cache-dir \
37- fastapi==0.109.0 \
38- uvicorn[standard]==0.27.0 \
39- sqlalchemy==2.0.25 \
40- asyncpg==0.29.0 \
41- redis[hiredis]==5.0.1
42-
43- RUN pip install --no-cache-dir \
44- psutil>=5.9.0 \
45- beautifulsoup4>=4.12.0 \
46- networkx>=3.0 \
47- pytesseract>=0.3.10
48-
49- # Optional voice/audio (commented for faster builds)
50- # RUN pip install --no-cache-dir openai-whisper faster-whisper speechbrain
51-
52- # Stage 2: Runtime — minimal production image
53- FROM python:3.11-slim
28+ # ── Stage 2: Runtime ──────────────────────────────────────────
29+ FROM python:3.12-slim
5430
5531LABEL maintainer="MOSO AI" \
56- description="MOSO: Privacy-First Adaptive AI Assistant" \
57- version="0.2.0-dev "
32+ description="MOSO: Privacy-First Adaptive AI Assistant" \
33+ version="0.2.0"
5834
5935# Security: non-root user
60- RUN groupadd -r moso && useradd -r -g moso moso
36+ RUN groupadd -r moso && useradd -r -g moso -m moso
6137
6238WORKDIR /app
6339
64- # Runtime dependencies only (no build tools)
40+ # Runtime dependencies only
6541RUN apt-get update && apt-get install -y --no-install-recommends \
6642 libopenblas0 \
6743 libgomp1 \
@@ -71,29 +47,30 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
7147 curl \
7248 && rm -rf /var/lib/apt/lists/*
7349
74- # Copy venv from builder (all packages included)
50+ # Copy venv from builder
7551COPY --from=builder --chown=moso:moso /opt/venv /opt/venv
52+ ENV PATH="/opt/venv/bin:$PATH"
7653
77- # Copy application
78- COPY --chown=moso:moso . .
54+ # Copy application code (models excluded via .dockerignore)
55+ COPY --chown=moso:moso moso_core/ ./moso_core/
56+ COPY --chown=moso:moso backend/ ./backend/
57+ COPY --chown=moso:moso moso_ui/ ./moso_ui/
58+ COPY --chown=moso:moso run.py ./
7959
8060# Environment
81- ENV PATH="/opt/venv/bin:$PATH" \
82- PYTHONUNBUFFERED=1 \
61+ ENV PYTHONUNBUFFERED=1 \
8362 PYTHONDONTWRITEBYTECODE=1 \
84- MOSO_HOME=/app/. moso \
85- MODELS_PATH=/app /models
63+ MOSO_HOME=/data/ moso \
64+ MOSO_MODEL_PATH= /models
8665
87- # Setup data directories
88- RUN mkdir -p $MOSO_HOME models && \
89- chown -R moso:moso $MOSO_HOME models
66+ # Create data directories
67+ RUN mkdir -p /data/moso /models && chown -R moso:moso /data /models
9068
9169# Health check
92- HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
70+ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
9371 CMD curl -f http://localhost:8000/health || exit 1
9472
9573USER moso
9674EXPOSE 8000
9775
98- # Start FastAPI backend
9976CMD ["uvicorn" , "backend.api.main:app" , "--host" , "0.0.0.0" , "--port" , "8000" , "--workers" , "1" ]
0 commit comments