FROM python:3.11-slim

WORKDIR /app

# Install Typst compiler
RUN apt-get update && apt-get install -y \
    curl \
    xz-utils \
    && curl -fsSL https://github.com/typst/typst/releases/download/v0.11.1/typst-x86_64-unknown-linux-musl.tar.xz \
    | tar -xJ -C /tmp \
    && mv /tmp/typst-x86_64-unknown-linux-musl/typst /usr/local/bin/typst \
    && chmod +x /usr/local/bin/typst \
    && apt-get remove -y curl xz-utils \
    && apt-get autoremove -y \
    && rm -rf /var/lib/apt/lists/* /tmp/typst-x86_64-unknown-linux-musl

# Copy requirements first for better caching
COPY ./python/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Create directory for database
RUN mkdir -p /data

# Then copy the rest of the application
COPY ./python/ .

# Run with host 0.0.0.0 to make it accessible from outside the container
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]