Spaces:
Running
Running
File size: 1,676 Bytes
021e065 b7e0fc5 021e065 253e4cd 021e065 eb13a87 021e065 | 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 | 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"]
|