From d0852ad131f2f402dd70c4178c1937e04d0117f9 Mon Sep 17 00:00:00 2001 From: zhenyi <434836402@qq.com> Date: Sun, 7 Jun 2026 22:48:06 +0800 Subject: [PATCH] feat(build): add Docker support for emailks service - Create multi-stage Dockerfile with builder and runtime stages - Add .dockerignore to exclude unnecessary files and directories - Configure builder stage with Rust toolchain and dependencies - Set up runtime stage with minimal Debian base image - Copy compiled binary from builder to runtime stage - Expose port 50051 for gRPC service - Add proper dependency caching for faster builds - Include SSL certificates and required libraries in runtime --- .dockerignore | 4 ++++ Dockerfile | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ccc277e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +target/ +.git/ +.idea/ +**/*.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..649a53a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# ---- builder ---- +FROM rust:1.96-slim-bookworm AS builder + +RUN apt-get update && apt-get install -y --no-install-recommends \ + pkg-config \ + libssl-dev \ + protobuf-compiler \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# Cache dependencies +COPY Cargo.toml Cargo.lock ./ +COPY build.rs ./ +COPY proto/ proto/ +RUN echo '' >lib.rs && \ + echo 'fn main() {}' >main.rs && \ + cargo build --release; \ + rm -f lib.rs main.rs + +# Build real binary +COPY . . +RUN cargo build --release --bin emailks && \ + cp target/release/emailks /app/emailks + +# ---- runtime ---- +FROM debian:bookworm-slim + +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + libssl3 \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=builder /app/emailks /usr/local/bin/emailks + +EXPOSE 50051 + +ENTRYPOINT ["emailks"]