1- # syntax=docker/dockerfile:1
1+ FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
2+ WORKDIR /app
23
3- # Build stage
4- FROM rust:1.81-slim AS builder
4+ LABEL org.opencontainers.image.licenses="MIT OR Apache-2.0"
55
6- # Install build dependencies
7- RUN apt-get update && apt-get install -y \
6+ RUN apt-get update && \
7+ apt-get -y upgrade && \
8+ apt-get install -y \
9+ build-essential \
810 pkg-config \
911 libssl-dev \
10- && rm -rf /var/lib/apt/lists/*
12+ clang-14 \
13+ libclang-14-dev \
14+ llvm-14-dev \
15+ libc6-dev \
16+ && ln -sf /usr/lib/llvm-14/lib/libclang.so /usr/lib/libclang.so
1117
12- WORKDIR /app
18+ FROM chef AS planner
19+ COPY . .
20+ RUN cargo chef prepare --recipe-path recipe.json
21+
22+ FROM chef AS builder
23+ COPY --from=planner /app/recipe.json recipe.json
1324
14- # Copy manifests
25+ # Copy workspace Cargo files for better caching
1526COPY Cargo.toml Cargo.lock ./
16- COPY bin/ bin/
17- COPY crates/ crates/
27+ COPY bin/lumen/Cargo.toml bin/lumen/
28+ COPY crates/common/Cargo.toml crates/common/
29+ COPY crates/node/Cargo.toml crates/node/
30+ COPY crates/rollkit/Cargo.toml crates/rollkit/
31+ COPY crates/tests/Cargo.toml crates/tests/
32+
33+ ARG BUILD_PROFILE=docker
34+ ENV BUILD_PROFILE=$BUILD_PROFILE
35+
36+ # Set memory-efficient build flags
37+ ARG RUSTFLAGS="-C codegen-units=1"
38+ ENV RUSTFLAGS="$RUSTFLAGS"
39+ ENV CARGO_BUILD_JOBS=2
40+ ENV CARGO_INCREMENTAL=0
41+
42+ # Cook dependencies first (better layer caching)
43+ RUN cargo chef cook --profile $BUILD_PROFILE --recipe-path recipe.json --manifest-path bin/lumen/Cargo.toml
1844
19- # Build the application
20- RUN cargo build --release --bin lumen
45+ # Copy all source code
46+ COPY . .
2147
22- # Runtime stage
23- FROM gcr.io/distroless/cc-debian12
48+ # Build the binary with memory-efficient settings
49+ RUN cargo build --profile $BUILD_PROFILE --bin lumen --manifest-path bin/lumen/Cargo.toml -j 2
50+
51+ # Copy binary from correct location
52+ RUN ls -la /app/target/$BUILD_PROFILE/lumen
53+ RUN cp /app/target/$BUILD_PROFILE/lumen /lumen
54+
55+ FROM ubuntu:22.04 AS runtime
56+
57+ RUN apt-get update && \
58+ apt-get install -y ca-certificates libssl-dev pkg-config strace && \
59+ rm -rf /var/lib/apt/lists/*
60+
61+ WORKDIR /app
62+ COPY --from=builder /lumen /usr/local/bin/
63+ RUN chmod +x /usr/local/bin/lumen
64+ COPY LICENSE-* ./
2465
25- # Copy the binary from builder
26- COPY --from=builder /app/target/release/lumen /usr/local/bin/lumen
66+ # Expose ports: P2P, Discovery, Metrics, JSON-RPC, WebSocket, GraphQL, Engine API
67+ EXPOSE 30303 30303/udp 9001 8545 8546 7545 8551
2768
28- # Expose default ports
29- EXPOSE 8545 8546 30303 6060 9001
69+ # Add health check
70+ HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
71+ CMD /usr/local/bin/lumen --version || exit 1
3072
31- # Set the entrypoint
32- ENTRYPOINT ["/usr/local/bin/lumen" ]
73+ ENTRYPOINT ["/usr/local/bin/lumen" ]
0 commit comments