Spaces:
Running
Running
joseph njoroge kariuki
fix: install rust to /usr/local so CARGO_HOME persists across Docker layers
b7e0fc5 | 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 stable - set explicit home dirs so they persist across layers | |
| ENV RUSTUP_HOME=/usr/local/rustup \ | |
| CARGO_HOME=/usr/local/cargo \ | |
| PATH=/usr/local/cargo/bin:${PATH} | |
| RUN curl https://sh.rustup.rs -sSf | sh -s -- -y \ | |
| --no-modify-path \ | |
| --default-toolchain stable \ | |
| && rustup default stable \ | |
| && cargo --version \ | |
| && rustc --version | |
| # 4. Copy backend requirements and install Python deps + maturin | |
| WORKDIR /app | |
| 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 | |
| # 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"] | |