Spaces:
Sleeping
Sleeping
| # Use Python 3.12 slim for a smaller image | |
| FROM python:3.12-slim | |
| # Set environment variables | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV PORT=7860 | |
| # Install system dependencies including Rust toolchain requirements and build tools | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| curl \ | |
| git \ | |
| pkg-config \ | |
| libssl-dev \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Install Rust | |
| RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | |
| ENV PATH="/root/.cargo/bin:${PATH}" | |
| # Set the working directory | |
| WORKDIR /app | |
| # Copy dependency files | |
| COPY pyproject.toml ./ | |
| # Install Python dependencies | |
| # Using uv for faster builds | |
| RUN pip install --no-cache-dir uv && \ | |
| uv pip install --system --no-cache . | |
| # Copy the rest of the application | |
| COPY . . | |
| # Build the Rust engine | |
| RUN maturin develop --manifest-path engine_rust_src/Cargo.toml --release | |
| # Compile card data | |
| RUN python -m compiler.main | |
| # Create a non-privileged user (required for some HF Space environments) | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| # Expose the port used by Hugging Face Spaces | |
| EXPOSE 7860 | |
| # Run the server | |
| # HF Spaces expects the app to listen on 0.0.0.0:7860 | |
| CMD ["python", "backend/server.py"] | |