# Multi-stage Dockerfile for Lode Observe AI
# AI agent observability & tracing platform with OTEL export

# Stage 1: Builder
FROM python:3.11-slim as builder

WORKDIR /build

# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    git \
    && rm -rf /var/lib/apt/lists/*

# Copy source
COPY . .

# Build distribution
RUN pip install --upgrade pip setuptools wheel build && \
    python -m build

# Stage 2: Runtime
FROM python:3.11-slim

LABEL maintainer="CraftedWithIntent <dev@craftedwithintent.com>"
LABEL description="Lode Observe AI: Agent observability & tracing with OTEL export"
LABEL version="0.1.3-dev"

WORKDIR /app

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

# Copy built package from builder
COPY --from=builder /build/dist/*.whl .

# Install lode-observe-ai and dependencies
RUN pip install --no-cache-dir *.whl && \
    rm -f *.whl

# Create non-root user
RUN useradd -m -u 1000 lode && \
    mkdir -p /data && \
    chown -R lode:lode /data /app

USER lode

# Health check for CLI readiness
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD lode-observe-ai --version || exit 1

# Configuration for OTEL export
# Traces are exported to backend, not stored locally (optional)
ENV OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
ENV OTEL_SERVICE_NAME=lode-agent
ENV LODE_SAMPLE_RATE=1.0
ENV LODE_OVERHEAD_BUDGET_MS=0.5
ENV LODE_STORAGE_PATH=/data/traces.db

# Default command: CLI is ready for manual invocation
# Example: docker run lode-observe-ai export --trace-id abc123 --format otel
ENTRYPOINT ["lode-observe-ai"]
CMD ["--help"]
