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