From 683462cc10370fdc7d1f02c850f508e79426d3ce Mon Sep 17 00:00:00 2001 From: guochao Date: Thu, 30 May 2024 02:07:52 +0800 Subject: [PATCH] add dockerfiles --- .dockerignore | 1 + Dockerfile | 21 +++++++++++++++++++++ Dockerfile.alpine | 21 +++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 Dockerfile.alpine diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c41cc9e --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +/target \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f935444 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM rust:bookworm as rust + +FROM rust as chef +RUN apt update && apt install -y build-essential && cargo install --locked cargo-chef +WORKDIR /app + +FROM chef as planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef AS builder +RUN apt install -y libprotobuf-dev protobuf-compiler +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json +COPY . . +RUN cargo build --release --package chat-signaling-server --bin server + +FROM debian:bookworm AS runtime +WORKDIR /app +COPY --from=builder /app/target/release/server /usr/local/bin +ENTRYPOINT ["/usr/local/bin/server"] \ No newline at end of file diff --git a/Dockerfile.alpine b/Dockerfile.alpine new file mode 100644 index 0000000..b27b1c0 --- /dev/null +++ b/Dockerfile.alpine @@ -0,0 +1,21 @@ +FROM rust:alpine as rust + +FROM rust as chef +RUN apk add libc-dev musl-dev && cargo install --locked 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 +RUN cargo chef cook --release --recipe-path recipe.json +RUN apk add protoc protobuf-dev +COPY . . +RUN cargo build --release --package chat-signaling-server --bin server + +FROM alpine AS runtime +WORKDIR /app +COPY --from=builder /app/target/release/server /usr/local/bin +ENTRYPOINT ["/usr/local/bin/server"] \ No newline at end of file