Spaces:
Running
Running
| # syntax=docker/dockerfile:1.7 | |
| FROM python:3.11-slim-bookworm | |
| ARG DEBIAN_FRONTEND=noninteractive | |
| ENV PYTHONUNBUFFERED=1 \ | |
| PYTHONDONTWRITEBYTECODE=1 \ | |
| PIP_DISABLE_PIP_VERSION_CHECK=1 \ | |
| PIP_NO_CACHE_DIR=1 \ | |
| HOME=/home/user \ | |
| PATH=/home/user/.local/bin:${PATH} \ | |
| PLAYWRIGHT_BROWSERS_PATH=/home/user/.cache/ms-playwright \ | |
| PORT=7860 | |
| # Install Python packages first so Playwright's dependency installer is available. | |
| WORKDIR /tmp/build | |
| COPY requirements.txt ./ | |
| RUN python -m pip install --no-cache-dir -r requirements.txt \ | |
| && python -m playwright install-deps chromium \ | |
| && apt-get update \ | |
| && apt-get install -y --no-install-recommends tini \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Hugging Face Docker Spaces run the container as UID 1000. | |
| RUN useradd --create-home --uid 1000 --shell /bin/bash user \ | |
| && mkdir -p /home/user/app /home/user/.cache/ms-playwright \ | |
| && chown -R user:user /home/user/app /home/user/.cache | |
| USER user | |
| WORKDIR /home/user/app | |
| # Download the browser as the runtime user so cache permissions remain correct. | |
| RUN python -m playwright install chromium | |
| COPY --chown=user:user app ./app | |
| COPY --chown=user:user README.md ./README.md | |
| EXPOSE 7860 | |
| ENTRYPOINT ["/usr/bin/tini", "--"] | |
| CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-7860} --proxy-headers --forwarded-allow-ips='*'"] | |