Skip to content

Commit

Permalink
🧹 Speed up base image build (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista authored Aug 8, 2024
1 parent 6b1ab64 commit 866ba45
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 34 deletions.
67 changes: 55 additions & 12 deletions .github/workflows/reusable-publish-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,62 @@ env:
IMAGE_NAMESPACE: ${{ github.repository_owner }}

jobs:
build:
name: Build docker image
build-base:
name: Build base image
runs-on: ubuntu-latest-4xlarge

permissions:
contents: read
packages: write

strategy:
matrix:
include:
- image: devtools-dev-base
target: base
- image: devtools-dev-node-evm-hardhat
target: node-evm-hardhat
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAMESPACE }}/devtools-dev-base
tags: |
type=ref,event=branch
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ github.sha }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push base image
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
with:
provenance: false
context: .
platforms: linux/amd64,linux/arm64
push: true
target: base
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha
cache-to: type=gha,mode=max

build-node-evm:
name: Build EVM node image
runs-on: ubuntu-latest-4xlarge
needs:
- build-base

permissions:
contents: read
packages: write

steps:
- name: Checkout repository
Expand All @@ -50,7 +91,7 @@ jobs:
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAMESPACE }}/${{ matrix.image }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAMESPACE }}/devtools-dev-node-evm-hardhat
tags: |
type=ref,event=branch
type=raw,value=latest,enable={{is_default_branch}}
Expand All @@ -59,14 +100,16 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
- name: Build and push EVM node image
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
with:
provenance: false
context: .
platforms: linux/amd64,linux/arm64
push: true
target: ${{ matrix.target }}
target: node-evm-hardhat
build-args: |
BASE_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAMESPACE }}/devtools-dev-base:${{ github.sha }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
Expand Down
40 changes: 18 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ WORKDIR /app

# We'll add an empty NPM_TOKEN to suppress any warnings
ENV NPM_TOKEN=
ENV PATH "/root/.cargo/bin:/root/.foundry/bin:/root/.solana/bin:$PATH"
# 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 the system packages
Expand All @@ -66,31 +68,24 @@ RUN apt-get install --yes \
pkg-config libudev-dev llvm libclang-dev protobuf-compiler

# Install rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
RUN rustup default ${RUST_TOOLCHAIN_VERSION}
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${RUST_TOOLCHAIN_VERSION}

# Build Solana from source
#
# This is necessary since developer machines' are running M2 processors
# and solana does not build for linux on M2
#
# First we download & extract the source code
RUN curl -s -L https://github.com/solana-labs/solana/archive/refs/tags/v${SOLANA_VERSION}.tar.gz | tar -xz

# Then we install the binaries (validator is enough)
RUN ./solana-${SOLANA_VERSION}/scripts/cargo-install-all.sh --validator-only ~/.solana

# Update the solana config
# RUN solana config set --url https://api.devnet.solana.com

# Build BPF SDK
RUN cargo install --path ./solana-${SOLANA_VERSION}/sdk/cargo-build-bpf

# Delete the source files
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 || \
# 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 \
)

# Delete the source files (only left behind if solana was build from source)
RUN rm -rf ./solana-*

# Install AVM - Anchor version manager for Solana
RUN cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
RUN cargo install --git https://github.com/coral-xyz/anchor avm

# Install anchor
RUN avm install latest && avm use latest
Expand Down Expand Up @@ -118,6 +113,7 @@ RUN node -v
RUN pnpm --version
RUN git --version
RUN anchor --version
RUN avm --version
RUN forge --version
RUN anvil --version
RUN chisel --version
Expand Down

0 comments on commit 866ba45

Please sign in to comment.