# CAVORA Docker Image
# Multi-stage build for optimized container

FROM python:3.9-slim AS builder

WORKDIR /build

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

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

# Final stage
FROM python:3.9-slim

LABEL maintainer="Samir Baladi <gitdeeper@gmail.com>"
LABEL description="CAVORA - Underground Research Initiative"
LABEL version="1.0.0"

WORKDIR /app

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

# Copy Python packages from builder
COPY --from=builder /root/.local /root/.local

# Copy application code
COPY . .

# Make sure scripts are executable
RUN chmod +x scripts/*.py

# Set environment variables
ENV PATH=/root/.local/bin:$PATH
ENV PYTHONPATH=/app:$PYTHONPATH
ENV CAVORA_ENV=production

# Create non-root user
RUN useradd -m -u 1000 cavora && \
    chown -R cavora:cavora /app
USER cavora

# Create necessary directories
RUN mkdir -p data output logs

# Expose ports for dashboard
EXPOSE 8050

# Default command
CMD ["python", "-c", "import cavora; print('CAVORA v1.0.0 ready')"]
