Drop transformers, matplotlib, geopy, and diskcache (~560MB) from dependencies — none are imported in the codebase. Replace single-stage poetry-based Docker build with a two-stage pip-based build: builder stage installs into a venv from an exported requirements.txt, runtime stage copies only the venv and app code. Eliminates poetry from the image (fixes ARM segfaults) and removes ~200MB of build tools from the final image.
43 lines
1,018 B
Docker
43 lines
1,018 B
Docker
# Stage 1: Build dependencies
|
|
FROM python:3.13-slim AS builder
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
build-essential \
|
|
gcc \
|
|
python3-dev \
|
|
libopencv-dev \
|
|
libmariadb-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /app
|
|
|
|
COPY requirements.txt ./
|
|
|
|
# Install dependencies into a venv using pip (no poetry needed)
|
|
RUN python -m venv /app/.venv && \
|
|
/app/.venv/bin/pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Stage 2: Runtime image
|
|
FROM python:3.13-slim
|
|
|
|
# Install only runtime system dependencies (no build tools)
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
libgl1 \
|
|
libglib2.0-0 \
|
|
tesseract-ocr \
|
|
tesseract-ocr-eng \
|
|
libmariadb3 \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy the venv from the builder stage
|
|
COPY --from=builder /app/.venv /app/.venv
|
|
|
|
ENV PATH="/app/.venv/bin:$PATH"
|
|
|
|
# Copy the application code
|
|
COPY . .
|
|
|
|
EXPOSE 5001
|
|
CMD ["uvicorn", "api.app:app", "--host", "0.0.0.0", "--port", "5001"]
|