FROM docker.io/clux/muslrust:stable AS chef
RUN cargo install cargo-chef

WORKDIR /src

FROM docker.io/clux/muslrust:stable AS audit
RUN cargo install cargo-audit

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

FROM chef AS builder
COPY --from=planner /src/recipe.json recipe.json
RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json

COPY . .
RUN cargo build --release --target x86_64-unknown-linux-musl --bin cargo-sonar

FROM docker.io/rust:slim
COPY --from=audit /root/.cargo/bin/cargo-audit /usr/local/cargo/bin/cargo-audit
COPY --from=builder /src/target/x86_64-unknown-linux-musl/release/cargo-sonar /usr/local/cargo/bin/cargo-sonar
CMD ["cargo", "sonar"]
