# --- Base image with Node + Python ---
FROM ubuntu:22.04

# --- Install system dependencies ---
RUN apt-get update && apt-get install -y \
    curl python3 python3-pip git build-essential libgl1 libglvnd0 ffmpeg unzip \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# --- Install Bun ---
RUN curl -fsSL https://bun.sh/install | bash
ENV PATH="/root/.bun/bin:${PATH}"

# --- Install Python dependencies ---
RUN pip3 install --upgrade pip
RUN pip3 install torch --index-url https://download.pytorch.org/whl/cpu
RUN pip3 install --no-cache-dir fastapi uvicorn pillow open-clip-torch numpy faiss-cpu python-multipart

# --- Copy project files ---
WORKDIR /app
COPY python_service ./python_service
COPY src ./src
COPY package.json .
COPY bun.lock .

# --- Expose ports ---
EXPOSE 3000

# --- Start services ---
# Use & to run Python worker in background, Bun frontend as main process
CMD python3 python_service/app.py & bun run src/index.ts
