Skip to content

Commit 87c50d8

Browse files
authored
Merge pull request #3 from Project-MOSO-AI/docs/readme-rewrite
feat: production Docker deployment with real FastAPI API
2 parents ea6c036 + 8f86d52 commit 87c50d8

8 files changed

Lines changed: 2197 additions & 1605 deletions

File tree

‎.dockerignore‎

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
# .dockerignore — exclude unnecessary files from build context
2-
# Significantly reduces build context size
1+
# .dockerignore — exclude everything not needed in the image
32

43
# Version control
54
.git/
6-
.gitignore
75
.github/
6+
.gitignore
87

98
# Development
109
.venv/
1110
.env
12-
.env.local
13-
.env.*.local
11+
.env.*
1412
__pycache__/
1513
*.pyc
1614
*.pyo
@@ -26,45 +24,40 @@ htmlcov/
2624
.idea/
2725
*.swp
2826
*.swo
29-
*~
3027
.DS_Store
31-
*.sublime-project
32-
*.sublime-workspace
3328

34-
# Documentation (keep llms.txt for context)
35-
docs/
36-
README.md
37-
LICENSE
38-
SECURITY.md
39-
40-
# Tests & fixtures (exclude but keep test runner config if needed)
41-
tests/
42-
test_*.py
43-
pytest.ini
44-
conftest.py
45-
46-
# Models (store in volume, not image)
29+
# Models (mounted as external volume)
4730
models/
4831
*.gguf
4932
*.bin
5033
*.pth
5134

52-
# Temporary/build artifacts
53-
*.log
35+
# User data (mounted as external volume)
36+
.moso/
5437
*.db
5538
*.sqlite
56-
*.tmp
57-
tmp/
58-
temp/
59-
logs/
39+
40+
# Tests
41+
tests/
42+
test_*.py
43+
conftest.py
44+
pytest.ini
45+
46+
# Documentation
47+
docs/
48+
README.md
49+
LICENSE
50+
SECURITY.md
51+
llms.txt
6052

6153
# Docker files
6254
Dockerfile
6355
.dockerignore
6456
docker-compose*.yml
6557

66-
# CI/CD
67-
.github/
68-
.gitlab-ci.yml
69-
.circleci/
70-
.travis.yml
58+
# Temporary
59+
*.log
60+
*.tmp
61+
tmp/
62+
temp/
63+
logs/

‎Dockerfile‎

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,43 @@
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

67
WORKDIR /build
78

8-
# Install only essential build dependencies (layer caches separately)
99
RUN 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
1917
RUN python -m venv /opt/venv
2018
ENV PATH="/opt/venv/bin:$PATH"
2119

22-
# Upgrade pip to latest
2320
RUN 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

5531
LABEL 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

6238
WORKDIR /app
6339

64-
# Runtime dependencies only (no build tools)
40+
# Runtime dependencies only
6541
RUN 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
7551
COPY --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

9573
USER moso
9674
EXPOSE 8000
9775

98-
# Start FastAPI backend
9976
CMD ["uvicorn", "backend.api.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]

0 commit comments

Comments
 (0)