1+ # Compileo API Dockerfile - Multi-stage build for optimal size
2+ FROM nvidia/cuda:13.0.0-devel-ubuntu24.04 AS builder
3+
4+ # Set environment variables
5+ ENV PYTHONUNBUFFERED=1 \
6+ PYTHONDONTWRITEBYTECODE=1 \
7+ PIP_NO_CACHE_DIR=1 \
8+ PIP_DISABLE_PIP_VERSION_CHECK=1 \
9+ DEBIAN_FRONTEND=noninteractive
10+
11+ # Install Python and system dependencies for building
12+ RUN apt-get update && apt-get install -y \
13+ python3.12 \
14+ python3.12-dev \
15+ python3-pip \
16+ build-essential \
17+ gcc \
18+ g++ \
19+ libffi-dev \
20+ libssl-dev \
21+ curl \
22+ git \
23+ poppler-utils \
24+ tesseract-ocr \
25+ tesseract-ocr-eng \
26+ libglib2.0-0 \
27+ libgomp1 \
28+ libgthread-2.0-0 \
29+ && rm -rf /var/lib/apt/lists/*
30+
31+ # Set working directory
32+ WORKDIR /app
33+
34+ # Copy requirements first for better caching
35+ COPY requirements-docker.txt .
36+ COPY pyproject.toml .
37+
38+ # Install Python dependencies (including torch+cu130 and flash-attn compilation)
39+ RUN pip install --no-cache-dir --upgrade pip setuptools wheel --break-system-packages --ignore-installed && \
40+ pip install --no-cache-dir torch==2.9.1+cu130 torchvision==0.24.1+cu130 --index-url https://download.pytorch.org/whl/cu130 --break-system-packages --ignore-installed && \
41+ pip install --no-cache-dir -r requirements-docker.txt --break-system-packages --ignore-installed && \
42+ pip install --no-cache-dir --no-build-isolation flash-attn --break-system-packages --ignore-installed
43+
44+ # Copy source code
45+ COPY src/ ./src/
46+ COPY main.py .
47+
48+ # Production stage
49+ FROM nvidia/cuda:13.0.0-runtime-ubuntu24.04
50+
51+ # Set environment variables
52+ ENV PYTHONUNBUFFERED=1 \
53+ PYTHONDONTWRITEBYTECODE=1 \
54+ DEBIAN_FRONTEND=noninteractive
55+
56+ # Install Python and runtime dependencies only
57+ RUN apt-get update && apt-get install -y \
58+ python3 \
59+ python3-pip \
60+ curl \
61+ poppler-utils \
62+ tesseract-ocr \
63+ tesseract-ocr-eng \
64+ libglib2.0-0 \
65+ libgomp1 \
66+ libglib2.0-0 \
67+ && rm -rf /var/lib/apt/lists/*
68+
69+ # Set working directory
70+ WORKDIR /app
71+
72+ # Create non-root user
73+ RUN useradd --create-home --shell /bin/bash --uid 1001 compileo
74+
75+ # Add user local bin to PATH
76+ ENV PATH="/home/compileo/.local/bin:${PATH}"
77+
78+ # Copy Python packages from builder stage
79+ COPY --from=builder /usr/local/lib/python3.12/dist-packages /usr/local/lib/python3.12/dist-packages
80+ COPY --from=builder /usr/local/bin /usr/local/bin
81+
82+ # Copy application code
83+ COPY --from=builder /app/src ./src
84+ COPY --from=builder /app/main.py .
85+
86+ # Create necessary directories and set permissions
87+ RUN mkdir -p data uploads test_outputs storage plugins src/compileo/features/ingestion/hf_models && \
88+ chown -R compileo:compileo /app
89+
90+ # Switch to non-root user
91+ USER compileo
92+
93+ # Expose port
94+ EXPOSE 8000
95+
96+ # Health check
97+ HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
98+ CMD curl -f http://localhost:8000/docs || exit 1
99+
100+ # Run the API
101+ CMD ["uvicorn", "src.compileo.api.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
0 commit comments