# ============================================================ # BeFree Bank Statement Processor — Production Backend # Deploy on Railway, Render, Fly.io, or any container host # ============================================================ FROM python:3.12-slim AS base # System dependencies for PDF and image processing (PyMuPDF, camelot, pytesseract) RUN apt-get update && apt-get install -y --no-install-recommends \ tesseract-ocr \ poppler-utils \ libgl1 \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender1 \ ghostscript \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Copy dependency files first for better Docker layer caching COPY requirements.txt ./ COPY shared/pyproject.toml shared/ COPY shared/__init__.py shared/constants.py shared/models.py shared/ COPY bank-extractor/pyproject.toml bank-extractor/ COPY bank-classifier/pyproject.toml bank-classifier/ COPY bank-hitl/pyproject.toml bank-hitl/ # Upgrade pip and install all third-party dependencies from requirements.txt # (dynamically filters out local editable packages to keep layer caching active) RUN pip install --no-cache-dir --upgrade pip && \ python -c "print('\n'.join(line.strip() for line in open('requirements.txt') if line.strip() and not line.strip().startswith('-e')))" > temp_reqs.txt && \ pip install --no-cache-dir -r temp_reqs.txt && \ rm temp_reqs.txt # Copy full source code COPY . . # Install local editable packages RUN pip install --no-cache-dir \ -e shared \ -e bank-extractor \ -e "bank-hitl[web]" \ -e bank-classifier # Create data directories programmatically inside the container (startup creates them too) RUN mkdir -p data/uploads data/output data/corrections data/logs data/models # Expose standard port and Render's default port (Hugging Face expects 7860) EXPOSE 7860 EXPOSE 10000 # Health check (dynamically checks the port exposed by Render, falling back to 8000) HEALTHCHECK --interval=30s --timeout=5s --retries=3 \ CMD python -c "import urllib.request, os; port = os.environ.get('PORT', '7860'); urllib.request.urlopen(f'http://localhost:{port}/health')" || exit 1 # Start the server (dynamically maps to the $PORT env var set by Render) CMD ["sh", "-c", "uvicorn api_server:app --host 0.0.0.0 --port ${PORT:-7860} --workers 1"]