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"]