Skip to content

Commit cc0bf4e

Browse files
authored
Merge pull request #4 from use-ink/frank/optimise-image
build: optimize dockerfile
2 parents ac4f226 + cd9c066 commit cc0bf4e

File tree

1 file changed

+55
-56
lines changed

1 file changed

+55
-56
lines changed

ci/Dockerfile

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
FROM docker.io/library/debian:stable-slim
22

33
### meta ###
4-
ENV RUST_STABLE_VERSION=1.85.0 \
4+
ENV RUST_STABLE_VERSION=1.86.0 \
5+
# restricted by https://github.com/trailofbits/dylint/blob/master/examples/general/rust-toolchain
56
RUST_NIGHTLY_VERSION=2025-02-20 \
6-
POLKADOT_SDK_HASH=c6249dca5928c12c35c577b971277d4211c928b7
7+
POLKADOT_SDK_BRANCH=stable2503
78

89
WORKDIR /builds
910

@@ -14,6 +15,9 @@ ENV SHELL=/bin/bash \
1415
PATH=/usr/local/cargo/bin:$PATH \
1516
RUST_BACKTRACE=1
1617

18+
ARG TARGETARCH
19+
ENV ARCH=$TARGETARCH
20+
1721
### base ###
1822

1923
# base | add non-root user
@@ -31,80 +35,89 @@ RUN set -eux; \
3135
# needed for `paritytech/revive`
3236
libtinfo-dev \
3337
# needed for `cargo-spellcheck`
34-
libclang-dev
38+
libclang-dev && \
39+
# base | clean up layer
40+
apt-get autoremove -y && \
41+
apt-get clean && \
42+
rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man /usr/local/doc /usr/lib/llvm-11 /tmp/* /var/tmp/*
3543

3644
### generic ci ####
3745

3846
ARG GH_TOOL_VERSION="2.54.0"
3947

40-
RUN wget "https://github.com/cli/cli/releases/download/v${GH_TOOL_VERSION}/gh_${GH_TOOL_VERSION}_linux_amd64.deb" && \
41-
dpkg -i "gh_${GH_TOOL_VERSION}_linux_amd64.deb" && rm "gh_${GH_TOOL_VERSION}_linux_amd64.deb"
48+
RUN wget "https://github.com/cli/cli/releases/download/v${GH_TOOL_VERSION}/gh_${GH_TOOL_VERSION}_linux_${TARGETARCH}.deb" && \
49+
dpkg -i "gh_${GH_TOOL_VERSION}_linux_${TARGETARCH}.deb" && \
50+
rm "gh_${GH_TOOL_VERSION}_linux_${TARGETARCH}.deb"
4251

43-
# generic ci | install stable rust
52+
# generic ci | install rust toolchains
4453
# llvm-tools-preview is for grcov
4554
# base | install rustup, use minimum components
46-
RUN curl -L "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init" \
47-
-o rustup-init && \
55+
RUN case ${TARGETARCH} in \
56+
"amd64") RUST_ARCH="x86_64" ;; \
57+
"arm64") RUST_ARCH="aarch64" ;; \
58+
*) RUST_ARCH=${TARGETARCH} ;; \
59+
esac && \
60+
curl -L "https://static.rust-lang.org/rustup/dist/${RUST_ARCH}-unknown-linux-gnu/rustup-init" -o rustup-init && \
4861
chmod u+x rustup-init && \
4962
./rustup-init -y --no-modify-path --default-toolchain none && \
5063
rm -f rustup-init && \
5164
chown -R root:nonroot ${RUSTUP_HOME} ${CARGO_HOME} && \
5265
chmod -R g+w ${RUSTUP_HOME} ${CARGO_HOME} && \
66+
# generic ci | install specific stable version
5367
rustup toolchain install "${RUST_STABLE_VERSION}" --profile minimal \
5468
--component rustfmt,clippy,rust-src,llvm-tools-preview && \
5569
rustup default "${RUST_STABLE_VERSION}" && \
5670
rm -rf "${CARGO_HOME}/registry" "${CARGO_HOME}/git" && \
5771
# generic ci | "alias" pinned stable toolchain as generic stable
58-
ln -s "/usr/local/rustup/toolchains/${RUST_STABLE_VERSION}-x86_64-unknown-linux-gnu" /usr/local/rustup/toolchains/stable-x86_64-unknown-linux-gnu && \
59-
# generic ci | install asm toolchain for the default stable toolchain
60-
rustup target add riscv64imac-unknown-none-elf && \
61-
# needed for `ink-node`
62-
rustup target add wasm32v1-none && \
63-
cargo install --git https://github.com/use-ink/ink-node --branch main --force --locked && \
72+
ln -s "/usr/local/rustup/toolchains/${RUST_STABLE_VERSION}-${RUST_ARCH}-unknown-linux-gnu" "/usr/local/rustup/toolchains/stable-${RUST_ARCH}-unknown-linux-gnu" && \
73+
# generic ci | install asm toolchain for the default stable toolchain; `wasm32v1-none` for `ink-node`
74+
rustup target add riscv64imac-unknown-none-elf wasm32v1-none && \
6475
# generic ci | install specific rust nightly, default is stable, use minimum components
6576
rustup toolchain install "nightly-${RUST_NIGHTLY_VERSION}" --profile minimal \
66-
--component rustfmt,clippy,rust-analyzer,llvm-tools,rustc-dev,rust-src,llvm-tools-preview && \
67-
rustup toolchain install "nightly" --profile minimal \
68-
--component rustfmt,clippy,rust-analyzer,llvm-tools,rustc-dev,rust-src,llvm-tools-preview && \
69-
# generic ci | "alias" pinned nightly toolchain as generic nightly
70-
rustup target add riscv64imac-unknown-none-elf \
71-
--toolchain "nightly" && \
72-
rustup default nightly && \
73-
rustup target add riscv64imac-unknown-none-elf \
74-
--toolchain "nightly-${RUST_NIGHTLY_VERSION}" && \
75-
rustup run nightly-${RUST_NIGHTLY_VERSION} cargo install cargo-dylint dylint-link && \
76-
cargo install cargo-spellcheck --locked && \
77-
cargo install cargo-nextest --locked && \
77+
--component rustfmt,clippy,rust-analyzer,rustc-dev,rust-src,llvm-tools-preview && \
78+
# generic ci | "alias" pinned nightly toolchain as rolling nightly
79+
ln -s "/usr/local/rustup/toolchains/nightly-${RUST_NIGHTLY_VERSION}-${RUST_ARCH}-unknown-linux-gnu" "/usr/local/rustup/toolchains/nightly-${RUST_ARCH}-unknown-linux-gnu" && \
80+
# generic ci | install asm toolchain for the nightly toolchain
81+
rustup target add riscv64imac-unknown-none-elf --toolchain "nightly" && \
82+
# generic ci | clean up layer
83+
rm -rf "${RUSTUP_HOME}/downloads" "${RUSTUP_HOME}/tmp"
84+
85+
# generic ci | install core packages
86+
RUN cargo +nightly install cargo-dylint dylint-link && \
87+
cargo install cargo-spellcheck cargo-nextest xargo --locked && \
7888
cargo install zepter --locked --version 1.5.1 && \
79-
cargo install --git https://github.com/paritytech/cargo-contract \
80-
--locked --branch master && \
81-
git clone https://github.com/paritytech/polkadot-sdk.git --depth 50 && \
89+
cargo install --git https://github.com/use-ink/ink-node --branch main --force --locked && \
90+
cargo install --git https://github.com/use-ink/cargo-contract --locked --branch master && \
91+
git clone https://github.com/paritytech/polkadot-sdk.git -b ${POLKADOT_SDK_BRANCH} --depth 1 && \
8292
cd polkadot-sdk/ && \
83-
git reset --hard ${POLKADOT_SDK_HASH} && \
8493
cargo +nightly install --path substrate/bin/utils/subkey --locked && \
8594
cargo +nightly install --path substrate/frame/revive/rpc --locked && \
8695
cd ../ && rm -rf polkadot-sdk/ && \
8796
# We require `grcov` for coverage reporting and `rust-covfix` to improve it.
88-
cargo install grcov rust-covfix && \
89-
# codecov
90-
cargo +nightly install grcov rust-covfix xargo dylint-link && \
97+
cargo +nightly install grcov rust-covfix --locked && \
9198
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --import && \
9299
# Download the binary release of `paritytech/revive`
93-
curl -L https://github.com/paritytech/revive/releases/download/v0.1.0-dev.12/resolc-x86_64-unknown-linux-musl.tar.gz > resolc.tar.gz && \
94-
tar -xvzf resolc.tar.gz && \
95-
rm resolc.tar.gz && \
96-
chmod +x resolc-x86_64-unknown-linux-musl && \
97-
mv resolc-x86_64-unknown-linux-musl /usr/local/bin/resolc
100+
if [ "$TARGETARCH" = "amd64" ]; then \
101+
curl -fsSL -O https://github.com/paritytech/revive/releases/download/v0.1.0-dev.13/resolc-x86_64-unknown-linux-musl && \
102+
chmod +x resolc-x86_64-unknown-linux-musl && \
103+
mv resolc-x86_64-unknown-linux-musl /usr/local/bin/resolc; \
104+
else \
105+
echo "Skipping x86_64 specific installation of resolc for $TARGETARCH"; \
106+
fi && \
107+
# generic ci | clean up layer
108+
rm -rf "${CARGO_HOME}/registry" "${CARGO_HOME}/git"
98109

99110
# Install node.js 22.x. Used for testing revive with hardhat.
100111
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
101112
apt-get install -y nodejs && \
102113
node -v && npm -v && npx -v && \
103114
apt-get autoremove -y && \
104-
apt-get clean
115+
apt-get clean && \
116+
rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man
105117

106118
# codecov uploader
107119
ARG CODECOV_UPLOADER_VERSION="v0.7.3"
120+
ARG CODECOV_CLI_VERSION="v0.6.0"
108121

109122
RUN curl --remote-name --silent https://uploader.codecov.io/${CODECOV_UPLOADER_VERSION}/linux/codecov && \
110123
curl --remote-name --silent https://uploader.codecov.io/${CODECOV_UPLOADER_VERSION}/linux/codecov.SHA256SUM && \
@@ -113,27 +126,13 @@ RUN curl --remote-name --silent https://uploader.codecov.io/${CODECOV_UPLOADER_V
113126
shasum --algorithm 256 --check codecov.SHA256SUM && \
114127
chmod +x codecov && \
115128
mv codecov /usr/local/bin/codecov && \
116-
rm -f codecov.SHA256SUM codecov.SHA256SUM.sig
117-
118-
# codecov-cli
119-
ARG CODECOV_CLI_VERSION="v0.6.0"
120-
121-
RUN curl -Os https://cli.codecov.io/${CODECOV_CLI_VERSION}/linux/codecov && \
129+
rm -f codecov.SHA256SUM codecov.SHA256SUM.sig && \
130+
# codecov-cli
131+
curl -Os https://cli.codecov.io/${CODECOV_CLI_VERSION}/linux/codecov && \
122132
curl -Os https://cli.codecov.io/${CODECOV_CLI_VERSION}/linux/codecov.SHA256SUM && \
123133
curl -Os https://cli.codecov.io/${CODECOV_CLI_VERSION}/linux/codecov.SHA256SUM.sig && \
124134
gpg --verify codecov.SHA256SUM.sig codecov.SHA256SUM && \
125135
shasum -a 256 -c codecov.SHA256SUM && \
126136
chmod +x codecov && \
127137
mv codecov /usr/local/bin/codecovcli && \
128138
rm -f codecov.SHA256SUM codecov.SHA256SUM.sig
129-
130-
### finalize ###
131-
132-
# finalize | apt clean up
133-
RUN rm -rf "${CARGO_HOME}/registry" "${CARGO_HOME}/git" && \
134-
apt-get autoremove -y && \
135-
apt-get clean && \
136-
rm -rf /var/lib/apt/lists/* \
137-
rm -rf /usr/local/doc \
138-
rm -rf /usr/lib/llvm-11 \
139-
rm -rf /tmp/*

0 commit comments

Comments
 (0)