FROM ghcr.io/astral-sh/uv:python3.12-bookworm

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PYTHONPATH=/app \
    UV_CACHE_DIR=/app/.cache/uv \
    PLAYWRIGHT_BROWSERS_PATH=/app/.playwright

# Set work directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    gcc \
    nodejs \
    npm \
    gettext \
    gnupg \
    chromium \
    chromium-driver \
    fonts-wqy-zenhei \
    fonts-arphic-ukai \
    && rm -rf /var/lib/apt/lists/*

# Copy project files
COPY pyproject.toml uv.lock ./

# Install dependencies using uv
RUN uv venv /app/.venv

ENV PATH="/app/.venv/bin:$PATH"
ENV VIRTUAL_ENV=/app/.venv

RUN uv sync --no-dev --frozen --no-install-project

# Copy the rest of the project
COPY . .

# Sync the project
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --frozen

# Install Playwright browsers
RUN playwright install chromium
