From 9772b968e3d61060eab64bae6f80646960b25c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Jakub=20Nani=C5=A1ta?= Date: Thu, 10 Oct 2024 15:38:45 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=9E=EF=B8=8F=20Add=20support=20for=20A?= =?UTF-8?q?ptos=20CLI=20to=20the=20base=20development=20images=20(#917)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workflows/reusable-publish-docker.yaml | 2 + Dockerfile | 167 +++++++++++++++--- 2 files changed, 146 insertions(+), 23 deletions(-) diff --git a/.github/workflows/reusable-publish-docker.yaml b/.github/workflows/reusable-publish-docker.yaml index 777e439cf..32efa788e 100644 --- a/.github/workflows/reusable-publish-docker.yaml +++ b/.github/workflows/reusable-publish-docker.yaml @@ -73,6 +73,8 @@ jobs: annotations: ${{ steps.meta.outputs.annotations }} cache-from: type=gha cache-to: type=gha,mode=max + build-args: | + CARGO_BUILD_JOBS=2 build-node-evm: name: Build EVM node image diff --git a/Dockerfile b/Dockerfile index f8b8de372..a396d33ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,9 +12,9 @@ # so the code will still work on node 18.16.0 ARG NODE_VERSION=20.10.0 -# We will allow consumers to override the default base image +# We will allow consumers to override build stages with prebuilt images # -# This will allow CI environments to supply the prebuilt base image +# This will allow CI environments to supply the prebuilt images # while not breaking the flow for local development # # Local development does not by default have access to GHCR and would require @@ -36,27 +36,17 @@ ARG EVM_NODE_IMAGE=node-evm-hardhat # / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ # `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' # -# Base node image with just the build tools +# Base machine image with system packages # # .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- # / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ # `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' -FROM node:$NODE_VERSION AS base +FROM node:$NODE_VERSION AS machine -ARG RUST_TOOLCHAIN_VERSION=1.75.0 -ARG SOLANA_VERSION=1.18.17 -ARG SVM_RS_VERSION=0.5.4 -ARG ANCHOR_VERSION=0.30.1 -ARG SOLC_VERSION=0.8.22 +ENV PATH="/root/.cargo/bin:$PATH" -WORKDIR /app - -# We'll add an empty NPM_TOKEN to suppress any warnings -ENV NPM_TOKEN= -# Since we either install prebuilt binary for Solana or build from source, we need to include both -# paths to binaries in the path -ENV PATH "/root/.avm/bin:/root/.cargo/bin:/root/.foundry/bin:/root/.solana/bin:/root/.local/share/solana/install/active_release/bin:$PATH" -ENV NPM_CONFIG_STORE_DIR=/pnpm +# Update package lists +RUN apt update # Update the system packages RUN apt-get update @@ -70,44 +60,175 @@ RUN apt-get install --yes \ # Parallel is a utilit we use to parallelize the BATS (user) tests parallel \ # Utilities required to build solana - pkg-config libudev-dev llvm libclang-dev protobuf-compiler + pkg-config libudev-dev llvm libclang-dev protobuf-compiler \ + # Utilities required to build aptos CLI + libssl-dev libdw-dev lld # Install rust +ARG RUST_TOOLCHAIN_VERSION=1.75.0 RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${RUST_TOOLCHAIN_VERSION} +# Install docker +RUN curl -sSL https://get.docker.com/ | sh + +# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- +# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ +# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' +# +# Image that builds Aptos developer tooling +# +# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- +# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ +# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' +FROM machine AS aptos + +WORKDIR /app/aptos + +ARG APTOS_VERSION=4.2.3 +RUN \ + (\ + # We download the source code and extract the archive + curl -s -L https://github.com/aptos-labs/aptos-core/archive/refs/tags/aptos-cli-v${APTOS_VERSION}.tar.gz | tar -xz && \ + # Then rename the directory just for convenience + mv ./aptos-core-aptos-cli-v${APTOS_VERSION} ./src \ + ) + +# Switch to the project +WORKDIR /app/aptos/src + +# Configure cargo. We want to provide a way of limiting cargo resources +# on the github runner since it is not large enough to support multiple cargo builds +ARG CARGO_BUILD_JOBS=default +ENV CARGO_BUILD_JOBS=$CARGO_BUILD_JOBS + +# Install aptos from source +RUN cargo build --package aptos --profile cli + +# Copy the build artifacts +RUN mkdir -p /root/.aptos/bin/ && cp -R ./target/cli/aptos /root/.aptos/bin/ + +# Delete the source files +RUN rm -rf /app/aptos/aptos-core + +# Make sure we can execute the binary +ENV PATH="/root/.aptos/bin:$PATH" +RUN aptos --version + +# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- +# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ +# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' +# +# Image that builds Solana developer tooling +# +# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- +# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ +# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' +FROM machine AS solana + +WORKDIR /app/solana + +# Configure cargo. We want to provide a way of limiting cargo resources +# on the github runner since it is not large enough to support multiple cargo builds +ARG CARGO_BUILD_JOBS=default +ENV CARGO_BUILD_JOBS=$CARGO_BUILD_JOBS + +# Install Solana using a binary with a fallback to installing from source +ARG SOLANA_VERSION=1.18.17 RUN \ # First we try to download prebuilt binaries for Solana - curl --proto '=https' --tlsv1.2 -sSf https://release.solana.com/v${SOLANA_VERSION}/install | sh -s || \ + (\ + curl --proto '=https' --tlsv1.2 -sSf https://release.solana.com/v${SOLANA_VERSION}/install | sh -s && \ + mkdir -p /root/.solana && \ + # Copy the active release directory into /root/.solana (using cp -L to dereference any symlinks) + cp -LR /root/.local/share/solana/install/active_release/bin /root/.solana/bin \ + ) || \ # If that doesn't work, we'll need to build Solana from source (\ # We download the source code and extract the archive curl -s -L https://github.com/solana-labs/solana/archive/refs/tags/v${SOLANA_VERSION}.tar.gz | tar -xz && \ # Then run the installer - ./solana-${SOLANA_VERSION}/scripts/cargo-install-all.sh --validator-only ~/.solana \ + ./solana-${SOLANA_VERSION}/scripts/cargo-install-all.sh --validator-only /root/.solana \ ) -# Delete the source files (only left behind if solana was build from source) +# Delete the source files (only left behind if solana was built from source) RUN rm -rf ./solana-* # Install AVM - Anchor version manager for Solana RUN cargo install --git https://github.com/coral-xyz/anchor avm # Install anchor +ARG ANCHOR_VERSION=0.30.1 RUN avm install ${ANCHOR_VERSION} RUN avm use ${ANCHOR_VERSION} +# Make sure we can execute the binaries +ENV PATH="/root/.avm/bin:/root/.solana/bin:$PATH" +RUN anchor --version +RUN avm --version +RUN solana --version + +# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- +# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ +# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' +# +# Image that builds EVM developer tooling +# +# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- +# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ +# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' +FROM machine AS evm + # Install foundry +ENV PATH="/root/.foundry/bin:$PATH" RUN curl -L https://foundry.paradigm.xyz | bash RUN foundryup # Install SVM, Solidity version manager +ARG SVM_RS_VERSION=0.5.4 RUN cargo install svm-rs@${SVM_RS_VERSION} # Install solc 0.8.22 +ARG SOLC_VERSION=0.8.22 RUN svm install ${SOLC_VERSION} -# Install docker -RUN curl -sSL https://get.docker.com/ | sh +# Make sure we can execute the binaries +RUN forge --version +RUN anvil --version +RUN chisel --version +RUN cast --version + +# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- +# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ +# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' +# +# Base node image with just the build tools +# +# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- +# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ +# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' +FROM machine AS base + +WORKDIR /app + +# We'll add an empty NPM_TOKEN to suppress any warnings +ENV NPM_TOKEN= +ENV NPM_CONFIG_STORE_DIR=/pnpm +ENV PATH="/root/.aptos/bin/root/.avm/bin:/root/.foundry/bin:/root/.solana/bin:$PATH" + +# Get aptos CLI +COPY --from=aptos /root/.aptos/bin /root/.aptos/bin + +# Get solana tooling +COPY --from=solana /root/.cargo/bin/anchor /root/.cargo/bin/anchor +COPY --from=solana /root/.cargo/bin/avm /root/.cargo/bin/avm +COPY --from=solana /root/.avm /root/.avm +COPY --from=solana /root/.solana/bin /root/.solana/bin + +# Get EVM tooling +COPY --from=evm /root/.cargo/bin/solc /root/.cargo/bin/solc +COPY --from=evm /root/.cargo/bin/svm /root/.cargo/bin/svm +COPY --from=evm /root/.foundry /root/.foundry +COPY --from=evm /root/.svm /root/.svm # Enable corepack, new node package manager manager #