FROM rust:latest AS chef
WORKDIR /app

# Plan
FROM chef AS planner
COPY . .
RUN cargo install cargo-chef
RUN cargo chef prepare --recipe-path recipe.json

# Build dependencies
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
RUN cargo install cargo-chef
RUN cargo chef cook --release --recipe-path recipe.json

# Build application
COPY . .
RUN cargo build --release
# RUN ldd /app/target/release/beacon-verifier; test $? -eq 1

# Runtime
FROM alpine/openssl:latest AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/beacon-verifier /usr/local/bin
ENTRYPOINT ["bash"]
