File size: 3,315 Bytes
b8277c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8c9ee8
 
 
 
 
 
 
 
5123406
a8c9ee8
 
b8277c4
 
 
 
a8c9ee8
b8277c4
 
 
a8c9ee8
 
 
b8277c4
 
 
 
5123406
 
 
 
 
 
 
 
b8277c4
 
 
 
a8c9ee8
b8277c4
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# ==========================================
# Stage 1: Build Backend (Python deps)
# ==========================================
FROM python:3.11-slim AS backend-builder

ENV PYTHONUNBUFFERED=1 PIP_NO_CACHE_DIR=1
WORKDIR /app

# Install build dependencies for MySQL/PostgreSQL C libraries
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
       build-essential gcc pkg-config \
       default-libmysqlclient-dev \
       libmariadb-dev-compat \
       libssl-dev libpq-dev \
    && rm -rf /var/lib/apt/lists/*

# Install Python dependencies
COPY backend/requirements-hf.txt /tmp/requirements.txt
RUN pip install --upgrade pip setuptools wheel \
    && pip install -r /tmp/requirements.txt

# ==========================================
# Stage 2: Final Runtime
# ==========================================
FROM python:3.11-slim

WORKDIR /app

# Install runtime dependencies: Redis, Nginx, Supervisor
RUN apt-get update && apt-get install -y --no-install-recommends \
    redis-server \
    nginx \
    supervisor \
    curl \
    libmariadb3 \
    libssl3 \
    libpq5 \
    && rm -rf /var/lib/apt/lists/*

# Install MinIO server binary
RUN set -eux; \
        arch="$(dpkg --print-architecture)"; \
        case "$arch" in \
            amd64) minio_arch="amd64" ;; \
            arm64) minio_arch="arm64" ;; \
            *) echo "Unsupported architecture: $arch"; exit 1 ;; \
        esac; \
        curl -fsSL --retry 5 --retry-connrefused --retry-delay 5 "https://dl.min.io/server/minio/release/linux-${minio_arch}/minio" -o /usr/local/bin/minio; \
        chmod +x /usr/local/bin/minio

# Copy Python packages from builder stage
COPY --from=backend-builder /usr/local/bin /usr/local/bin
COPY --from=backend-builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages

# Copy backend modules required by unified HF app
COPY backend/__init__.py        /app/backend/
COPY backend/SQL_Agent/         /app/backend/SQL_Agent/
COPY backend/data_sources/      /app/backend/data_sources/
COPY backend/tenant_files/      /app/backend/tenant_files/
COPY backend/excel_module/      /app/backend/excel_module/
COPY backend/ml_module/         /app/backend/ml_module/
COPY backend/core/              /app/backend/core/
COPY backend/shared/            /app/backend/shared/
COPY backend/unified/           /app/backend/unified/
COPY backend/.env               /app/backend/.env
# COPY supervisord.conf  /app/supervisord.conf
# COPY nginx.conf        /app/nginx.conf uncomment these for hf deployeent
# Copy HF Space configuration files
COPY hf-space/supervisord.conf  /app/supervisord.conf
COPY hf-space/nginx.conf        /app/nginx.conf
#uncomment this for local deployment
# COPY hf-space/supervisord.conf  /app/supervisord.conf
# COPY hf-space/nginx.conf        /app/nginx.conf
# Set Python path so imports like `backend.data_sources.api` work
ENV PYTHONPATH=/app:/app/backend

# Create temp directories
RUN mkdir -p /tmp/redis-data /tmp/minio-data /app/data /app/logs

# ── HF Spaces user setup (UID 1000 required) ─────────────────
RUN useradd -m -u 1000 user \
    && chown -R user:user /app /tmp

USER user

ENV HOME=/home/user
ENV PATH=/home/user/.local/bin:$PATH

EXPOSE 7860

CMD ["supervisord", "-c", "/app/supervisord.conf"]