FROM rust:1.89-slim-bullseye AS builder

WORKDIR /app

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

# test then build
RUN cargo build --example tcp_client
RUN cargo build --example participant

# create a minimal runtime image
FROM debian:bullseye-slim
RUN apt-get update && apt-get install -y \
    ca-certificates \
    libssl-dev \
    && rm -rf /var/lib/apt/lists/*



# Copy the built binary from the builder stage
COPY --from=builder /app/target/debug/examples/tcp_client /usr/local/bin/tcp_client
COPY --from=builder /app/target/debug/examples/participant /usr/local/bin/participant

# run participant and tcp_client
CMD ["sh", "-c", "participant"]