2026-02-21 19:49:11 +00:00
|
|
|
# syntax=docker/dockerfile:1
|
|
|
|
|
|
2026-02-07 11:06:35 +00:00
|
|
|
# Stage 1: Install build tools and Python dependencies
|
2026-02-07 10:48:22 +00:00
|
|
|
FROM python:3.13-slim AS builder
|
2025-05-21 21:30:00 +00:00
|
|
|
|
2026-02-21 19:49:11 +00:00
|
|
|
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
|
|
|
|
|
|
|
|
|
|
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
|
|
|
|
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
|
|
|
|
|
apt-get update && apt-get install -y --no-install-recommends \
|
2025-05-21 21:30:00 +00:00
|
|
|
build-essential \
|
|
|
|
|
gcc \
|
|
|
|
|
python3-dev \
|
|
|
|
|
libopencv-dev \
|
2026-02-21 19:49:11 +00:00
|
|
|
libmariadb-dev
|
2026-02-07 10:48:22 +00:00
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
COPY requirements.txt ./
|
|
|
|
|
|
2026-02-21 19:49:11 +00:00
|
|
|
# Install dependencies into a venv using uv (10-25x faster than pip)
|
|
|
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
|
|
|
python -m venv /app/.venv && \
|
2026-02-21 21:26:44 +00:00
|
|
|
uv pip install --python /app/.venv/bin/python -r requirements.txt
|
2026-02-07 10:48:22 +00:00
|
|
|
|
2026-02-07 11:06:35 +00:00
|
|
|
# Stage 2: Runtime system dependencies (runs in parallel with builder)
|
|
|
|
|
FROM python:3.13-slim AS runtime-base
|
2026-02-07 10:48:22 +00:00
|
|
|
|
2026-02-21 19:49:11 +00:00
|
|
|
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
|
|
|
|
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
|
|
|
|
|
apt-get update && apt-get install -y --no-install-recommends \
|
2025-05-21 21:30:00 +00:00
|
|
|
libglib2.0-0 \
|
|
|
|
|
tesseract-ocr \
|
|
|
|
|
tesseract-ocr-eng \
|
2026-02-07 10:48:22 +00:00
|
|
|
libmariadb3 \
|
2026-02-21 19:49:11 +00:00
|
|
|
curl
|
2025-05-21 21:30:00 +00:00
|
|
|
|
2026-02-21 15:10:55 +00:00
|
|
|
# Stage 3: Test — runtime deps + venv + test dependencies + run tests
|
2026-02-10 22:57:42 +00:00
|
|
|
FROM runtime-base AS test
|
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
COPY --from=builder /app/.venv /app/.venv
|
|
|
|
|
ENV PATH="/app/.venv/bin:$PATH"
|
|
|
|
|
|
2026-02-21 19:49:11 +00:00
|
|
|
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
|
|
|
|
|
|
|
|
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
|
|
|
uv pip install --python /app/.venv/bin/python pytest pytest-asyncio pytest-xdist httpx aioresponses fakeredis
|
2026-02-10 22:57:42 +00:00
|
|
|
|
2026-02-21 15:10:55 +00:00
|
|
|
COPY . .
|
|
|
|
|
|
|
|
|
|
RUN pytest tests/ -x -q
|
|
|
|
|
|
2026-02-10 22:57:42 +00:00
|
|
|
# Stage 4: Final image — combine venv from builder + runtime base
|
2026-02-21 21:26:44 +00:00
|
|
|
FROM runtime-base AS production
|
2026-02-07 11:06:35 +00:00
|
|
|
|
2026-02-21 19:49:11 +00:00
|
|
|
RUN adduser --system --no-create-home appuser
|
|
|
|
|
|
2025-05-21 21:30:00 +00:00
|
|
|
WORKDIR /app
|
|
|
|
|
|
2026-02-07 10:48:22 +00:00
|
|
|
# Copy the venv from the builder stage
|
|
|
|
|
COPY --from=builder /app/.venv /app/.venv
|
2025-05-21 21:30:00 +00:00
|
|
|
|
|
|
|
|
ENV PATH="/app/.venv/bin:$PATH"
|
|
|
|
|
|
|
|
|
|
# Copy the application code
|
|
|
|
|
COPY . .
|
|
|
|
|
|
2026-02-21 19:49:11 +00:00
|
|
|
RUN chown -R appuser /app
|
|
|
|
|
|
|
|
|
|
USER appuser
|
|
|
|
|
|
2025-06-24 19:12:20 +00:00
|
|
|
EXPOSE 5001
|
2026-02-21 19:49:11 +00:00
|
|
|
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=10s --retries=3 --start-period=40s \
|
|
|
|
|
CMD curl -f http://localhost:5001/api/status || exit 1
|
|
|
|
|
|
2026-02-08 20:06:46 +00:00
|
|
|
CMD ["sh", "-c", "alembic upgrade head && uvicorn api.app:app --host 0.0.0.0 --port 5001 --no-server-header"]
|