@@ -5,8 +5,10 @@ set -euo pipefail
5
5
# Builds docker images for antithesis testing.
6
6
7
7
# e.g.,
8
- # ./scripts/build_antithesis_images.sh # Build local images
9
- # IMAGE_PREFIX=<registry>/<repo> TAG=latest ./scripts/build_antithesis_images.sh # Specify a prefix to enable image push and use a specific tag
8
+ # TEST_SETUP=avalanchego ./scripts/build_antithesis_images.sh # Build local images for avalanchego
9
+ # TEST_SETUP=avalanchego NODE_ONLY=1 ./scripts/build_antithesis_images.sh # Build only a local node image for avalanchego
10
+ # TEST_SETUP=xsvm ./scripts/build_antithesis_images.sh # Build local images for xsvm
11
+ # TEST_SETUP=xsvm IMAGE_PREFIX=<registry>/<repo> TAG=latest ./scripts/build_antithesis_images.sh # Specify a prefix to enable image push and use a specific tag
10
12
11
13
# Directory above this script
12
14
AVALANCHE_PATH=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) " ; cd .. && pwd )
@@ -28,11 +30,13 @@ GO_VERSION="$(go list -m -f '{{.GoVersion}}')"
28
30
function build_images {
29
31
local test_setup=$1
30
32
local uninstrumented_node_dockerfile=$2
33
+ local image_prefix=$3
34
+ local node_only=${4:- }
31
35
32
36
# Define image names
33
37
local base_image_name=" antithesis-${test_setup} "
34
- if [[ -n " ${IMAGE_PREFIX } " ]]; then
35
- base_image_name=" ${IMAGE_PREFIX } /${base_image_name} "
38
+ if [[ -n " ${image_prefix } " ]]; then
39
+ base_image_name=" ${image_prefix } /${base_image_name} "
36
40
fi
37
41
local node_image_name=" ${base_image_name} -node:${TAG} "
38
42
local workload_image_name=" ${base_image_name} -workload:${TAG} "
@@ -49,22 +53,65 @@ function build_images {
49
53
fi
50
54
51
55
# Define default build command
52
- local docker_cmd=" docker buildx build --build-arg GO_VERSION=${GO_VERSION} "
53
- if [[ -n " ${IMAGE_PREFIX} " ]]; then
56
+ local docker_cmd=" docker buildx build --build-arg GO_VERSION=${GO_VERSION} --build-arg NODE_IMAGE=${node_image_name} "
57
+
58
+ if [[ " ${test_setup} " == " xsvm" ]]; then
59
+ # The xsvm node image is built on the avalanchego node image, which is assumed to have already been
60
+ # built. The image name doesn't include the image prefix because it is not intended to be pushed.
61
+ docker_cmd=" ${docker_cmd} --build-arg AVALANCHEGO_NODE_IMAGE=antithesis-avalanchego-node:${TAG} "
62
+ fi
63
+
64
+ # Build node image first to allow the workload image to use it.
65
+ ${docker_cmd} -t " ${node_image_name} " -f " ${node_dockerfile} " " ${AVALANCHE_PATH} "
66
+ if [[ -n " ${image_prefix} " ]]; then
54
67
# Push images with an image prefix since the prefix defines a registry location
55
68
docker_cmd=" ${docker_cmd} --push"
56
69
fi
57
70
58
- # Build node image first to allow the config and workload image builds to use it.
59
- ${docker_cmd} -t " ${node_image_name} " -f " ${node_dockerfile} " " ${AVALANCHE_PATH} "
60
- ${docker_cmd} --build-arg NODE_IMAGE=" ${node_image_name} " -t " ${workload_image_name} " -f " ${base_dockerfile} .workload" " ${AVALANCHE_PATH} "
61
- ${docker_cmd} --build-arg IMAGE_TAG=" ${TAG} " -t " ${config_image_name} " -f " ${base_dockerfile} .config" " ${AVALANCHE_PATH} "
71
+ if [[ -n " ${node_only} " ]]; then
72
+ # Skip building the config and workload images. Supports building the avalanchego
73
+ # node image as the base image for the xsvm node image.
74
+ return
75
+ fi
76
+
77
+ TARGET_PATH=" ${AVALANCHE_PATH} /build/antithesis/${test_setup} "
78
+ if [[ -d " ${TARGET_PATH} " ]]; then
79
+ # Ensure the target path is empty before generating the compose config
80
+ rm -r " ${TARGET_PATH:? } "
81
+ fi
82
+
83
+ # Define the env vars for the compose config generation
84
+ COMPOSE_ENV=" TARGET_PATH=${TARGET_PATH} IMAGE_TAG=${TAG} "
85
+
86
+ if [[ " ${test_setup} " == " xsvm" ]]; then
87
+ # Ensure avalanchego and xsvm binaries are available to create an initial db state that includes subnets.
88
+ " ${AVALANCHE_PATH} " /scripts/build.sh
89
+ " ${AVALANCHE_PATH} " /scripts/build_xsvm.sh
90
+ COMPOSE_ENV=" ${COMPOSE_ENV} AVALANCHEGO_PATH=${AVALANCHE_PATH} /build/avalanchego AVALANCHEGO_PLUGIN_DIR=${HOME} /.avalanchego/plugins"
91
+ fi
92
+
93
+ # Generate compose config for copying into the config image
94
+ # shellcheck disable=SC2086
95
+ env ${COMPOSE_ENV} go run " ${AVALANCHE_PATH} /tests/antithesis/${test_setup} /gencomposeconfig"
96
+
97
+ # Build the config image
98
+ ${docker_cmd} -t " ${config_image_name} " -f " ${base_dockerfile} .config" " ${AVALANCHE_PATH} "
99
+
100
+ # Build the workload image
101
+ ${docker_cmd} -t " ${workload_image_name} " -f " ${base_dockerfile} .workload" " ${AVALANCHE_PATH} "
62
102
}
63
103
64
104
TEST_SETUP=" ${TEST_SETUP:- } "
65
105
if [[ " ${TEST_SETUP} " == " avalanchego" ]]; then
66
- build_images avalanchego " ${AVALANCHE_PATH} /Dockerfile"
106
+ build_images avalanchego " ${AVALANCHE_PATH} /Dockerfile" " ${IMAGE_PREFIX} " " ${NODE_ONLY:- } "
107
+ elif [[ " ${TEST_SETUP} " == " xsvm" ]]; then
108
+ # Only build the node image to use as the base for the xsvm image. Provide an empty
109
+ # image prefix (the 3rd argument) to prevent the image from being pushed
110
+ NODE_ONLY=1
111
+ build_images avalanchego " ${AVALANCHE_PATH} /Dockerfile" " " " ${NODE_ONLY} "
112
+
113
+ build_images xsvm " ${AVALANCHE_PATH} /vms/example/xsvm/Dockerfile" " ${IMAGE_PREFIX} "
67
114
else
68
- echo " TEST_SETUP must be set. Valid values are 'avalanchego'"
115
+ echo " TEST_SETUP must be set. Valid values are 'avalanchego' or 'xsvm' "
69
116
exit 255
70
117
fi
0 commit comments