@@ -5,34 +5,76 @@ set -euo pipefail
55# Sanity check the image build by attempting to build and run the image without error.
66
77# Directory above this script
8- SUBNET_EVM_PATH=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) " ; cd .. && pwd )
8+ SUBNET_EVM_PATH=$(
9+ cd " $( dirname " ${BASH_SOURCE[0]} " ) "
10+ cd .. && pwd
11+ )
912# Load the constants
1013source " $SUBNET_EVM_PATH " /scripts/constants.sh
1114
1215# Load the versions
1316source " $SUBNET_EVM_PATH " /scripts/versions.sh
1417
15- # Use the default node image
16- AVALANCHEGO_NODE_IMAGE=" ${AVALANCHEGO_IMAGE_NAME} :${AVALANCHE_VERSION} "
17-
18- # Build the avalanchego image if it cannot be pulled. This will usually be due to
19- # AVALANCHE_VERSION being not yet merged since the image is published post-merge.
20- if ! docker pull " ${AVALANCHEGO_NODE_IMAGE} " ; then
21- # Use a image name without a repository (i.e. without 'avaplatform/' prefix ) to build a
22- # local image that will not be pushed.
23- export AVALANCHEGO_IMAGE_NAME=" avalanchego"
24- echo " Building ${AVALANCHEGO_IMAGE_NAME} :${AVALANCHE_VERSION} locally"
25-
26- source " ${SUBNET_EVM_PATH} " /scripts/lib_avalanchego_clone.sh
27- clone_avalanchego " ${AVALANCHE_VERSION} "
28- SKIP_BUILD_RACE=1 DOCKER_IMAGE=" ${AVALANCHEGO_IMAGE_NAME} " " ${AVALANCHEGO_CLONE_PATH} " /scripts/build_image.sh
29- fi
30-
31- # Build a local image
32- bash -x " ${SUBNET_EVM_PATH} " /scripts/build_docker_image.sh
33-
34- # Check that the image can be run and contains the plugin
35- echo " Checking version of the plugin provided by the image"
36- docker run -t --rm " ${DOCKERHUB_REPO} :${DOCKERHUB_TAG} " /avalanchego/build/plugins/" ${DEFAULT_VM_ID} " --version
37- echo " " # --version output doesn't include a newline
38- echo " Successfully checked image build"
18+ build_and_test () {
19+ local imagename=" ${1} "
20+ local vm_id=" ${2} "
21+ local multiarch_image=" ${3} "
22+
23+ if [[ " ${multiarch_image} " == true ]]; then
24+ local arches=" linux/amd64,linux/arm64"
25+ else
26+ # Test only the host platform for single arch builds
27+ local host_arch
28+ host_arch=" $( go env GOARCH) "
29+ local arches=" linux/$host_arch "
30+ fi
31+
32+ local imgtag=" testtag"
33+
34+ PLATFORMS=" ${arches} " \
35+ BUILD_IMAGE_ID=" ${imgtag} " \
36+ VM_ID=$" ${vm_id} " \
37+ IMAGE_NAME=" ${imagename} " \
38+ ./scripts/build_docker_image.sh
39+
40+ echo " listing images"
41+ docker images
42+
43+ # Check all of the images expected to have been built
44+ local target_images=(
45+ " $imagename :$imgtag "
46+ " $imagename :$DOCKERHUB_TAG "
47+ )
48+ IFS=' ,' read -r -a archarray <<< " $arches"
49+ for arch in " ${archarray[@]} " ; do
50+ for target_image in " ${target_images[@]} " ; do
51+ echo " checking sanity of image $target_image for $arch by running '${VM_ID} version'"
52+ docker run -t --rm --platform " $arch " " $target_image " /avalanchego/build/plugins/" ${VM_ID} " --version
53+ done
54+ done
55+ }
56+
57+ VM_ID=" ${VM_ID:- ${DEFAULT_VM_ID} } "
58+
59+ echo " checking build of single-arch image"
60+ build_and_test " subnet-evm" " ${VM_ID} " false
61+
62+ echo " starting local docker registry to allow verification of multi-arch image builds"
63+ REGISTRY_CONTAINER_ID=" $( docker run --rm -d -P registry:2) "
64+ REGISTRY_PORT=" $( docker port " $REGISTRY_CONTAINER_ID " 5000/tcp | grep -v " ::" | awk -F: ' {print $NF}' ) "
65+
66+ echo " starting docker builder that supports multiplatform builds"
67+ # - '--driver-opt network=host' enables the builder to use the local registry
68+ docker buildx create --use --name ci-builder --driver-opt network=host
69+
70+ # Ensure registry and builder cleanup on teardown
71+ function cleanup {
72+ echo " stopping local docker registry"
73+ docker stop " ${REGISTRY_CONTAINER_ID} "
74+ echo " removing multiplatform builder"
75+ docker buildx rm ci-builder
76+ }
77+ trap cleanup EXIT
78+
79+ echo " checking build of multi-arch images"
80+ build_and_test " localhost:${REGISTRY_PORT} /subnet-evm" " ${VM_ID} " true
0 commit comments