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

use foundryup to improve build performance #4

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Changes from all 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
47 changes: 20 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ FROM debian:stable-slim as foundry-builder
# DOCKER_BUILDKIT=1 docker build . -t ...
ARG TARGETARCH
ARG MAXIMUM_THREADS=2
ARG CARGO_INCREMENTAL=0

RUN export DEBIAN_FRONTEND=noninteractive && \
apt update && \
Expand All @@ -54,39 +55,25 @@ RUN useradd --create-home -s /bin/bash xmtp
RUN usermod -a -G sudo xmtp
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers


WORKDIR /rustup
## Rust
ADD https://sh.rustup.rs /rustup/rustup.sh
RUN chmod 755 /rustup/rustup.sh
RUN chmod 555 /rustup/rustup.sh

## FoundryUp
ADD https://foundry.paradigm.xyz /rustup/foundryup.sh
RUN chmod 555 /rustup/foundryup.sh

ENV USER=xmtp
USER xmtp
RUN /rustup/rustup.sh -y --default-toolchain stable --profile minimal

## Foundry
WORKDIR /build

# latest https://github.com/foundry-rs/foundry
ENV PATH=$PATH:~xmtp/.cargo/bin
RUN git clone https://github.com/foundry-rs/foundry

## Foundry
WORKDIR /build/foundry
RUN git pull && LATEST_TAG=$(git describe --tags --abbrev=0) || LATEST_TAG=master && \
echo "building tag ${LATEST_TAG}" && \
git -c advice.detachedHead=false checkout ${LATEST_TAG} && \
. $HOME/.cargo/env && \
THREAD_NUMBER=$(cat /proc/cpuinfo | grep -c ^processor) && \
MAX_THREADS=$(( THREAD_NUMBER > ${MAXIMUM_THREADS} ? ${MAXIMUM_THREADS} : THREAD_NUMBER )) && \
echo "building with ${MAX_THREADS} threads" && \
cargo build --jobs ${MAX_THREADS} --release && \
objdump -j .comment -s target/release/forge && \
strip target/release/forge && \
strip target/release/cast && \
strip target/release/anvil && \
strip target/release/chisel

RUN git rev-parse HEAD > /build/foundry_commit_sha256
RUN /rustup/foundryup.sh

FROM debian:stable-slim as node18-slim

Expand Down Expand Up @@ -148,12 +135,18 @@ COPY --from=go-builder /usr/local/go /usr/local/go
ARG ETH_VERSION=1.13.12
COPY --from=go-builder /go-ethereum/go-ethereum-${ETH_VERSION}/build/bin /usr/local/bin

# Foundry
COPY --from=foundry-builder /build/foundry_commit_sha256 /usr/local/etc/foundry_commit_sha256
COPY --from=foundry-builder /build/foundry/target/release/forge /usr/local/bin/forge
COPY --from=foundry-builder /build/foundry/target/release/cast /usr/local/bin/cast
COPY --from=foundry-builder /build/foundry/target/release/anvil /usr/local/bin/anvil
COPY --from=foundry-builder /build/foundry/target/release/chisel /usr/local/bin/chisel
# Foundry Up
ENV USER=xmtp
USER xmtp
ENV FOUNDRY_INSTALL_DIR=/home/${USER}/.foundry
COPY --from=foundry-builder ${FOUNDRY_INSTALL_DIR} ${FOUNDRY_INSTALL_DIR}
ENV PATH=$PATH:${FOUNDRY_INSTALL_DIR}/bin
RUN foundryup

RUN strip ${FOUNDRY_INSTALL_DIR}/bin/forge
RUN strip ${FOUNDRY_INSTALL_DIR}/bin/cast
RUN strip ${FOUNDRY_INSTALL_DIR}/bin/anvil
RUN strip ${FOUNDRY_INSTALL_DIR}/bin/chisel

LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="foundry" \
Expand Down
Loading