fede1024 / rust-rdkafka

A fully asynchronous, futures-based Kafka client library for Rust based on librdkafka
MIT License
1.62k stars 278 forks source link

how to use Dockerfile to build image of rust-kafka #687

Open uamself opened 5 months ago

Guyzeroth commented 5 months ago

Here's an example dockerfile I use with cargo-chef for faster builds . just place it in the root of your codebase in Dockerfile . replace your_binary with whatever your built artifact is called.


FROM rust:bookworm as chef

RUN cargo install cargo-chef

WORKDIR app
FROM chef as planner 

COPY . .

RUN cargo chef prepare  --recipe-path recipe.json

FROM chef AS builder

COPY --from=planner /app/recipe.json recipe.json

#Build deps (Cached)

RUN cargo chef cook --release --recipe-path recipe.json
#Build application
COPY . .

RUN cargo build --release

FROM debian:bookworm as runtime

WORKDIR /app/

COPY --from=builder /app/target/release/YOUR_BINARY

CMD ["/app/YOUR_BINARY"]

build with something like docker build -t YOUR_DOCKER_REPO/YOUR_APP:latest .