-
Notifications
You must be signed in to change notification settings - Fork 5
/
Dockerfile
80 lines (65 loc) · 2.81 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
# This is copied and adapted from https://github.com/dfinity/exchange-rate-canister/blob/458adc36f9c3f6b7232a8868528262c0c3eb52ab/Dockerfile
# Use this with
#
# docker build . -t cycles-ledger
# container_id=$(docker create cycles-ledger no-op)
# docker cp $container_id:cycles-ledger.wasm.gz cycles-ledger.wasm.gz
# docker rm --volumes $container_id
# This is the "builder", i.e. the base image used later to build the final
# code.
FROM --platform=linux/amd64 ubuntu:20.04 as builder
SHELL ["bash", "-c"]
ARG rust_version=1.72.0
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
apt -yq update && \
apt -yqq install --no-install-recommends curl ca-certificates \
build-essential pkg-config libssl-dev llvm-dev liblmdb-dev clang cmake \
git jq
# Install Rust and Cargo in /opt
ENV RUSTUP_HOME=/opt/rustup \
CARGO_HOME=/opt/cargo \
PATH=/opt/cargo/bin:$PATH
RUN curl --fail https://sh.rustup.rs -sSf \
| sh -s -- -y --default-toolchain ${rust_version}-x86_64-unknown-linux-gnu --no-modify-path && \
rustup default ${rust_version}-x86_64-unknown-linux-gnu && \
rustup target add wasm32-unknown-unknown
ENV PATH=/cargo/bin:$PATH
# Pre-build all cargo dependencies. Because cargo doesn't have a build option
# to build only the dependencies, we pretend that our project is a simple, empty
# `lib.rs`. Then we remove the dummy source files to make sure cargo rebuild
# everything once the actual source code is COPYed (and e.g. doesn't trip on
# timestamps being older)
COPY Cargo.lock .
COPY Cargo.toml .
COPY cycles-ledger/Cargo.toml cycles-ledger/Cargo.toml
COPY depositor/Cargo.toml depositor/Cargo.toml
COPY fake-cmc/Cargo.toml fake-cmc/Cargo.toml
RUN mkdir -p cycles-ledger/src && \
touch cycles-ledger/src/lib.rs && \
mkdir -p depositor/src && \
touch depositor/src/lib.rs && \
mkdir -p fake-cmc/src && \
touch fake-cmc/src/lib.rs && \
cargo build --target wasm32-unknown-unknown --release --package cycles-ledger && \
rm -rf cycles-ledger/
# Install dfx
COPY dfx.json dfx.json
ENV PATH="/root/.local/share/dfx/bin:${PATH}"
RUN DFXVM_INIT_YES=true DFX_VERSION="$(jq -cr .dfx dfx.json)" \
sh -c "$(curl -fsSL https://internetcomputer.org/install.sh)" && \
dfx --version
# Start the second container
FROM --platform=linux/amd64 builder AS build
SHELL ["bash", "-c"]
# Build
# ... put only git-tracked files in the build directory
COPY . /build
WORKDIR /build
# Creates the wasm without creating the canister
RUN dfx build --check cycles-ledger
RUN ls -sh /build
RUN ls -sh /build/.dfx/local/canisters/cycles-ledger/cycles-ledger.wasm.gz
RUN sha256sum /build/.dfx/local/canisters/cycles-ledger/cycles-ledger.wasm.gz
FROM --platform=linux/amd64 scratch AS scratch
COPY --from=build /build/.dfx/local/canisters/cycles-ledger/cycles-ledger.wasm.gz /