content: # Multi-stage build for smaller image size
  FROM python:3.11-slim as builder
  
  # Install build dependencies
  RUN apt-get update && apt-get install -y \
      gcc \
      g++ \
      && rm -rf /var/lib/apt/lists/*
  
  # Create virtual environment
  RUN python -m venv /opt/venv
  ENV PATH="/opt/venv/bin:$PATH"
  
  # Copy requirements and install dependencies
  COPY requirements.txt .
  RUN pip install --no-cache-dir -r requirements.txt
  
  # Production stage
  FROM python:3.11-slim
  
  # Install runtime dependencies only
  RUN apt-get update && apt-get install -y \
      curl \
      && rm -rf /var/lib/apt/lists/* \
      && apt-get clean
  
  # Copy virtual environment from builder
  COPY --from=builder /opt/venv /opt/venv
  ENV PATH="/opt/venv/bin:$PATH"
  
  # Create non-root user
  RUN useradd --create-home --shell /bin/bash refinery && \
      mkdir -p /app/data && \
      chown -R refinery:refinery /app
  
  # Set working directory
  WORKDIR /app
  
  # Copy application code
  COPY --chown=refinery:refinery refinery_agent.py .
  COPY --chown=refinery:refinery orchestrator/ ./orchestrator/
  
  # Switch to non-root user
  USER refinery
  
  # Expose port
  EXPOSE 8005
  
  # Health check
  HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
      CMD curl -f http://localhost:8005/health || exit 1
  
  # Start the service
  CMD ["python", "refinery_agent.py"]