-
Notifications
You must be signed in to change notification settings - Fork 141
/
Dockerfile
103 lines (84 loc) · 3.42 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
96
97
98
99
100
101
102
103
# Use this with
#
# docker build -t internet-identity .
# or use ./scripts/docker-build
#
# The docker image. To update, run `docker pull ubuntu` locally, and update the
# sha256:... accordingly.
FROM --platform=linux/amd64 ubuntu@sha256:bbf3d1baa208b7649d1d0264ef7d522e1dc0deeeaaf6085bf8e4618867f03494 as deps
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 jq
# Install node
RUN curl --fail -sSf https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
ENV NVM_DIR=/root/.nvm
COPY .node-version .node-version
RUN . "$NVM_DIR/nvm.sh" && nvm install "$(cat .node-version)"
RUN . "$NVM_DIR/nvm.sh" && nvm use "v$(cat .node-version)"
RUN . "$NVM_DIR/nvm.sh" && nvm alias default "v$(cat .node-version)"
RUN ln -s "$NVM_DIR/versions/node/v$(cat .node-version)" "$NVM_DIR/versions/node/default"
ENV PATH="$NVM_DIR/versions/node/default/bin/:${PATH}"
RUN node --version
RUN npm --version
# Install Rust and Cargo in /opt
ENV RUSTUP_HOME=/opt/rustup \
CARGO_HOME=/cargo \
PATH=/cargo/bin:$PATH
RUN mkdir -p ./scripts
COPY ./scripts/bootstrap ./scripts/bootstrap
COPY ./rust-toolchain.toml ./rust-toolchain.toml
RUN ./scripts/bootstrap
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
RUN wasm-pack --version
# 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`. When we COPY the actual files we make sure to `touch` lib.rs so
# that cargo knows to rebuild it with the new content.
COPY Cargo.lock .
COPY Cargo.toml .
COPY src/internet_identity/Cargo.toml src/internet_identity/Cargo.toml
COPY src/internet_identity_interface/Cargo.toml src/internet_identity_interface/Cargo.toml
COPY src/archive/Cargo.toml src/archive/Cargo.toml
COPY src/canister_tests/Cargo.toml src/canister_tests/Cargo.toml
COPY src/sig-verifier-js/Cargo.toml src/sig-verifier-js/Cargo.toml
COPY src/asset_util/Cargo.toml src/asset_util/Cargo.toml
ENV CARGO_TARGET_DIR=/cargo_target
COPY ./scripts/build ./scripts/build
RUN mkdir -p src/internet_identity/src \
&& touch src/internet_identity/src/lib.rs \
&& mkdir -p src/internet_identity_interface/src \
&& touch src/internet_identity_interface/src/lib.rs \
&& mkdir -p src/archive/src \
&& touch src/archive/src/lib.rs \
&& mkdir -p src/canister_tests/src \
&& touch src/canister_tests/src/lib.rs \
&& mkdir -p src/sig-verifier-js/src \
&& touch src/sig-verifier-js/src/lib.rs \
&& mkdir -p src/asset_util/src \
&& touch src/asset_util/src/lib.rs \
&& ./scripts/build --only-dependencies --internet-identity --archive \
&& rm -rf src
FROM deps as build_internet_identity
COPY . .
# The version baked in
ARG II_VERSION=
# The features, see README
ARG II_FETCH_ROOT_KEY=
ARG II_DUMMY_CAPTCHA=
ARG II_DUMMY_AUTH=
ARG II_DEV_CSP=
RUN touch src/*/src/lib.rs
RUN npm ci
RUN ./scripts/build
RUN sha256sum /internet_identity.wasm.gz
FROM deps as build_archive
COPY . .
RUN touch src/*/src/lib.rs
RUN ./scripts/build --archive
RUN sha256sum /archive.wasm.gz
FROM scratch AS scratch_internet_identity
COPY --from=build_internet_identity /internet_identity.wasm.gz /
FROM scratch AS scratch_archive
COPY --from=build_archive /archive.wasm.gz /