FROM rust:1.89-bookworm AS builder

WORKDIR /build

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

COPY Cargo.toml Cargo.lock ./
COPY src ./src

RUN cargo build --release --bin rtr_debug_client

FROM debian:bookworm-slim AS runtime

RUN apt-get update \
    && apt-get install -y --no-install-recommends ca-certificates tzdata \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app
ENV TZ=Asia/Shanghai

COPY --from=builder /build/target/release/rtr_debug_client /usr/local/bin/rtr_debug_client
COPY --chmod=755 deploy/client/entrypoint.sh /usr/local/bin/rtr-debug-client-entrypoint.sh

ENTRYPOINT ["/usr/local/bin/rtr-debug-client-entrypoint.sh"]
