# Stage 0: grab docker CLI + compose plugin
FROM docker:cli AS docker-cli

FROM python:3.11-slim

WORKDIR /app

# System dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    libpq-dev \
    gcc \
    libpango-1.0-0 \
    libpangoft2-1.0-0 \
    libcairo2 \
    libgdk-pixbuf-2.0-0 \
    libffi-dev \
    && rm -rf /var/lib/apt/lists/*

# Copy docker CLI + compose plugin for worker scaling
COPY --from=docker-cli /usr/local/bin/docker /usr/local/bin/docker
COPY --from=docker-cli /usr/local/libexec/docker/cli-plugins/docker-compose /usr/local/libexec/docker/cli-plugins/docker-compose

# Install Python dependencies (dev + cad extras: pytest, trimesh, pygltflib)
COPY pyproject.toml .
RUN pip install --no-cache-dir -e ".[dev,cad]"

# Copy app code
COPY . .

# Create upload dirs
RUN mkdir -p uploads/step_files uploads/excel_files uploads/thumbnails

COPY start.sh /start.sh
RUN chmod +x /start.sh

EXPOSE 8000
