github.com/MetalBlockchain/metalgo@v1.11.9/scripts/tests.build_image.sh (about) 1 #!/usr/bin/env bash 2 3 set -euo pipefail 4 5 # This test script is intended to execute successfully on a ubuntu 22.04 host with either the 6 # amd64 or arm64 arches. Recent docker (with buildx support) and qemu are required. See 7 # build_image.sh for more details. 8 9 # TODO(marun) Perform more extensive validation (e.g. e2e testing) against one or more images 10 11 # Directory above this script 12 AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) 13 14 source "$AVALANCHE_PATH"/scripts/constants.sh 15 16 build_and_test() { 17 local image_name=$1 18 19 DOCKER_IMAGE="$image_name" ./scripts/build_image.sh 20 21 echo "listing images" 22 docker images 23 24 local host_arch 25 host_arch="$(go env GOARCH)" 26 27 if [[ "$image_name" == *"/"* ]]; then 28 # Test all arches if testing a multi-arch image 29 local arches=("amd64" "arm64") 30 else 31 # Test only the host platform for single arch builds 32 local arches=("$host_arch") 33 fi 34 35 # Check all of the images expected to have been built 36 local target_images=( 37 "$image_name:$commit_hash" 38 "$image_name:$image_tag" 39 "$image_name:$commit_hash-race" 40 "$image_name:$image_tag-race" 41 ) 42 43 for arch in "${arches[@]}"; do 44 for target_image in "${target_images[@]}"; do 45 if [[ "$host_arch" == "amd64" && "$arch" == "arm64" && "$target_image" =~ "-race" ]]; then 46 # Error reported when trying to sanity check this configuration in github ci: 47 # 48 # FATAL: ThreadSanitizer: unsupported VMA range 49 # FATAL: Found 39 - Supported 48 50 # 51 echo "skipping sanity check for $target_image" 52 echo "image is for arm64 and binary is compiled with race detection" 53 echo "amd64 github workers are known to run kernels incompatible with these images" 54 else 55 echo "checking sanity of image $target_image for $arch by running 'avalanchego --version'" 56 docker run -t --rm --platform "linux/$arch" "$target_image" /avalanchego/build/avalanchego --version 57 fi 58 done 59 done 60 } 61 62 echo "checking build of single-arch images" 63 build_and_test avalanchego 64 65 echo "starting local docker registry to allow verification of multi-arch image builds" 66 REGISTRY_CONTAINER_ID="$(docker run --rm -d -P registry:2)" 67 REGISTRY_PORT="$(docker port "$REGISTRY_CONTAINER_ID" 5000/tcp | grep -v "::" | awk -F: '{print $NF}')" 68 69 echo "starting docker builder that supports multiplatform builds" 70 # - creating a new builder enables multiplatform builds 71 # - '--driver-opt network=host' enables the builder to use the local registry 72 docker buildx create --use --name ci-builder --driver-opt network=host 73 74 # Ensure registry and builder cleanup on teardown 75 function cleanup { 76 echo "stopping local docker registry" 77 docker stop "${REGISTRY_CONTAINER_ID}" 78 echo "removing multiplatform builder" 79 docker buildx rm ci-builder 80 } 81 trap cleanup EXIT 82 83 echo "checking build of multi-arch images" 84 build_and_test "localhost:${REGISTRY_PORT}/avalanchego"