-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
69 lines (52 loc) · 2.32 KB
/
Copy pathDockerfile
File metadata and controls
69 lines (52 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Genesis Protocol — Multi-stage Production Build
#
# Stage 1: Compile Rust binary with release optimizations
# Stage 2: Minimal runtime image (no compiler, no source)
# ── Build Stage ──────────────────────────────────────────
FROM rust:1.77-slim AS builder
WORKDIR /build
# Copy manifests first (layer caching for dependencies)
COPY Cargo.toml Cargo.lock ./
COPY crates/genesis-dna/Cargo.toml crates/genesis-dna/Cargo.toml
COPY crates/metabolism/Cargo.toml crates/metabolism/Cargo.toml
COPY crates/apostle/Cargo.toml crates/apostle/Cargo.toml
COPY crates/ecosystem/Cargo.toml crates/ecosystem/Cargo.toml
COPY crates/evolution/Cargo.toml crates/evolution/Cargo.toml
COPY crates/gateway/Cargo.toml crates/gateway/Cargo.toml
# Create dummy source files to cache dependency compilation
RUN mkdir -p src && echo "fn main() {}" > src/main.rs && \
for crate in genesis-dna metabolism apostle ecosystem evolution gateway; do \
mkdir -p crates/$crate/src && echo "" > crates/$crate/src/lib.rs; \
done
RUN cargo build --release 2>/dev/null || true
# Copy real source code
COPY . .
# Touch source files to invalidate cache for our code only
RUN find . -name "*.rs" -exec touch {} +
# Build release binary
RUN cargo build --release --bin genesis-protocol
# ── Runtime Stage ────────────────────────────────────────
FROM debian:bookworm-slim AS runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*
# Non-root user for security
RUN useradd --create-home --shell /bin/bash genesis
USER genesis
WORKDIR /home/genesis
# Copy binary
COPY --from=builder /build/target/release/genesis-protocol /usr/local/bin/genesis-protocol
# Data directory for world state persistence (world_state.json written to CWD)
RUN mkdir -p /home/genesis/data
VOLUME /home/genesis/data
WORKDIR /home/genesis/data
# Expose HTTP gateway port
EXPOSE 3000
# Environment defaults (override at runtime)
ENV RUST_LOG=info
# Health check — hit /status every 30s
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -sf http://localhost:3000/status || exit 1
# Run
ENTRYPOINT ["genesis-protocol"]