# Multi-stage Dockerfile for Rocky Man
# This creates an architecture-independent image that can run on x86_64, aarch64, etc.

FROM rockylinux/rockylinux:9 AS builder

# Install system dependencies
RUN dnf install -y epel-release \
    && dnf install -y \
    python3 \
    python3-pip \
    python3-dnf \
    mandoc \
    rpm-build \
    dnf-plugins-core \
    && dnf clean all

# Set working directory
WORKDIR /app

# Copy project files
COPY pyproject.toml README.md LICENSE ./
COPY src ./src
COPY templates ./templates

# Install Python dependencies using pip
RUN python3 -m pip install --no-cache-dir -e .

# Runtime stage
FROM rockylinux/rockylinux:9

# Install runtime dependencies
RUN dnf install -y epel-release \
    && dnf install -y \
    python3 \
    python3-dnf \
    mandoc \
    rpm-build \
    dnf-plugins-core \
    && dnf clean all

# Copy Python packages and app from builder
COPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
COPY --from=builder /usr/local/lib64/python3.9/site-packages /usr/local/lib64/python3.9/site-packages
COPY --from=builder /app /app

WORKDIR /app

# Create directories for data
RUN mkdir -p /data/html /data/tmp

# Set environment variables
ENV PYTHONUNBUFFERED=1

# Volume for output
VOLUME ["/data/html", "/data/tmp"]

# Default command
ENTRYPOINT ["python3", "-m", "rocky_man.main"]
CMD ["--output-dir", "/data/html", "--download-dir", "/data/tmp/downloads", "--extract-dir", "/data/tmp/extracts"]
