-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.api
More file actions
101 lines (82 loc) · 2.88 KB
/
Copy pathDockerfile.api
File metadata and controls
101 lines (82 loc) · 2.88 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
# Compileo API Dockerfile - Multi-stage build for optimal size
FROM nvidia/cuda:13.0.0-devel-ubuntu24.04 AS builder
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
DEBIAN_FRONTEND=noninteractive
# Install Python and system dependencies for building
RUN apt-get update && apt-get install -y \
python3.12 \
python3.12-dev \
python3-pip \
build-essential \
gcc \
g++ \
libffi-dev \
libssl-dev \
curl \
git \
poppler-utils \
tesseract-ocr \
tesseract-ocr-eng \
libglib2.0-0 \
libgomp1 \
libgthread-2.0-0 \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy requirements first for better caching
COPY requirements-docker.txt .
COPY pyproject.toml .
# Install Python dependencies (including torch+cu130 and flash-attn compilation)
RUN pip install --no-cache-dir --upgrade pip setuptools wheel --break-system-packages --ignore-installed && \
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 && \
pip install --no-cache-dir -r requirements-docker.txt --break-system-packages --ignore-installed && \
pip install --no-cache-dir --no-build-isolation flash-attn --break-system-packages --ignore-installed
# Copy source code
COPY src/ ./src/
COPY main.py .
# Production stage
FROM nvidia/cuda:13.0.0-runtime-ubuntu24.04
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
DEBIAN_FRONTEND=noninteractive
# Install Python and runtime dependencies only
RUN apt-get update && apt-get install -y \
python3 \
python3-pip \
curl \
poppler-utils \
tesseract-ocr \
tesseract-ocr-eng \
libglib2.0-0 \
libgomp1 \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Create non-root user
RUN useradd --create-home --shell /bin/bash --uid 1001 compileo
# Add user local bin to PATH
ENV PATH="/home/compileo/.local/bin:${PATH}"
# Copy Python packages from builder stage
COPY --from=builder /usr/local/lib/python3.12/dist-packages /usr/local/lib/python3.12/dist-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy application code
COPY --from=builder /app/src ./src
COPY --from=builder /app/main.py .
# Create necessary directories and set permissions
RUN mkdir -p data uploads test_outputs storage plugins src/compileo/features/ingestion/hf_models && \
chown -R compileo:compileo /app
# Switch to non-root user
USER compileo
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:8000/docs || exit 1
# Run the API
CMD ["uvicorn", "src.compileo.api.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]