File size: 1,661 Bytes
c129c6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ee755de
c129c6f
ee755de
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
FROM python:3.12-slim

# Install system dependencies, including Google Chrome for undetected-chromedriver
RUN apt-get update && apt-get install -y \
    wget \
    gnupg \
    xvfb \
    && mkdir -p /etc/apt/keyrings \
    && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /etc/apt/keyrings/google-chrome.gpg \
    && sh -c 'echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/google-chrome.gpg] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
    && apt-get update \
    && apt-get install -y google-chrome-stable \
    && rm -rf /var/lib/apt/lists/*

# Install uv for fast dependency resolution
RUN pip install --no-cache-dir uv

# Copy dependency definition files
COPY pyproject.toml uv.lock* ./

# Install python dependencies system-wide
RUN uv pip install --system -r pyproject.toml

# Set Playwright browsers path to a shared location accessible by all users
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright

# Install Playwright browsers and their system dependencies
RUN playwright install chromium \
    && playwright install-deps chromium \
    && chmod -R 755 /ms-playwright

# Set up non-root user for Hugging Face Spaces (required by HF)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

WORKDIR $HOME/app

# Copy the rest of the application files setting the owner to the non-root user
COPY --chown=user . $HOME/app

# Expose the port Hugging Face Spaces expects
EXPOSE 7860
ENV PORT=7860
ENV PYTHONUNBUFFERED=1

# Command to run the backend application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]