Skip to content

Commit

Permalink
[testing] Enable image build testing for unmerged avalanchego version
Browse files Browse the repository at this point in the history
  • Loading branch information
marun committed Sep 20, 2024
1 parent df6ad02 commit 46a7671
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 22 deletions.
22 changes: 3 additions & 19 deletions scripts/build_antithesis_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,15 @@ set -euo pipefail
# Directory above this script
SUBNET_EVM_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )

# Allow configuring the clone path to point to a shared and/or existing clone of the avalanchego repo
AVALANCHEGO_CLONE_PATH="${AVALANCHEGO_CLONE_PATH:-${SUBNET_EVM_PATH}/avalanchego}"

# Assume it's necessary to build the avalanchego node image from source
# TODO(marun) Support use of a released node image if using a release version of avalanchego

source "${SUBNET_EVM_PATH}"/scripts/versions.sh
source "${SUBNET_EVM_PATH}"/scripts/constants.sh
source "${SUBNET_EVM_PATH}"/scripts/lib_avalanchego_clone.sh

echo "checking out target avalanchego version ${AVALANCHE_VERSION}"
if [[ -d "${AVALANCHEGO_CLONE_PATH}" ]]; then
echo "updating existing clone"
cd "${AVALANCHEGO_CLONE_PATH}"
git fetch
else
echo "creating new clone"
git clone https://github.com/ava-labs/avalanchego.git "${AVALANCHEGO_CLONE_PATH}"
cd "${AVALANCHEGO_CLONE_PATH}"
fi
# Branch will be reset to $AVALANCHE_VERSION if it already exists
git checkout -B "test-${AVALANCHE_VERSION}" "${AVALANCHE_VERSION}"
cd "${SUBNET_EVM_PATH}"

AVALANCHEGO_COMMIT_HASH="$(git --git-dir="${AVALANCHEGO_CLONE_PATH}/.git" rev-parse HEAD)"
AVALANCHEGO_IMAGE_TAG="${AVALANCHEGO_COMMIT_HASH::8}"
clone_avalanchego "${AVALANCHE_VERSION}"
AVALANCHEGO_IMAGE_TAG="$(avalanchego_image_tag_from_clone)"

# Build avalanchego node image in the clone path
pushd "${AVALANCHEGO_CLONE_PATH}" > /dev/null
Expand Down
4 changes: 2 additions & 2 deletions scripts/build_docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ if [[ "${VM_ID}" != "${DEFAULT_VM_ID}" ]]; then
fi

# Default to the release image. Will need to be overridden when testing against unreleased versions.
AVALANCHEGO_NODE_IMAGE=${AVALANCHEGO_NODE_IMAGE:-"avaplatform/avalanchego:${AVALANCHE_VERSION}"}
AVALANCHEGO_NODE_IMAGE="${AVALANCHEGO_NODE_IMAGE:-${AVALANCHEGO_IMAGE_NAME}:${AVALANCHE_VERSION}}"

echo "Building Docker Image: $DOCKERHUB_REPO:$BUILD_IMAGE_ID based of AvalancheGo@$AVALANCHE_VERSION"
docker build -t "$DOCKERHUB_REPO:$BUILD_IMAGE_ID" -t "$DOCKERHUB_REPO:${DOCKERHUB_TAG}" \
"$SUBNET_EVM_PATH" -f "$SUBNET_EVM_PATH/Dockerfile" \
--build-arg AVALANCHEGO_NODE_IMAGE="$AVALANCHEGO_NODE_IMAGE" \
--build-arg SUBNET_EVM_COMMIT="$SUBNET_EVM_COMMIT" \
--build-arg CURRENT_BRANCH="$CURRENT_BRANCH" \
--build-arg VM_ID="$VM_ID"
--build-arg VM_ID="$VM_ID"
3 changes: 3 additions & 0 deletions scripts/constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ DEFAULT_VM_ID="srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy"
# You should probably set it - export DOCKER_REPO='avaplatform/subnet-evm'
DOCKERHUB_REPO=${DOCKER_REPO:-"subnet-evm"}

# Shared between ./scripts/build_docker_image.sh and ./scripts/tests.build_docker_image.sh
AVALANCHEGO_IMAGE_NAME="${AVALANCHEGO_IMAGE_NAME:-avaplatform/avalanchego}"

# if this isn't a git repository (say building from a release), don't set our git constants.
if [ ! -d .git ]; then
CURRENT_BRANCH=""
Expand Down
37 changes: 37 additions & 0 deletions scripts/lib_avalanchego_clone.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

set -euo pipefail

# Defines functions for interacting with git clones of the avalanchego repo.

if [[ -z "${SUBNET_EVM_PATH}" ]]; then
echo "SUBNET_EVM_PATH must be set"
exit 1
fi

export AVALANCHEGO_CLONE_PATH=${AVALANCHEGO_CLONE_PATH:-${SUBNET_EVM_PATH}/avalanchego}

# Clones the avalanchego repo to the given path and checks out specified version.
function clone_avalanchego {
local avalanche_version="$1"

echo "checking out target avalanchego version ${avalanche_version}"
if [[ -d "${AVALANCHEGO_CLONE_PATH}" ]]; then
echo "updating existing clone"
cd "${AVALANCHEGO_CLONE_PATH}"
git fetch
else
echo "creating new clone"
git clone https://github.com/ava-labs/avalanchego.git "${AVALANCHEGO_CLONE_PATH}"
cd "${AVALANCHEGO_CLONE_PATH}"
fi
# Branch will be reset to $avalanche_version if it already exists
git checkout -B "test-${avalanche_version}" "${avalanche_version}"
cd "${SUBNET_EVM_PATH}"
}

# Derives an image tag from the current state of the avalanchego clone
function avalanchego_image_tag_from_clone {
local commit_hash="$(git --git-dir="${AVALANCHEGO_CLONE_PATH}/.git" rev-parse HEAD)"
echo "${commit_hash::8}"
}
21 changes: 20 additions & 1 deletion scripts/tests.build_docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,27 @@ SUBNET_EVM_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
# Load the constants
source "$SUBNET_EVM_PATH"/scripts/constants.sh

# Load the versions
source "$SUBNET_EVM_PATH"/scripts/versions.sh

# Use the default node image
AVALANCHEGO_NODE_IMAGE="${AVALANCHEGO_IMAGE_NAME}:${AVALANCHE_VERSION}"

# Build the avalanchego image if it cannot be pulled. This will usually be due to
# AVALANCHE_VERSION being not yet merged since the image is published post-merge.
if ! docker pull "${AVALANCHEGO_NODE_IMAGE}"; then
# Use a image name without a repository (i.e. without 'avaplatform/' prefix ) to build a
# local image that will not be pushed.
export AVALANCHEGO_IMAGE_NAME="avalanchego"
echo "Building ${AVALANCHEGO_IMAGE_NAME}:${AVALANCHE_VERSION} locally"

source "${SUBNET_EVM_PATH}"/scripts/lib_avalanchego_clone.sh
clone_avalanchego "${AVALANCHE_VERSION}"
SKIP_BUILD_RACE=1 DOCKER_IMAGE="${AVALANCHEGO_IMAGE_NAME}" "${AVALANCHEGO_CLONE_PATH}"/scripts/build_image.sh
fi

# Build a local image
"${SUBNET_EVM_PATH}"/scripts/build_docker_image.sh
bash -x "${SUBNET_EVM_PATH}"/scripts/build_docker_image.sh

# Check that the image can be run and contains the plugin
echo "Checking version of the plugin provided by the image"
Expand Down

0 comments on commit 46a7671

Please sign in to comment.