File size: 1,007 Bytes
1cec79f
 
 
 
edea27f
 
 
 
 
1cec79f
edea27f
 
 
 
 
1cec79f
edea27f
 
1cec79f
edea27f
 
 
 
 
1cec79f
edea27f
1cec79f
edea27f
4445143
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
FROM python:3.11-slim

WORKDIR /app

# Playwright saves browsers here during the image build. The same path is then
# available to the non-root FastAPI process at runtime.
ENV PYTHONUNBUFFERED=1 \
    PORT=7860 \
    PLAYWRIGHT_BROWSERS_PATH=/ms-playwright

# Install the application dependencies first so Docker can cache this layer.
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt \
    && python -m playwright install --with-deps chromium \
    && rm -rf /var/lib/apt/lists/* /root/.cache/pip

# Copy the FastAPI application after dependency installation.
COPY . ./

# Avoid running the web app as root. The installed browser path is readable by
# this user and /tmp remains writable for temporary MP4 output.
RUN useradd --create-home --uid 1000 appuser \
    && chown -R appuser:appuser /app /ms-playwright
USER appuser

EXPOSE 7860

# Uses $PORT when a host injects it, and otherwise listens on 7860.
CMD ["sh", "-c", "uvicorn app:app --host 0.0.0.0 --port ${PORT:-7860}"]