FROM python:3.11-slim WORKDIR /app # Install system dependencies required for Playwright RUN apt-get update && apt-get install -y \ wget \ gnupg \ libnss3 \ libnspr4 \ libdbus-1-3 \ libatk1.0-0 \ libatk-bridge2.0-0 \ libcups2 \ libdrm2 \ libgtk-3-0 \ libgtk-4-1 \ libxss1 \ libxcomposite1 \ libxdamage1 \ libxrandr2 \ libgbm1 \ libxkbcommon0 \ libatspi2.0-0 \ libxdamage1 \ libxfixes3 \ libxrandr2 \ libasound2 \ libpangocairo-1.0-0 \ libatk1.0-0 \ libcairo-gobject2 \ libgtk-3-0 \ libgdk-pixbuf2.0-0 \ && rm -rf /var/lib/apt/lists/* # Create a non-root user first RUN useradd -m -u 1000 appuser # Copy requirements and install Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Switch to appuser for Playwright installation USER appuser # Install Playwright browsers - this must be done as the same user that will run the app RUN playwright install-deps chromium || true RUN playwright install chromium # Switch back to root to set up directories and copy files USER root # Create directories and set permissions RUN mkdir -p /app/data/tmp /app/data/downloads /app/data/static && \ chown -R appuser:appuser /app/data && \ chmod -R 777 /app/data # Copy application code COPY . . # Change ownership of the app directory to appuser RUN chown -R appuser:appuser /app # Switch back to non-root user for running the application USER appuser # Expose port EXPOSE 7860 # Set environment variables for directories ENV WEBTOON_TMP_DIR=/app/data/tmp ENV WEBTOON_DOWNLOADS_DIR=/app/data/downloads ENV WEBTOON_STATIC_DIR=/app/data/static # Set Playwright environment variables ENV PLAYWRIGHT_BROWSERS_PATH=/home/appuser/.cache/ms-playwright # Run the application with uvicorn CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]