From a4bd1ef8134aa3c57543ca0be7e67501c2e2b7fd Mon Sep 17 00:00:00 2001 From: jetie <1405758738@qq.com> Date: Sun, 14 Jun 2026 19:29:56 +0800 Subject: [PATCH] chore(docker): add Dockerfile and .dockerignore for container builds Multi-stage build: rust:1-bookworm builder with protobuf-compiler and clang (for RocksDB bindgen), debian:bookworm-slim runtime (189MB). Dependency caching via dummy files so code-only changes rebuild in ~25s. --- .dockerignore | 13 ++++++++++++ Dockerfile | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..25bf362 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +/target +.git +.github +.claude +.idea +.vscode +*.swp +*.swo +.DS_Store +.env +.env.* +tests/ +criterion/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2f8dca3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,55 @@ +# === Build stage === +FROM rust:1-bookworm AS builder + +RUN apt-get update && apt-get install -y --no-install-recommends \ + protobuf-compiler \ + clang \ + libclang-dev \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# Copy dependency manifests first to leverage Docker layer caching +COPY Cargo.toml Cargo.lock ./ +# Create dummy files to trigger dependency download +RUN mkdir -p src/bin/aether-bench && \ + echo "fn main(){}" > src/main.rs && \ + echo "fn main(){}" > src/bin/aether-bench/main.rs && \ + echo "fn main(){}" > build.rs && \ + mkdir benches && \ + echo "fn main(){}" > benches/storage.rs && \ + echo "fn main(){}" > benches/raft_store.rs && \ + echo "fn main(){}" > benches/codec.rs && \ + mkdir proto && touch proto/kv.proto proto/cluster.proto proto/raft.proto \ + proto/watch.proto proto/lease.proto proto/auth.proto proto/shard.proto \ + proto/maintenance.proto proto/lock.proto proto/election.proto \ + proto/barrier.proto proto/queue.proto proto/session.proto && \ + cargo build --release && \ + rm -rf src build.rs benches proto + +# Copy source and proto files, then rebuild +COPY build.rs ./ +COPY benches/ benches/ +COPY proto/ proto/ +COPY src/ src/ +RUN touch build.rs src/main.rs && cargo build --release + +# === Runtime stage === +FROM debian:bookworm-slim AS runtime + +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +RUN groupadd -r aether && useradd -r -g aether -d /data aether + +COPY --from=builder /app/target/release/aether /usr/local/bin/aether + +RUN mkdir -p /data && chown aether:aether /data + +USER aether +WORKDIR /data + +EXPOSE 2379 2380 9090 + +ENTRYPOINT ["aether"]