# Build stage
FROM rust:1.83-bookworm AS builder
# Install build dependencies for rdkafka
RUN apt-get update && apt-get install -y \
cmake \
build-essential \
libssl-dev \
libsasl2-dev \
libclang-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy manifests
COPY Cargo.toml Cargo.lock ./
# Create dummy source to cache dependencies
RUN mkdir src && \
echo "fn main() {}" > src/main.rs && \
cargo build --release && \
rm -rf src
# Copy actual source
COPY src ./src
# Build the release binary
RUN touch src/main.rs && cargo build --release
# Runtime stage
FROM debian:bookworm-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
libsasl2-2 \
curl \
wget \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN useradd -r -g root klag
WORKDIR /app
# Copy binary from builder
COPY --from=builder /app/target/release/klag-exporter /app/klag-exporter
# Copy example config
COPY config.example.toml /app/config.example.toml
# Set ownership
RUN chown -R klag:root /app
USER klag
# Expose Prometheus metrics port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
ENTRYPOINT ["/app/klag-exporter"]
CMD ["--config", "/app/config.toml"]