add dockerfiles

This commit is contained in:
guochao 2024-05-30 02:07:52 +08:00
parent caf67bf618
commit 683462cc10
3 changed files with 43 additions and 0 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
/target

21
Dockerfile Normal file
View File

@ -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"]

21
Dockerfile.alpine Normal file
View File

@ -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"]