@@ -17,13 +17,64 @@ RUN protoc --go_out=./ proto/libp2p.proto
17
17
RUN go mod download
18
18
RUN go build -o libp2p_port
19
19
20
+ # Precompile rust crates
21
+ # bls nif
22
+ FROM rust:1.71.1 AS bls_nif_builder
23
+ LABEL stage=builder
24
+
25
+ RUN mkdir /bls_nif
26
+ WORKDIR /bls_nif
27
+
28
+ COPY ./native/bls_nif /bls_nif
29
+ RUN cargo build --release && \
30
+ mv target/release/libbls_nif.so ./libbls_nif.so && \
31
+ rm -rf target/
32
+
33
+ # kzg nif
34
+ FROM rust:1.71.1 AS kzg_nif_builder
35
+ LABEL stage=builder
36
+
37
+ RUN mkdir /kzg_nif
38
+ WORKDIR /kzg_nif
39
+
40
+ COPY ./native/kzg_nif /kzg_nif
41
+ RUN cargo build --release && \
42
+ mv target/release/libkzg_nif.so ./libkzg_nif.so && \
43
+ rm -rf target/
44
+
45
+ # snappy nif
46
+ FROM rust:1.71.1 AS snappy_nif_builder
47
+ LABEL stage=builder
48
+
49
+ RUN mkdir /snappy_nif
50
+ WORKDIR /snappy_nif
51
+
52
+ COPY ./native/snappy_nif /snappy_nif
53
+ RUN cargo build --release && \
54
+ mv target/release/libsnappy_nif.so ./libsnappy_nif.so && \
55
+ rm -rf target/
56
+
57
+ # ssz nif
58
+ FROM rust:1.71.1 AS ssz_nif_builder
59
+ LABEL stage=builder
60
+
61
+ RUN mkdir /ssz_nif
62
+ WORKDIR /ssz_nif
63
+
64
+ COPY ./native/ssz_nif /ssz_nif
65
+ RUN cargo build --release && \
66
+ mv target/release/libssz_nif.so ./libssz_nif.so && \
67
+ rm -rf target/
68
+
20
69
# Main image
21
70
FROM elixir:1.16.2-otp-26
22
71
23
72
RUN mkdir /consensus
24
73
WORKDIR /consensus
25
74
26
75
ENV MIX_ENV=prod
76
+ # To avoid recompiling rustler NIFs
77
+ ENV RUSTLER_SKIP_COMPILE=yes
27
78
28
79
RUN mix local.hex --force
29
80
@@ -38,21 +89,11 @@ COPY Makefile .oapi_version /consensus/
38
89
RUN make download-beacon-node-oapi
39
90
40
91
# Install rust
92
+ # NOTE: this is needed for some dependencies
41
93
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
42
94
43
95
ENV PATH="${PATH}:/root/.cargo/bin:/root/.mix/escripts"
44
96
45
- # Precompile rust crates. Rustler stores targets under _build
46
- COPY ./native /consensus/native
47
- RUN cd /consensus/native/bls_nif && cargo build --release \
48
- --target-dir="/consensus/_build/prod/lib/lambda_ethereum_consensus/native/bls_nif"
49
- RUN cd /consensus/native/kzg_nif && cargo build --release \
50
- --target-dir="/consensus/_build/prod/lib/lambda_ethereum_consensus/native/kzg_nif"
51
- RUN cd /consensus/native/snappy_nif && cargo build --release \
52
- --target-dir="/consensus/_build/prod/lib/lambda_ethereum_consensus/native/snappy_nif"
53
- RUN cd /consensus/native/ssz_nif && cargo build --release \
54
- --target-dir="/consensus/_build/prod/lib/lambda_ethereum_consensus/native/ssz_nif"
55
-
56
97
# Precompile elixir dependencies
57
98
COPY mix.exs mix.lock .fork_version ./
58
99
COPY ./config/config.exs /consensus/config/config.exs
@@ -61,6 +102,12 @@ RUN mix deps.compile
61
102
62
103
COPY . .
63
104
COPY --from=libp2p_builder /libp2p_port/libp2p_port /consensus/priv/native/libp2p_port
105
+ # TODO: only copy artifacts
106
+ # Copy precompiled rust crates. Rustler stores targets under _build
107
+ COPY --from=bls_nif_builder /bls_nif/libbls_nif.so /consensus/priv/native/libbls_nif.so
108
+ COPY --from=kzg_nif_builder /kzg_nif/libkzg_nif.so /consensus/priv/native/libkzg_nif.so
109
+ COPY --from=snappy_nif_builder /snappy_nif/libsnappy_nif.so /consensus/priv/native/libsnappy_nif.so
110
+ COPY --from=ssz_nif_builder /ssz_nif/libssz_nif.so /consensus/priv/native/libssz_nif.so
64
111
65
112
RUN protoc --elixir_out=. proto/libp2p.proto
66
113
0 commit comments