# Osiris CLI - Multi-stage Docker build
# Optimized for size and security

# Stage 1: Builder
FROM python:3.11-slim as builder

WORKDIR /app

# Install build dependencies
RUN apt-get update && apt-get install -y \
    gcc \
    g++ \
    && rm -rf /var/lib/apt/lists/*

# Copy only requirements first for better caching
COPY pyproject.toml ./
COPY README.md ./

# Install build tools and create wheel
RUN pip install --no-cache-dir build && \
    python -m build --wheel

# Stage 2: Runtime
FROM python:3.11-slim

# Create non-root user for security
RUN useradd -m -u 1000 osiris && \
    mkdir -p /home/osiris/.osiris && \
    chown -R osiris:osiris /home/osiris

# Install runtime dependencies only
RUN apt-get update && apt-get install -y \
    git \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy wheel from builder
COPY --from=builder /app/dist/*.whl /tmp/

# Install osiris-cli
RUN pip install --no-cache-dir /tmp/*.whl && \
    rm /tmp/*.whl

# Switch to non-root user
USER osiris
WORKDIR /home/osiris

# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV OSIRIS_HOME=/home/osiris/.osiris

# Create config directory
RUN mkdir -p $OSIRIS_HOME

# Expose default port (if needed for future web interface)
EXPOSE 8080

# Set entrypoint
ENTRYPOINT ["osiris"]

# Default command (interactive mode)
CMD []
