Spaces:
Sleeping
Sleeping
| # Use standard Python 3.9 slim image | |
| FROM python:3.9-slim | |
| # Set working directory | |
| WORKDIR /app | |
| # Install system dependencies including Node.js | |
| RUN apt-get update && apt-get install -y \ | |
| curl \ | |
| build-essential \ | |
| libmagic1 \ | |
| poppler-utils \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Install Node.js 18 (PATTERN MULTI-SERVICES) | |
| RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ | |
| && apt-get install -y nodejs | |
| # Create non-root user for security (PATTERN OFFICIEL HF) | |
| RUN useradd -m -u 1000 user | |
| # Install uv as root | |
| RUN pip install uv | |
| # Create cache directory with proper permissions before switching user | |
| RUN mkdir -p /home/user/.cache/uv && chown -R user:user /home/user/.cache | |
| USER user | |
| # Set environment variables (PATTERN OFFICIEL HF) | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH \ | |
| UV_CACHE_DIR=/home/user/.cache/uv | |
| # Set workdir with user permissions | |
| WORKDIR $HOME/app | |
| # Copy project files with correct ownership (PATTERN OFFICIEL HF) | |
| COPY --chown=user . $HOME/app | |
| # Install Python dependencies with uv FIRST (PATTERN OPTIMIZED UV) | |
| WORKDIR $HOME/app/backend | |
| RUN echo "π Setting up Python environment with uv..." && \ | |
| uv venv .venv && \ | |
| echo "source .venv/bin/activate" >> $HOME/.bashrc | |
| # Install dependencies with uv | |
| RUN echo "π¦ Installing Python dependencies..." && \ | |
| . .venv/bin/activate && \ | |
| uv pip install -e . | |
| # Build Frontend in Docker (PATTERN BUILD AUTOMATION) | |
| WORKDIR $HOME/app/frontend | |
| RUN echo "ποΈ Building React frontend..." && \ | |
| npm install && \ | |
| npm run build | |
| # Copy built frontend to backend static directory | |
| WORKDIR $HOME/app/backend | |
| RUN echo "π Copying frontend build to static..." && \ | |
| rm -rf static && \ | |
| mkdir -p static && \ | |
| cp -r $HOME/app/frontend/build/* static/ | |
| # Verify static files are present | |
| RUN echo "=== Static files verification ===" && \ | |
| ls -la static/ && \ | |
| ls -la static/static/css/ && \ | |
| ls -la static/static/js/ | |
| # Create uploads directory | |
| RUN mkdir -p $HOME/app/backend/uploads | |
| # Expose Hugging Face port | |
| EXPOSE 7860 | |
| # Set environment variables for Hugging Face | |
| ENV HOST=0.0.0.0 | |
| ENV PORT=7860 | |
| ENV PYTHONPATH=$HOME/app/backend/src | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ | |
| CMD curl -f http://localhost:7860/api/health || exit 1 | |
| # Start the application | |
| WORKDIR $HOME/app/backend | |
| CMD ["/bin/bash", "-c", "source .venv/bin/activate && uv run uvicorn src.main:app --host 0.0.0.0 --port 7860"] |