d0852ad131
- 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
39 lines
839 B
Docker
39 lines
839 B
Docker
# ---- 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"]
|