FROM python:3.14-slim

LABEL maintainer="Denis Petelin <denis.petelin@example.com>"
LABEL description="Mimir - Your Ever-Evolving Engineering Playbook"
LABEL version="1.0.0"

# Runtime-only (no secrets baked in). Common overrides:
#   DATABASE_URL, DJANGO_SECRET_KEY — production
#   GITHUB_TOKEN, GITHUB_BUG_REPO — bug reports → GitHub Issues (FOB process)
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    supervisor \
    graphviz \
    && rm -rf /var/lib/apt/lists/* \
    && mkdir -p /var/log/supervisor

# Set working directory
WORKDIR /app

# Copy requirements and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Copy Docker configuration files
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY docker/entrypoint.sh /app/entrypoint.sh

# Make entrypoint executable
RUN chmod +x /app/entrypoint.sh

# Create data directory
RUN mkdir -p /app/data

# Create volume mount point for persistent storage
VOLUME ["/app/data"]

# Expose Django port
EXPOSE 8000

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
  CMD python -c "import requests; requests.get('http://localhost:8000', timeout=5)" || exit 1

# Set entrypoint
ENTRYPOINT ["/app/entrypoint.sh"]
