# ==============================================================================
# Makima Server — slim image (no LLM/STT/TTS models)
# ==============================================================================
# This builds the smallest viable Makima server image: the Rust binary plus
# the runtime tools the orchestrator needs. The Listen and Speak websocket
# endpoints will respond with "ML models not configured" — everything else
# (mesh, directives, files, repo CRUD) works normally.
#
# Use Dockerfile.full when you need STT (Parakeet), diarization (Sortformer),
# or TTS (Chatterbox) — that variant is ~5GB larger because it downloads the
# model weights at build time.
# ==============================================================================

# ---------- Builder stage ----------
FROM rust:1.91-bookworm AS builder

WORKDIR /app

RUN apt-get update && apt-get install -y \
    pkg-config \
    libssl-dev \
    && rm -rf /var/lib/apt/lists/*

# Copy workspace files. We deliberately do NOT copy `voices/` or any model
# data — the slim build doesn't ship them.
COPY Cargo.toml Cargo.lock ./
COPY makima ./makima
COPY vendor ./vendor
COPY tools/stt-client ./tools/stt-client

RUN cargo build --release --package makima --bin makima

# ---------- Runtime stage ----------
FROM debian:bookworm-slim

# Runtime deps — same as the daemon image. No python, no huggingface_hub,
# no model download script.
RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    libssl3 \
    git \
    curl \
    openssh-client \
    jq \
    && rm -rf /var/lib/apt/lists/*

# GitHub CLI for orchestrator PR operations.
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
        -o /usr/share/keyrings/githubcli-archive-keyring.gpg \
    && chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
    && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
        > /etc/apt/sources.list.d/github-cli.list \
    && apt-get update \
    && apt-get install -y --no-install-recommends gh \
    && rm -rf /var/lib/apt/lists/*

COPY --from=builder /app/target/release/makima /makima

# Embed daemon binary for the download endpoint (same binary, served as
# `/api/v1/daemons/binaries/...` to clients).
RUN mkdir -p /app/daemon-binaries \
    && cp /makima /app/daemon-binaries/makima-linux-x86_64
ENV DAEMON_BINARIES_DIR=/app/daemon-binaries

ENV PORT=8080
ENV RUST_LOG=makima=info,tower_http=info
# NOTE: PARAKEET_MODEL_DIR / SORTFORMER_MODEL_PATH / CHATTERBOX_MODEL_DIR are
# DELIBERATELY not set. The server will start without them and Listen/Speak
# will return "ML models not configured" if a client attempts to use them.

EXPOSE 8080

HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
    CMD curl -f http://localhost:${PORT}/api/v1/healthcheck || exit 1

CMD ["/makima", "server"]
