# Orchestrator Agent Dockerfile
# Part of ABI-Core Agentic Orchestration Layer

FROM smarbuy/abi-image:latest

# Set working directory
WORKDIR /app

# Copy agent-specific requirements and install
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy agent files
COPY ./agent/*.py /app/agent/
COPY ./agent/models/*.py /app/agent/models/

# Environment variables for abi-entrypoint.sh
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
ENV ABI_ROLE="Orchestrator Agent"
ENV ABI_NODE="ABI AGENT"
ENV AGENT_HOST=0.0.0.0
ENV AGENT_PORT=8002

# ABI Entrypoint configuration
# START_OLLAMA will be set via docker-compose (true for distributed, false for centralized)
ENV START_OLLAMA=true
ENV LOAD_MODELS=true
ENV SERVICE_MODULE=main
ENV SERVICE_PORT=8002

# Create non-root user but keep root for model access
RUN useradd -m -u 1000 orchestrator && \
    chown -R orchestrator:orchestrator /app && \
    chmod -R 755 /root/.ollama || true

# Health check - verify agent is ready
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
    CMD curl -f http://localhost:8002/health >/dev/null 2>&1 || exit 1

# Expose ports (agent + web interface + Ollama for distributed mode)
EXPOSE 8002
EXPOSE 8083
EXPOSE 11434

# Volume for model data (used in distributed mode)
VOLUME ["/root/.ollama"]

# Use abi-entrypoint.sh (inherited from abi-image)
# The entrypoint will handle Ollama startup, model loading, and agent startup
# No need to override CMD - entrypoint will use SERVICE_MODULE
