File size: 1,311 Bytes
5b4a293
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
FROM python:3.12-slim

# Install uv globally
RUN pip install uv

# Update system packages and install Playwright system dependencies (as root)
RUN apt-get update && apt-get install -y \
    libnss3 \
    libatk-bridge2.0-0 \
    libdrm2 \
    libxkbcommon0 \
    libxcomposite1 \
    libxdamage1 \
    libxrandr2 \
    libgbm1 \
    libxss1     libasound2     libcups2     libxfixes3     libcairo2     libpango-1.0-0     --no-install-recommends &&     rm -rf /var/lib/apt/lists/*

# Create a non-root user
RUN adduser --disabled-password --gecos '' appuser

# Create /app directory and set ownership
RUN mkdir /app && chown appuser:appuser /app

WORKDIR /app

# Switch to the non-root user
USER appuser

# Create virtual environment as appuser
RUN uv venv .venv
# Use the virtual environment automatically
ENV VIRTUAL_ENV=/app/.venv
ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONUNBUFFERED=1

# Copy dependency files and install dependencies as appuser
COPY pyproject.toml uv.lock ./ 
RUN uv sync

# Install Playwright browser binaries as appuser
RUN /app/.venv/bin/playwright install chromium

# Copy the rest of your application code as appuser
COPY . .

# Expose the port Gradio runs on
EXPOSE 7860
ENV GRADIO_SERVER_NAME="0.0.0.0"

# Command to run the Gradio application
CMD ["uv", "run", "--active", "app.py"]