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

# Install musl target and musl-tools
RUN rustup target add x86_64-unknown-linux-musl \
    && apt-get update \
    && apt-get install -y musl-tools build-essential

WORKDIR /app

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

# Build fully static binary
RUN cargo build --release --target x86_64-unknown-linux-musl

# --- Final stage ---
FROM debian:bookworm

# Copy static binary
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/payphone /usr/local/bin/payphone

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

ENTRYPOINT ["/usr/local/bin/payphone"]
CMD ["start"]
