From 23dc2d5939853a7167c4878a6f8cf7a72dcb7004 Mon Sep 17 00:00:00 2001 From: mm Date: Mon, 13 May 2024 18:29:23 +0200 Subject: [PATCH 1/7] lowering size of the zk_env image --- docker/zk-environment/Dockerfile | 43 +++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/docker/zk-environment/Dockerfile b/docker/zk-environment/Dockerfile index 6690d317d2a3..3828ef60d801 100644 --- a/docker/zk-environment/Dockerfile +++ b/docker/zk-environment/Dockerfile @@ -20,10 +20,28 @@ RUN git submodule update --init --recursive # Build Solidity WORKDIR /solidity/build -RUN cmake .. +# The default compilation is Release with Debug symbols, which is quite large. +RUN cmake .. -DCMAKE_BUILD_TYPE="Release" RUN make -FROM debian:bookworm as rust-lightweight +# Rust binaries - with a separate builder. +FROM rust:slim-bookworm as rust-builder + +ARG ARCH=amd64 +RUN apt-get update && apt-get install -y \ + libssl-dev \ + pkg-config \ + libclang-15-dev \ + g++ + +RUN cargo install --version=0.7.3 sqlx-cli +RUN cargo install cargo-nextest +RUN cargo install cargo-spellcheck +RUN cargo install sccache + + +# Main builder. +FROM debian:bookworm as rust-lightweight-base ARG ARCH=amd64 @@ -100,13 +118,13 @@ RUN echo "deb [arch=${ARCH}] http://packages.cloud.google.com/apt cloud-sdk main gcloud config set component_manager/disable_update_check true && \ gcloud config set metrics/environment github_docker_image -RUN wget -c -O - https://sh.rustup.rs | bash -s -- -y && \ - rustup default stable - -RUN cargo install --version=0.7.3 sqlx-cli -RUN cargo install cargo-nextest -RUN cargo install cargo-spellcheck +COPY --from=rust-builder /usr/local/cargo/bin/sqlx \ + /usr/local/cargo/bin/cargo-sqlx \ + /usr/local/cargo/bin/cargo-nextest \ + /usr/local/cargo/bin/cargo-spellcheck \ + /usr/local/cargo/bin/sccache /usr/local/cargo/bin/ + # Copy compiler (both solc and zksolc) binaries # Obtain `solc` 0.8.20. COPY --from=solidity-builder /solidity/build/solc/solc /usr/bin/ @@ -129,10 +147,11 @@ RUN wget -c https://sourceware.org/pub/valgrind/valgrind-3.20.0.tar.bz2 && \ ENV ZKSYNC_HOME=/usr/src/zksync ENV PATH="${ZKSYNC_HOME}/bin:${PATH}" ENV CI=1 -RUN cargo install sccache ENV RUSTC_WRAPPER=/usr/local/cargo/bin/sccache -FROM rust-lightweight as rust-lightweight-nightly +FROM rust-lightweight-base as rust-lightweight +RUN wget -c -O - https://sh.rustup.rs | bash -s -- -y + -RUN rustup install nightly-2023-08-21 && \ - rustup default nightly-2023-08-21 +FROM rust-lightweight-base as rust-lightweight-nightly +RUN wget -c -O - https://sh.rustup.rs | bash -s -- -y --default-toolchain nightly-2023-08-21 From 016d952fce0ba8c8e8b46d43ad6dc6a211b77041 Mon Sep 17 00:00:00 2001 From: mm Date: Mon, 13 May 2024 19:22:39 +0200 Subject: [PATCH 2/7] don't install more clang versions --- docker/zk-environment/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/zk-environment/Dockerfile b/docker/zk-environment/Dockerfile index 3828ef60d801..73dfe1f5b903 100644 --- a/docker/zk-environment/Dockerfile +++ b/docker/zk-environment/Dockerfile @@ -82,7 +82,7 @@ RUN apt-get update && \ lldb-15 \ lld-15 \ liburing-dev \ - libclang-dev + libclang-15-dev # Install Docker RUN apt-get update && \ @@ -149,9 +149,11 @@ ENV PATH="${ZKSYNC_HOME}/bin:${PATH}" ENV CI=1 ENV RUSTC_WRAPPER=/usr/local/cargo/bin/sccache +# If target is 'main' - then install default rust. FROM rust-lightweight-base as rust-lightweight RUN wget -c -O - https://sh.rustup.rs | bash -s -- -y +# If target is nightly - then install only nightly rust. FROM rust-lightweight-base as rust-lightweight-nightly RUN wget -c -O - https://sh.rustup.rs | bash -s -- -y --default-toolchain nightly-2023-08-21 From 1e39054e159a5d4b96aee7fd826610a8e3aa3e31 Mon Sep 17 00:00:00 2001 From: mm Date: Wed, 5 Jun 2024 13:33:24 +0200 Subject: [PATCH 3/7] merge artifacts --- docker/zk-environment/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/zk-environment/Dockerfile b/docker/zk-environment/Dockerfile index 1de18b42d668..9ac84c048c78 100644 --- a/docker/zk-environment/Dockerfile +++ b/docker/zk-environment/Dockerfile @@ -160,4 +160,4 @@ RUN wget -c -O - https://sh.rustup.rs | bash -s -- -y # If target is nightly - then install only nightly rust. FROM rust-lightweight-base as rust-lightweight-nightly -RUN wget -c -O - https://sh.rustup.rs | bash -s -- -y --default-toolchain nightly-2023-08-21 +RUN wget -c -O - https://sh.rustup.rs | bash -s -- -y --default-toolchain nightly-2024-05-07 From a8fdf21d5815fd9a7af08558f5c2f85aff7c69c3 Mon Sep 17 00:00:00 2001 From: mm Date: Wed, 5 Jun 2024 15:36:14 +0200 Subject: [PATCH 4/7] moving forge and cast --- docker/zk-environment/Dockerfile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docker/zk-environment/Dockerfile b/docker/zk-environment/Dockerfile index 9ac84c048c78..2113966b4bbd 100644 --- a/docker/zk-environment/Dockerfile +++ b/docker/zk-environment/Dockerfile @@ -22,7 +22,7 @@ RUN git submodule update --init --recursive WORKDIR /solidity/build # The default compilation is Release with Debug symbols, which is quite large. RUN cmake .. -DCMAKE_BUILD_TYPE="Release" -RUN make +RUN make -j # Rust binaries - with a separate builder. FROM rust:slim-bookworm as rust-builder @@ -32,13 +32,16 @@ RUN apt-get update && apt-get install -y \ libssl-dev \ pkg-config \ libclang-15-dev \ - g++ + g++ \ + cmake RUN cargo install --version=0.7.3 sqlx-cli RUN cargo install cargo-nextest RUN cargo install cargo-spellcheck RUN cargo install sccache +RUN cargo install --git https://github.com/foundry-rs/foundry \ + --profile local --locked forge cast # Main builder. FROM debian:bookworm as rust-lightweight-base @@ -123,7 +126,9 @@ COPY --from=rust-builder /usr/local/cargo/bin/sqlx \ /usr/local/cargo/bin/cargo-sqlx \ /usr/local/cargo/bin/cargo-nextest \ /usr/local/cargo/bin/cargo-spellcheck \ - /usr/local/cargo/bin/sccache /usr/local/cargo/bin/ + /usr/local/cargo/bin/sccache \ + /usr/local/cargo/bin/forge \ + /usr/local/cargo/bin/cast /usr/local/cargo/bin/ # Copy compiler (both solc and zksolc) binaries # Obtain `solc` 0.8.20. @@ -143,9 +148,6 @@ RUN wget -c https://sourceware.org/pub/valgrind/valgrind-3.20.0.tar.bz2 && \ cd valgrind-3.20.0 && ./configure && make && make install && \ cd ../ && rm -rf valgrind-3.20.0.tar.bz2 && rm -rf valgrind-3.20.0 -# Install foundry -RUN cargo install --git https://github.com/foundry-rs/foundry \ - --profile local --locked forge cast # Setup the environment ENV ZKSYNC_HOME=/usr/src/zksync From bff90155d7dc2af731a5983a0d5cccbabaa4c7a8 Mon Sep 17 00:00:00 2001 From: mm Date: Wed, 5 Jun 2024 16:48:22 +0200 Subject: [PATCH 5/7] smaller google cli --- docker/zk-environment/Dockerfile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docker/zk-environment/Dockerfile b/docker/zk-environment/Dockerfile index 2113966b4bbd..792e9d058133 100644 --- a/docker/zk-environment/Dockerfile +++ b/docker/zk-environment/Dockerfile @@ -113,14 +113,19 @@ ENV RUSTUP_HOME=/usr/local/rustup \ PATH=/usr/local/cargo/bin:$PATH # Install gloud for GCR/GAR login +# Google was super lazy, and their package is around 1 GB. +# So we trim it a little bit based on info from `https://github.com/GoogleCloudPlatform/gsutil/issues/1732` ENV GCLOUD_VERSION=451.0.1 RUN echo "deb [arch=${ARCH}] http://packages.cloud.google.com/apt cloud-sdk main" > /etc/apt/sources.list.d/google-cloud-sdk.list && \ wget -c -O - https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \ apt-get update -y && apt-get install google-cloud-cli=${GCLOUD_VERSION}-0 --no-install-recommends -y && \ gcloud config set core/disable_usage_reporting true && \ gcloud config set component_manager/disable_update_check true && \ - gcloud config set metrics/environment github_docker_image - + gcloud config set metrics/environment github_docker_image && \ + rm -rf $(find /usr/lib/google-cloud-sdk/ -regex ".*/__pycache__") && \ + rm -rf /usr/lib/google-cloud-sdk/bin/anthoscli && \ + rm -rf /usr/lib/google-cloud-sdk/platform/bundledpythonunix && \ + rm -rf /usr/lib/google-cloud-sdk/data/gcloud.json COPY --from=rust-builder /usr/local/cargo/bin/sqlx \ /usr/local/cargo/bin/cargo-sqlx \ @@ -145,7 +150,7 @@ RUN apt-get remove valgrind -y # We need valgrind 3.20, which is unavailable in repos or ppa, so we will build it from source RUN wget -c https://sourceware.org/pub/valgrind/valgrind-3.20.0.tar.bz2 && \ tar -xf valgrind-3.20.0.tar.bz2 && \ - cd valgrind-3.20.0 && ./configure && make && make install && \ + cd valgrind-3.20.0 && ./configure && make -j && make install && \ cd ../ && rm -rf valgrind-3.20.0.tar.bz2 && rm -rf valgrind-3.20.0 From 2a366764b165a1a3f591e048fb7ef57327c8616d Mon Sep 17 00:00:00 2001 From: mm Date: Wed, 11 Sep 2024 19:27:38 +0200 Subject: [PATCH 6/7] fixed missing 'git' --- docker/zk-environment/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/zk-environment/Dockerfile b/docker/zk-environment/Dockerfile index 915d4e91e9dd..4bcb45009b22 100644 --- a/docker/zk-environment/Dockerfile +++ b/docker/zk-environment/Dockerfile @@ -38,7 +38,8 @@ RUN apt-get update && apt-get install -y \ pkg-config \ libclang-15-dev \ g++ \ - cmake + cmake \ + git RUN cargo install --version=0.8.0 sqlx-cli RUN cargo install cargo-nextest From 7083639dfa3af467b036371496dd87c3e407eb0a Mon Sep 17 00:00:00 2001 From: mm Date: Wed, 11 Sep 2024 19:47:18 +0200 Subject: [PATCH 7/7] fixes --- docker/zk-environment/Dockerfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docker/zk-environment/Dockerfile b/docker/zk-environment/Dockerfile index 4bcb45009b22..53e532653111 100644 --- a/docker/zk-environment/Dockerfile +++ b/docker/zk-environment/Dockerfile @@ -48,8 +48,8 @@ RUN cargo install sccache RUN git clone https://github.com/matter-labs/foundry-zksync RUN cd foundry-zksync && cargo build --release --bins -RUN mv ./foundry-zksync/target/release/forge /usr/local/bin/ -RUN mv ./foundry-zksync/target/release/cast /usr/local/bin/ +RUN mv ./foundry-zksync/target/release/forge /usr/local/cargo/bin/ +RUN mv ./foundry-zksync/target/release/cast /usr/local/cargo/bin/ # Main builder. FROM debian:bookworm as rust-lightweight-base @@ -173,5 +173,6 @@ FROM rust-lightweight-base as rust-lightweight RUN wget -c -O - https://sh.rustup.rs | bash -s -- -y -RUN rustup install nightly-2024-08-01 && \ - rustup default nightly-2024-08-01 +# If target is nightly - then install only nightly rust. +FROM rust-lightweight-base as rust-lightweight-nightly +RUN wget -c -O - https://sh.rustup.rs | bash -s -- -y --default-toolchain nightly-2024-08-01 \ No newline at end of file