Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Smaller zk_environment image #1920

Merged
merged 9 commits into from
Sep 11, 2024
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 49 additions & 21 deletions docker/zk-environment/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,31 @@ RUN git submodule update --init --recursive

# Build Solidity
WORKDIR /solidity/build
RUN cmake ..
RUN make
# The default compilation is Release with Debug symbols, which is quite large.
RUN cmake .. -DCMAKE_BUILD_TYPE="Release"
RUN make -j

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++ \
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

ARG ARCH=amd64

Expand Down Expand Up @@ -64,7 +85,7 @@ RUN apt-get update && \
lldb-15 \
lld-15 \
liburing-dev \
libclang-dev
libclang-15-dev

# Install Docker
RUN apt-get update && \
Expand Down Expand Up @@ -92,21 +113,28 @@ 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

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

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 \
/usr/local/cargo/bin/cargo-nextest \
/usr/local/cargo/bin/cargo-spellcheck \
/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.
COPY --from=solidity-builder /solidity/build/solc/solc /usr/bin/
Expand All @@ -122,21 +150,21 @@ 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

# 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
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
# 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


RUN rustup install nightly-2024-05-07 && \
rustup default nightly-2024-05-07
# 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-05-07
Loading