| # Use a lightweight Python 3.10 base image | |
| FROM python:3.10-slim | |
| # 1. Install Python dependencies | |
| RUN pip install --no-cache-dir fastapi uvicorn websockets playwright | |
| # 2. Install system dependencies required by Chromium | |
| RUN playwright install-deps chromium | |
| # 3. Create a non-root user (UID 1000) as required by Hugging Face Spaces | |
| RUN useradd -m -u 1000 user | |
| # 4. Create the /app directory and set ownership BEFORE switching users | |
| RUN mkdir -p /app/static && chown -R user:user /app | |
| # 5. Switch to the non-root user | |
| USER user | |
| # 6. Install Chromium as the non-root user (installs to their ~/.cache) | |
| RUN playwright install chromium | |
| # 7. Set working directory | |
| WORKDIR /app | |
| # 8. Copy application files with proper user ownership | |
| COPY --chown=user:user browser_server.py /app/ | |
| COPY --chown=user:user static/browser.html /app/static/ | |
| # 9. Expose the Hugging Face Spaces default port | |
| EXPOSE 7860 | |
| # 10. Start the server using Uvicorn directly | |
| # This binds it to HF's required port 7860. | |
| CMD ["uvicorn", "browser_server:app", "--host", "0.0.0.0", "--port", "7860"] |