| FROM debian:bullseye-slim | |
| # Install dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| tor \ | |
| python3 \ | |
| python3-pip \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Install Python dependencies | |
| RUN pip3 install requests requests[socks] fastapi uvicorn | |
| # Create a non-root user for running Tor | |
| RUN useradd -m -s /bin/bash toruser | |
| # Create Tor data directory and set permissions | |
| RUN mkdir -p /var/lib/tor && chown toruser:toruser /var/lib/tor | |
| # Copy custom torrc configuration | |
| COPY torrc /etc/tor/torrc | |
| # Set working directory | |
| WORKDIR /app | |
| # Copy the application script | |
| COPY app.py /app/app.py | |
| # Make the script executable | |
| RUN chmod +x /app/app.py | |
| # Switch to non-root user | |
| USER toruser | |
| # Expose port for FastAPI (Hugging Face Spaces uses 7860) | |
| EXPOSE 7860 | |
| # Run Tor in the background and the FastAPI application | |
| CMD tor & uvicorn app:main --host 0.0.0.0 --port 7860 |