FROM python:3.13-slim

WORKDIR /app

# Install system dependencies, Node.js, uv, and yarn
RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs \
    && npm install -g yarn \
    && rm -rf /var/lib/apt/lists/* \
    && curl -LsSf https://astral.sh/uv/install.sh | sh

# Add uv to PATH
ENV PATH="/root/.local/bin:$PATH"

# Copy dependency files
COPY pyproject.toml ./

# Install Python dependencies using uv
RUN uv pip install --system -e .

# Copy frontend package files and install dependencies
COPY raggr-frontend/package.json raggr-frontend/yarn.lock* raggr-frontend/
WORKDIR /app/raggr-frontend
RUN yarn install

# Copy application source code
WORKDIR /app
COPY . .

# Build frontend
WORKDIR /app/raggr-frontend
RUN yarn build

# Create database directory
WORKDIR /app
RUN mkdir -p /app/database

# Make startup script executable
RUN chmod +x /app/startup-dev.sh

# Set environment variables
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1

# Expose port
EXPOSE 8080

# Default command
CMD ["/app/startup-dev.sh"]
