Spaces:
Running
Running
| # ========================================== | |
| # 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 "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 HF Space configuration files | |
| COPY supervisord.conf /app/supervisord.conf | |
| COPY 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"] | |