# Stage 1: build
FROM rust:1.94-slim-bookworm AS builder

WORKDIR /src

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

COPY . .
RUN cargo build --release --locked

# Stage 2: runtime
FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    && rm -rf /var/lib/apt/lists/* \
    && groupadd --gid 10001 rivet \
    && useradd --uid 10001 --gid rivet --no-create-home rivet

COPY --from=builder /src/target/release/rivet /usr/local/bin/rivet
COPY --from=builder /src/target/release/rivet-mcp /usr/local/bin/rivet-mcp

USER rivet
ENTRYPOINT ["rivet"]
