FROM python:3.11-slim as builder

# Install system dependencies for WeasyPrint
RUN apt-get update && apt-get install -y \
    build-essential \
    pkg-config \
    libcairo2-dev \
    git \
    python3-cffi \
    python3-brotli \
    libpango-1.0-0 \
    libpangoft2-1.0-0 \
    libharfbuzz-subset0 \
    libjpeg-dev \
    libopenjp2-7-dev \
    libffi-dev \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Copy requirements and install
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Configure Git to trust the workspace
RUN git config --global --add safe.directory /app

# Copy source code including .gemini tools
COPY . .

# Run the build script
RUN python .gemini/build_site.py

# --- Runner Stage ---
FROM nginx:alpine

# Copy static site from builder
COPY --from=builder /app/_site_src/site /usr/share/nginx/html

# Copy Nginx config (optional, using default for now)
# COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
