Spaces:
Sleeping
Sleeping
| FROM python:3.11-slim | |
| # Install basic utils | |
| RUN apt-get update && apt-get install -y \ | |
| wget \ | |
| gnupg \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set up a new user named "user" with user ID 1000 (Required by Hugging Face) | |
| RUN useradd -m -u 1000 user | |
| # Set environment variables for Playwright so it stores browsers in a shared location | |
| ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright | |
| RUN mkdir -p $PLAYWRIGHT_BROWSERS_PATH && chown -R user:user $PLAYWRIGHT_BROWSERS_PATH | |
| WORKDIR /app | |
| # Install python dependencies as root | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| RUN pip install --no-cache-dir browserforge | |
| # Install Playwright dependencies (this requires root because it uses apt-get) | |
| RUN python -m playwright install-deps chromium | |
| # Now switch to the non-root user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH \ | |
| PYTHONUNBUFFERED=1 | |
| WORKDIR $HOME/app | |
| # Install Playwright browsers AS the user (so they are owned by the user) | |
| RUN python -m playwright install chromium | |
| # Copy app code | |
| COPY --chown=user . $HOME/app | |
| EXPOSE 7860 | |
| CMD ["/bin/bash", "-c", "echo '>>> BASH INLINE BOOTING <<<' && python -u -m uvicorn main:app --host 0.0.0.0 --port 7860"] | |