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