File size: 2,371 Bytes
d084ead
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ============================================================
# 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"]