FROM python:3.11-slim # 1. Install system tools, Redis, and Nginx RUN apt-get update && apt-get install -y \ curl gnupg gcc g++ pkg-config tesseract-ocr redis-server nginx \ && rm -rf /var/lib/apt/lists/* # 2. Install Node.js (V20) for frontend building RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ && apt-get install -y nodejs \ && rm -rf /var/lib/apt/lists/* # 3. Install Rust for Matulin compilation RUN curl https://sh.rustup.rs -sSf | sh -s -- -y ENV PATH="/root/.cargo/bin:$PATH" WORKDIR /app # 4. Copy backend requirements and install COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt maturin # 5. Create non-root user for Hugging Face Spaces compatibility RUN useradd -m -u 1000 user ENV HOME=/home/user WORKDIR /app # Copy all project code COPY --chown=user:user . . # 6. Build the Rust math library inside the container RUN cd senti/senti_calc && \ maturin build --release && \ pip install --force-reinstall target/wheels/*.whl # 7. Install frontend dependencies and build React App statically RUN cd frontend && \ npm install && \ npm run build # 8. Set up write permissions for unprivileged running RUN chmod +x /app/start.hf.sh && \ chown -R user:user /app && \ chmod -R 777 /tmp /var/log/nginx /var/lib/nginx # Switch to Hugging Face unprivileged user USER user EXPOSE 7860 CMD ["/app/start.hf.sh"]