File size: 1,215 Bytes
9d117bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ----------------------------
# Stage 1: Builder
# ----------------------------
FROM python:3.12-slim AS builder

WORKDIR /app

# Install only what is needed for building wheels
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    gcc \
    libgl1 \
    && rm -rf /var/lib/apt/lists/*

# Copy dependencies file
COPY requirements.txt .

# Install dependencies into a temporary folder
RUN pip install --upgrade pip && \
    pip install --prefix=/install --no-cache-dir -r requirements.txt

# Copy source
COPY . .

# ----------------------------
# Stage 2: Runtime (minimal size)
# ----------------------------
FROM python:3.12-slim

WORKDIR /app

# Install minimal runtime libraries only
RUN apt-get update && apt-get install -y --no-install-recommends \
    libgl1 \
    libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# Copy only installed python deps
COPY --from=builder /install /usr/local

# Copy only application code (not build deps)
COPY --from=builder /app /app

# Reduce Python overhead
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

EXPOSE 7860

# Use multiple workers in a lightweight way
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]