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

🗞️ Add support for Aptos CLI to the base development images #917

Merged
merged 12 commits into from
Oct 10, 2024
2 changes: 2 additions & 0 deletions .github/workflows/reusable-publish-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
167 changes: 144 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
#
Expand Down
Loading