11# Use Rust Nightly version base image
2- FROM rustlang/rust:nightly
2+ # FROM rustlang/rust:nightly
3+ FROM --platform=$BUILDPLATFORM rustlang/rust:nightly AS builder
34
45# Set working directory
56WORKDIR /app
67
78# Install necessary dependencies, including protoc
89RUN apt-get update && apt-get install -y \
910 protobuf-compiler \
11+ gcc-aarch64-linux-gnu \
12+ libc6-dev-arm64-cross \
1013 && rm -rf /var/lib/apt/lists/*
1114
1215# Clone project code
1316RUN git clone https://github.com/MetisProtocol/malaketh-layered.git .
1417
18+ RUN rustup target add aarch64-unknown-linux-gnu
19+
20+ ARG TARGETARCH
21+
1522# Build the project
16- RUN cargo build --release
23+ RUN if [ "$TARGETARCH" = "arm64" ]; then \
24+ export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc; \
25+ cargo build --release --target aarch64-unknown-linux-gnu; \
26+ else \
27+ cargo build --release; \
28+ fi
1729
1830# Copy the generated binary to a new lightweight image
19- # FROM debian:bullseye-slim
20- # FROM debian:bookworm-slim
21- # FROM ubuntu:22.04
2231FROM ubuntu:24.04
2332
2433# Install necessary dependencies
@@ -30,11 +39,18 @@ RUN apt-get update && apt-get install -y \
3039# Set working directory
3140WORKDIR /app
3241
33- # Copy the generated binary from the previous build image
34- COPY --from=0 /app/target/release/malachitebft-eth-app /app/
35- # COPY --from=0 /app/target/release/malachitebft-eth-cli /app/
36- # COPY --from=0 /app/target/release/malachitebft-eth-engine /app/
37- COPY --from=0 /app/target/release/malachitebft-eth-utils /app/
42+ ARG TARGETARCH
43+
44+ RUN if [ "$TARGETARCH" = "arm64" ]; then \
45+ echo "aarch64-unknown-linux-gnu/" > /target-subdir.txt; \
46+ else \
47+ echo "" > /target-subdir.txt; \
48+ fi
49+
50+ RUN --mount=from=builder,source=/app/target,target=/builder-target \
51+ TARGET_SUBDIR=$(cat /target-subdir.txt) && \
52+ cp /builder-target/${TARGET_SUBDIR}release/malachitebft-eth-app /app/
53+
3854
3955# Set environment variables
4056ENV PATH="/app:${PATH}"
@@ -44,4 +60,3 @@ EXPOSE 8545 8551 9090 3000
4460
4561# Run the application (assuming you want to run malachitebft-eth-app here)
4662CMD ["malachitebft-eth-app" ]
47-
0 commit comments