-
Notifications
You must be signed in to change notification settings - Fork 7
/
Dockerfile
95 lines (73 loc) · 2.58 KB
/
Dockerfile
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
########## Toolchain (Rust) image ##########
############################################
FROM debian:11 AS toolchain
ARG DEBIAN_FRONTEND=noninteractive
# Add .cargo/bin to PATH
ENV PATH="/root/.cargo/bin:${PATH}"
# Install system prerequisites
RUN apt-get update -y -q && apt-get install -y -q \
build-essential \
curl \
cmake \
clang \
git \
libgmp3-dev \
libssl-dev \
llvm \
lld \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
# Install Rust
RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y
# Install cargo libraries
RUN cargo install toml-cli
RUN cargo install sccache
########## Source image ###########
############################################
FROM toolchain as source
# Clone given release tag or branch of this repo
ARG REPO=https://github.com/0LNetworkCommunity/libra.git
ARG BRANCH=main
# Add target binaries to PATH
ENV SOURCE_PATH="/root/libra-framework" \
PATH="/root/libra-framework/target/release:${PATH}"
WORKDIR /root/libra-framework
# Fixme(nourspace): depending where these tools are hosted, we might not need to pull
RUN echo "Checking out '${BRANCH}' from '${REPO}' ..." \
&& git clone --branch ${BRANCH} --depth 1 ${REPO} ${SOURCE_PATH} \
&& echo "Commit hash: $(git rev-parse HEAD)"
########## Builder image ##########
############################################
FROM source as builder
# # Build 0L binaries
# RUN RUSTC_WRAPPER=sccache make bins
# Build the specified Rust packages as release binaries
RUN cargo build --release \
-p libra \
-p libra-genesis-tools \
-p libra-txs \
-p diem-db-tool
########## Production image ##########
############################################
# Todo(nourspace): find a smaller base image
# build the Rust binaries using the x86_64-unknown-linux-musl target instead of the default
# x86_64-unknown-linux-gnu target, since Alpine Linux uses musl-libc instead of glibc for its C
FROM debian:11-slim AS prod
# We don't persist this env var in production image as we don't have the source files
ARG SOURCE_PATH="/root/libra-framework"
# Add 0L binaries to PATH
ENV PATH="${SOURCE_PATH}/target/release:${PATH}"
# Install system prerequisites
RUN apt-get update && apt-get install -y \
curl \
libssl1.1 \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Copy binaries from builder
COPY --from=builder [ \
"${SOURCE_PATH}/target/release/libra", \
"${SOURCE_PATH}/target/release/libra-genesis-tools", \
"${SOURCE_PATH}/target/release/libra-txs", \
"${SOURCE_PATH}/target/release/diem-db-tool", \
"${SOURCE_PATH}/target/release/" \
]
WORKDIR /root