Skip to content

Commit 4d117d1

Browse files
committed
fixup: Update to use refactored antithesis tooling from avalanchego
1 parent 1941e49 commit 4d117d1

File tree

7 files changed

+117
-215
lines changed

7 files changed

+117
-215
lines changed

.github/workflows/publish_antithesis_images.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ jobs:
2929
run: bash -x ./scripts/build_antithesis_images.sh
3030
env:
3131
IMAGE_PREFIX: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}
32-
TAG: latest
32+
IMAGE_TAG: latest
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Trigger Antithesis
2+
3+
on:
4+
# TODO(marun) Add a schedule
5+
workflow_dispatch:
6+
inputs:
7+
duration:
8+
description: 'The duration (in hours) to run the test for'
9+
default: '0.5'
10+
required: true
11+
type: string
12+
recipients:
13+
description: 'Comma-seperated email addresses to send the test report to'
14+
required: true
15+
type: string
16+
image_tag:
17+
description: 'The image tag to target'
18+
default: latest
19+
required: true
20+
type: string
21+
22+
jobs:
23+
antithesis:
24+
name: Run Antithesis
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: antithesishq/[email protected]
28+
with:
29+
notebook_name: avalanche
30+
tenant: avalanche
31+
username: ${{ secrets.ANTITHESIS_USERNAME }}
32+
password: ${{ secrets.ANTITHESIS_PASSWORD }}
33+
github_token: ${{ secrets.ANTITHESIS_GH_PAT }}
34+
config_image: antithesis-subnet-evm-config:${{ github.event.inputs.image_tag || 'latest' }}
35+
images: antithesis-subnet-evm-workload:${{ github.event.inputs.image_tag || 'latest' }};antithesis-subnet-evm-node:${{ github.event.inputs.image_tag || 'latest' }}
36+
email_recipients: ${{ github.event.inputs.recipients || secrets.ANTITHESIS_RECIPIENTS }}
37+
additional_parameters: |-
38+
custom.duration=${{ github.event.inputs.duration || '11.25' }} # Duration is in hours
39+
custom.workload=subnet-evm

scripts/build_antithesis_images.sh

Lines changed: 41 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -5,87 +5,15 @@ set -euo pipefail
55
# Builds docker images for antithesis testing.
66

77
# 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+
# ./scripts/build_antithesis_images.sh # Build local images
9+
# IMAGE_PREFIX=<registry>/<repo> IMAGE_TAG=latest ./scripts/build_antithesis_images.sh # Specify a prefix to enable image push and use a specific tag
1010

1111
# Directory above this script
1212
SUBNET_EVM_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
1313

1414
# Allow configuring the clone path to point to a shared and/or existing clone of the avalanchego repo
1515
AVALANCHEGO_CLONE_PATH="${AVALANCHEGO_CLONE_PATH:-${SUBNET_EVM_PATH}/avalanchego}"
1616

17-
# Specifying an image prefix will ensure the image is pushed after build
18-
IMAGE_PREFIX="${IMAGE_PREFIX:-}"
19-
20-
TAG="${TAG:-}"
21-
if [[ -z "${TAG}" ]]; then
22-
# Default to tagging with the commit hash
23-
source "${SUBNET_EVM_PATH}"/scripts/constants.sh
24-
TAG="${SUBNET_EVM_COMMIT::8}"
25-
fi
26-
27-
# The dockerfiles don't specify the golang version to minimize the changes required to bump
28-
# the version. Instead, the golang version is provided as an argument.
29-
GO_VERSION="$(go list -m -f '{{.GoVersion}}')"
30-
31-
function build_images {
32-
local base_image_name=$1
33-
local uninstrumented_node_dockerfile=$2
34-
local avalanche_node_image=$3
35-
36-
# Define image names
37-
if [[ -n "${IMAGE_PREFIX}" ]]; then
38-
base_image_name="${IMAGE_PREFIX}/${base_image_name}"
39-
fi
40-
local node_image_name="${base_image_name}-node:${TAG}"
41-
local workload_image_name="${base_image_name}-workload:${TAG}"
42-
local config_image_name="${base_image_name}-config:${TAG}"
43-
44-
# Define dockerfiles
45-
local base_dockerfile="${SUBNET_EVM_PATH}/tests/antithesis/Dockerfile"
46-
local node_dockerfile="${base_dockerfile}.node"
47-
if [[ "$(go env GOARCH)" == "arm64" ]]; then
48-
# Antithesis instrumentation is only supported on amd64. On apple silicon (arm64), the
49-
# uninstrumented Dockerfile will be used to build the node image to enable local test
50-
# development.
51-
node_dockerfile="${uninstrumented_node_dockerfile}"
52-
fi
53-
54-
# Define default build command
55-
local docker_cmd="docker buildx build --build-arg GO_VERSION=${GO_VERSION} --build-arg NODE_IMAGE=${node_image_name}"
56-
if [[ -n "${IMAGE_PREFIX}" ]]; then
57-
# Push images with an image prefix since the prefix defines a registry location
58-
docker_cmd="${docker_cmd} --push"
59-
fi
60-
61-
# Build node image first to allow the workload image to be based on it.
62-
${docker_cmd} --build-arg AVALANCHEGO_NODE_IMAGE="${avalanche_node_image}" -t "${node_image_name}" \
63-
-f "${node_dockerfile}" "${SUBNET_EVM_PATH}"
64-
TARGET_PATH="${SUBNET_EVM_PATH}/build/antithesis"
65-
if [[ -d "${TARGET_PATH}" ]]; then
66-
# Ensure the target path is empty before generating the compose config
67-
rm -r "${TARGET_PATH}"
68-
fi
69-
70-
# Ensure avalanchego and subnet-evm binaries are available to create an initial db state that includes subnets.
71-
"${AVALANCHEGO_CLONE_PATH}"/scripts/build.sh
72-
PLUGIN_PATH="${TARGET_PATH}"/plugins
73-
"${SUBNET_EVM_PATH}"/scripts/build.sh "${PLUGIN_PATH}"/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy
74-
75-
# Generate compose config and db state for the config image
76-
TARGET_PATH="${TARGET_PATH}"\
77-
IMAGE_TAG="${TAG}"\
78-
AVALANCHEGO_PATH="${AVALANCHEGO_CLONE_PATH}/build/avalanchego"\
79-
AVALANCHEGO_PLUGIN_DIR="${PLUGIN_PATH}"\
80-
go run "${SUBNET_EVM_PATH}/tests/antithesis/gencomposeconfig"
81-
82-
# Build config image
83-
${docker_cmd} -t "${config_image_name}" -f "${base_dockerfile}.config" "${SUBNET_EVM_PATH}"
84-
85-
# Build workload image
86-
${docker_cmd} -t "${workload_image_name}" -f "${base_dockerfile}.workload" "${SUBNET_EVM_PATH}"
87-
}
88-
8917
# Assume it's necessary to build the avalanchego node image from source
9018
# TODO(marun) Support use of a released node image if using a release version of avalanchego
9119

@@ -105,7 +33,43 @@ fi
10533
git checkout -B "test-${AVALANCHE_VERSION}" "${AVALANCHE_VERSION}"
10634
cd "${SUBNET_EVM_PATH}"
10735

108-
# Build avalanchego node image. Supply an empty tag so the tag can be discovered from the hash of the avalanchego repo.
109-
NODE_ONLY=1 TEST_SETUP=avalanchego TAG='' bash -x "${AVALANCHEGO_CLONE_PATH}"/scripts/build_antithesis_images.sh
36+
AVALANCHEGO_COMMIT_HASH="$(git --git-dir="${AVALANCHEGO_CLONE_PATH}/.git" rev-parse HEAD)"
37+
AVALANCHEGO_IMAGE_TAG="${AVALANCHEGO_COMMIT_HASH::8}"
38+
39+
# Build avalanchego node image.
40+
NODE_ONLY=1 TEST_SETUP=avalanchego IMAGE_TAG="${AVALANCHEGO_IMAGE_TAG}" bash -x "${AVALANCHEGO_CLONE_PATH}"/scripts/build_antithesis_images.sh
41+
42+
# Specifying an image prefix will ensure the image is pushed after build
43+
IMAGE_PREFIX="${IMAGE_PREFIX:-}"
44+
45+
IMAGE_TAG="${IMAGE_TAG:-}"
46+
if [[ -z "${IMAGE_TAG}" ]]; then
47+
# Default to tagging with the commit hash
48+
source "${SUBNET_EVM_PATH}"/scripts/constants.sh
49+
IMAGE_TAG="${SUBNET_EVM_COMMIT::8}"
50+
fi
51+
52+
# The dockerfiles don't specify the golang version to minimize the changes required to bump
53+
# the version. Instead, the golang version is provided as an argument.
54+
GO_VERSION="$(go list -m -f '{{.GoVersion}}')"
55+
56+
# Import common functions used to build images for antithesis test setups
57+
# shellcheck source=/dev/null
58+
source "${AVALANCHEGO_CLONE_PATH}"/scripts/lib_build_antithesis_images.sh
59+
60+
build_antithesis_builder_image "${GO_VERSION}" "antithesis-subnet-evm-builder:${IMAGE_TAG}" "${AVALANCHEGO_CLONE_PATH}" "${SUBNET_EVM_PATH}"
61+
62+
# Ensure avalanchego and subnet-evm binaries are available to create an initial db state that includes subnets.
63+
"${AVALANCHEGO_CLONE_PATH}"/scripts/build.sh
64+
PLUGIN_PATH="${SUBNET_EVM_PATH}/build/plugins"
65+
mkdir -p "${PLUGIN_PATH}"
66+
"${SUBNET_EVM_PATH}"/scripts/build.sh "${PLUGIN_PATH}/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy"
67+
68+
echo "Generating compose configuration"
69+
gen_antithesis_compose_config "${IMAGE_TAG}" "${SUBNET_EVM_PATH}" "./tests/antithesis/gencomposeconfig" \
70+
"${SUBNET_EVM_PATH}/build/antithesis" \
71+
"AVALANCHEGO_PATH=${AVALANCHEGO_CLONE_PATH}/build/avalanchego AVALANCHEGO_PLUGIN_DIR=${PLUGIN_PATH}"
11072

111-
build_images antithesis-subnet-evm "${SUBNET_EVM_PATH}/Dockerfile" "antithesis-avalanchego-node:${AVALANCHE_VERSION::8}"
73+
build_antithesis_images "${GO_VERSION}" "${IMAGE_PREFIX}" "antithesis-subnet-evm" "${IMAGE_TAG}" \
74+
"${AVALANCHEGO_IMAGE_TAG}" "${SUBNET_EVM_PATH}/tests/antithesis/Dockerfile" \
75+
"${SUBNET_EVM_PATH}/Dockerfile" "${SUBNET_EVM_PATH}"

scripts/tests.build_antithesis_images.sh

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -euo pipefail
44

5-
# Validates the construction of the antithesis images.
5+
# Validates the construction of the antithesis images by:
66
#
77
# 1. Building the antithesis test images
88
# 2. Extracting the docker compose configuration from the config image
@@ -11,56 +11,22 @@ set -euo pipefail
1111
#
1212

1313
# e.g.,
14-
# ./scripts/tests.build_antithesis_images.sh # Test build of antithesis images
15-
# DEBUG=1 ./scripts/tests.build_antithesis_images.sh # Retain the temporary compose path for troubleshooting
14+
# ./scripts/tests.build_antithesis_images.sh # Test build of antithesis images
15+
# DEBUG=1 ./scripts/tests.build_antithesis_images.sh # Retain the temporary compose path for troubleshooting
1616

1717
SUBNET_EVM_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
1818

1919
# Discover the default tag that will be used for the image
2020
source "${SUBNET_EVM_PATH}"/scripts/constants.sh
21-
export TAG="${SUBNET_EVM_COMMIT::8}"
21+
export IMAGE_TAG="${SUBNET_EVM_COMMIT::8}"
2222

23-
# Build the images for the specified test setup
23+
# Build the images
2424
bash -x "${SUBNET_EVM_PATH}"/scripts/build_antithesis_images.sh
2525

26-
# Create a container from the config image to extract compose configuration from
27-
IMAGE_NAME="antithesis-subnet-evm-config"
28-
CONTAINER_NAME="tmp-${IMAGE_NAME}"
29-
docker create --name "${CONTAINER_NAME}" "${IMAGE_NAME}:${TAG}" /bin/true
30-
31-
# Create a temporary directory to write the compose configuration to
32-
TMPDIR="$(mktemp -d)"
33-
echo "using temporary directory ${TMPDIR} as the docker-compose path"
34-
35-
COMPOSE_FILE="${TMPDIR}/docker-compose.yml"
36-
COMPOSE_CMD="docker-compose -f ${COMPOSE_FILE}"
37-
38-
# Ensure cleanup
39-
function cleanup {
40-
echo "removing temporary container"
41-
docker rm "${CONTAINER_NAME}"
42-
echo "stopping and removing the docker compose project"
43-
${COMPOSE_CMD} down --volumes
44-
if [[ -z "${DEBUG:-}" ]]; then
45-
echo "removing temporary dir"
46-
rm -rf "${TMPDIR}"
47-
fi
48-
}
49-
trap cleanup EXIT
50-
51-
# Copy the docker-compose.yml file out of the container
52-
docker cp "${CONTAINER_NAME}":/docker-compose.yml "${COMPOSE_FILE}"
53-
54-
# Copy the volume paths out of the container
55-
docker cp "${CONTAINER_NAME}":/volumes "${TMPDIR}/"
56-
57-
# Run the docker compose project for 30 seconds without error. Local
58-
# network bootstrap is ~6s, but github workers can be much slower.
59-
${COMPOSE_CMD} up -d
60-
sleep 30
61-
if ${COMPOSE_CMD} ps -q | xargs docker inspect -f '{{ .State.Status }}' | grep -v 'running'; then
62-
echo "An error occurred."
63-
exit 255
64-
fi
65-
66-
# Success!
26+
# Test the images
27+
AVALANCHEGO_CLONE_PATH="${AVALANCHEGO_CLONE_PATH:-${SUBNET_EVM_PATH}/avalanchego}"
28+
export IMAGE_NAME="antithesis-subnet-evm-config"
29+
export DEBUG="${DEBUG:-}"
30+
set -x
31+
# shellcheck source=/dev/null
32+
. "${AVALANCHEGO_CLONE_PATH}"/scripts/lib_test_antithesis_images.sh

tests/antithesis/Dockerfile.node

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,16 @@
1-
# The version is supplied as a build argument rather than hard-coded
2-
# to minimize the cost of version changes.
3-
ARG GO_VERSION
1+
# BUILDER_IMAGE_TAG should identify the builder image
2+
ARG BUILDER_IMAGE_TAG
43

54
# AVALANCHEGO_NODE_IMAGE needs to identify an existing avalanchego node image and should include the tag
65
ARG AVALANCHEGO_NODE_IMAGE
76

8-
# Antithesis: Getting the Antithesis golang instrumentation library
9-
FROM docker.io/antithesishq/go-instrumentor AS instrumentor
10-
117
# ============= Compilation Stage ================
12-
FROM golang:$GO_VERSION-bullseye AS builder
13-
14-
WORKDIR /build
15-
# Copy and download avalanche dependencies using go mod
16-
COPY go.mod .
17-
COPY go.sum .
18-
RUN go mod download
19-
20-
# Copy the code into the container
21-
COPY . .
22-
23-
# Keep the commit hash to easily verify the exact version that is running
24-
RUN git rev-parse HEAD > ./commit_hash.txt
25-
26-
# Copy the instrumentor and supporting files to their correct locations
27-
COPY --from=instrumentor /opt/antithesis /opt/antithesis
28-
COPY --from=instrumentor /opt/antithesis/lib /lib
29-
30-
# Create the destination output directory for the instrumented code
31-
RUN mkdir -p /avalanchego_instrumented
32-
33-
# Park the .git file in a safe location
34-
RUN mkdir -p /opt/tmp/
35-
RUN cp -r .git /opt/tmp/
8+
FROM antithesis-subnet-evm-builder:$BUILDER_IMAGE_TAG AS builder
369

37-
# Instrument avalanchego
38-
RUN /opt/antithesis/bin/goinstrumentor \
39-
-stderrthreshold=INFO \
40-
-antithesis /opt/antithesis/instrumentation \
41-
. \
42-
/avalanchego_instrumented
10+
# The builder workdir will vary between instrumented and non-instrumented builders
11+
ARG BUILDER_WORKDIR
4312

44-
WORKDIR /avalanchego_instrumented/customer
45-
RUN go mod download
46-
RUN ln -s /opt/tmp/.git .git
13+
WORKDIR $BUILDER_WORKDIR
4714

4815
# Build the VM
4916
RUN ./scripts/build.sh /build/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy
@@ -56,7 +23,7 @@ FROM $AVALANCHEGO_NODE_IMAGE AS execution
5623
COPY --from=builder /build/commit_hash.txt /avalanchego/build/commit_hash.txt
5724

5825
# Copy the antithesis dependencies into the container
59-
COPY --from=builder /avalanchego_instrumented/symbols /symbols
26+
COPY --from=builder /instrumented/symbols /symbols
6027

6128
# Copy the executable into the container
6229
COPY --from=builder /build/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy\

tests/antithesis/Dockerfile.workload

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
# The version is supplied as a build argument rather than hard-coded
2-
# to minimize the cost of version changes.
3-
ARG GO_VERSION
1+
# BUILDER_IMAGE_TAG should identify the builder image
2+
ARG BUILDER_IMAGE_TAG
43

5-
# NODE_IMAGE needs to identify an existing node image and should include the tag
6-
ARG NODE_IMAGE
4+
# AVALANCHEGO_NODE_IMAGE needs to identify an existing avalanchego node image and should include the tag
5+
ARG AVALANCHEGO_NODE_IMAGE
76

87
# ============= Compilation Stage ================
9-
FROM golang:$GO_VERSION-bullseye AS builder
8+
FROM antithesis-subnet-evm-builder:$BUILDER_IMAGE_TAG AS builder
109

11-
WORKDIR /build
12-
# Copy and download avalanche dependencies using go mod
13-
COPY go.mod .
14-
COPY go.sum .
15-
RUN go mod download
10+
# The builder workdir will vary between instrumented and non-instrumented builders
11+
ARG BUILDER_WORKDIR
1612

17-
# Copy the code into the container
18-
COPY . .
13+
WORKDIR $BUILDER_WORKDIR
1914

2015
# Build the workload
2116
RUN ./scripts/build_antithesis_workload.sh
2217

2318
# ============= Cleanup Stage ================
2419
# Base the workflow on the node image to support bootstrap testing
25-
FROM $NODE_IMAGE AS execution
20+
FROM $AVALANCHEGO_NODE_IMAGE AS execution
21+
22+
# The builder workdir will vary between instrumented and non-instrumented builders
23+
ARG BUILDER_WORKDIR
2624

2725
# Copy the executable into the container
28-
COPY --from=builder /build/build/workload ./workload
26+
COPY --from=builder $BUILDER_WORKDIR/build/workload ./workload
2927

3028
CMD [ "./workload" ]

0 commit comments

Comments
 (0)