From 5be3d84fed4505bc08815c85e18872c48b22689a Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Fri, 20 Sep 2024 11:19:51 -0700 Subject: [PATCH] [testing] Enable image build testing for unmerged avalanchego version --- scripts/build_antithesis_images.sh | 22 +++-------------- scripts/build_docker_image.sh | 4 ++-- scripts/constants.sh | 3 +++ scripts/lib_avalanchego_clone.sh | 37 +++++++++++++++++++++++++++++ scripts/tests.build_docker_image.sh | 21 +++++++++++++++- 5 files changed, 65 insertions(+), 22 deletions(-) create mode 100644 scripts/lib_avalanchego_clone.sh diff --git a/scripts/build_antithesis_images.sh b/scripts/build_antithesis_images.sh index e90cfaee8e..b0764d84b9 100755 --- a/scripts/build_antithesis_images.sh +++ b/scripts/build_antithesis_images.sh @@ -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 diff --git a/scripts/build_docker_image.sh b/scripts/build_docker_image.sh index a27ce98d56..9de30cd7e7 100755 --- a/scripts/build_docker_image.sh +++ b/scripts/build_docker_image.sh @@ -20,7 +20,7 @@ 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}" \ @@ -28,4 +28,4 @@ docker build -t "$DOCKERHUB_REPO:$BUILD_IMAGE_ID" -t "$DOCKERHUB_REPO:${DOCKERHU --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" \ No newline at end of file + --build-arg VM_ID="$VM_ID" diff --git a/scripts/constants.sh b/scripts/constants.sh index da85ae9445..4fad925775 100644 --- a/scripts/constants.sh +++ b/scripts/constants.sh @@ -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="" diff --git a/scripts/lib_avalanchego_clone.sh b/scripts/lib_avalanchego_clone.sh new file mode 100644 index 0000000000..2266ad5197 --- /dev/null +++ b/scripts/lib_avalanchego_clone.sh @@ -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}" +} diff --git a/scripts/tests.build_docker_image.sh b/scripts/tests.build_docker_image.sh index 22ebd8eeb1..8c928e25a5 100755 --- a/scripts/tests.build_docker_image.sh +++ b/scripts/tests.build_docker_image.sh @@ -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"