-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[antithesis] Refactor existing job to support xsvm test setup
- Loading branch information
Showing
20 changed files
with
559 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
# Builds docker images for antithesis testing. | ||
|
||
# e.g., | ||
# ./scripts/build_antithesis_images.sh # Build local images | ||
# IMAGE_PREFIX=<registry>/<repo> TAG=latest ./scripts/build_antithesis_images.sh # Specify a prefix to enable image push and use a specific tag | ||
|
||
# Directory above this script | ||
AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) | ||
|
||
# Specifying an image prefix will ensure the image is pushed after build | ||
IMAGE_PREFIX="${IMAGE_PREFIX:-}" | ||
|
||
TAG="${TAG:-}" | ||
if [[ -z "${TAG}" ]]; then | ||
# Default to tagging with the commit hash | ||
source "${AVALANCHE_PATH}"/scripts/constants.sh | ||
TAG="${commit_hash}" | ||
fi | ||
|
||
# The dockerfiles don't specify the golang version to minimize the changes required to bump | ||
# the version. Instead, the golang version is provided as an argument. | ||
GO_VERSION="$(go list -m -f '{{.GoVersion}}')" | ||
|
||
function build_images { | ||
local test_setup=$1 | ||
local uninstrumented_node_dockerfile=$2 | ||
|
||
# Define image names | ||
local base_image_name="antithesis-${test_setup}" | ||
if [[ -n "${IMAGE_PREFIX}" ]]; then | ||
base_image_name="${IMAGE_PREFIX}/${base_image_name}" | ||
fi | ||
local node_image_name="${base_image_name}-node:${TAG}" | ||
local workload_image_name="${base_image_name}-workload:${TAG}" | ||
local config_image_name="${base_image_name}-config:${TAG}" | ||
|
||
# Define dockerfiles | ||
local base_dockerfile="${AVALANCHE_PATH}/tests/antithesis/${test_setup}/Dockerfile" | ||
local node_dockerfile="${base_dockerfile}.node" | ||
if [[ "$(go env GOARCH)" == "arm64" ]]; then | ||
# Antithesis instrumentation is only supported on amd64. On apple silicon (arm64), the | ||
# uninstrumented Dockerfile will be used to build the node image to enable local test | ||
# development. | ||
node_dockerfile="${uninstrumented_node_dockerfile}" | ||
fi | ||
|
||
# Define default build command | ||
local docker_cmd="docker buildx build --build-arg GO_VERSION=${GO_VERSION}" | ||
|
||
# Build node image first to allow the config and workload image builds to use it. | ||
${docker_cmd} -t "${node_image_name}" -f "${node_dockerfile}" "${AVALANCHE_PATH}" | ||
${docker_cmd} --build-arg NODE_IMAGE="${node_image_name}" -t "${workload_image_name}" -f "${base_dockerfile}.workload" "${AVALANCHE_PATH}" | ||
${docker_cmd} --build-arg IMAGE_TAG="${TAG}" -t "${config_image_name}" -f "${base_dockerfile}.config" "${AVALANCHE_PATH}" | ||
} | ||
|
||
TEST_SETUP="${TEST_SETUP:-}" | ||
if [[ "${TEST_SETUP}" == "avalanchego" ]]; then | ||
build_images avalanchego "${AVALANCHE_PATH}/Dockerfile" | ||
else | ||
echo "TEST_SETUP must be set. Valid values are 'avalanchego'" | ||
exit 255 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
# Validates the construction of the antithesis images for a test setup specified by TEST_SETUP. | ||
# | ||
# 1. Building the antithesis test image | ||
# 2. Extracting the docker compose configuration from the image | ||
# 3. Running the workload and its target network without error for a minute | ||
# 4. Stopping the workload and its target network | ||
# | ||
|
||
AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) | ||
|
||
# Discover the default tag that will be used for the image | ||
source "${AVALANCHE_PATH}"/scripts/constants.sh | ||
export TAG="${commit_hash}" | ||
|
||
# Build the images for the specified test setup | ||
export TEST_SETUP="${TEST_SETUP:-}" | ||
bash -x "${AVALANCHE_PATH}"/scripts/build_antithesis_images.sh | ||
|
||
# Create a container from the config image to extract compose configuration from | ||
IMAGE_NAME="antithesis-${TEST_SETUP}-config" | ||
CONTAINER_NAME="tmp-${IMAGE_NAME}" | ||
docker create --name "${CONTAINER_NAME}" "${IMAGE_NAME}:${TAG}" /bin/true | ||
|
||
# Create a temporary directory to write the compose configuration to | ||
TMPDIR="$(mktemp -d)" | ||
COMPOSE_FILE="${TMPDIR}/docker-compose.yml" | ||
COMPOSE_CMD="docker-compose -f ${COMPOSE_FILE}" | ||
|
||
# Ensure cleanup | ||
function cleanup { | ||
echo "removing temporary container" | ||
docker rm "${CONTAINER_NAME}" | ||
echo "stopping and removing the docker compose project" | ||
${COMPOSE_CMD} down --volumes | ||
echo "removing temporary dir" | ||
rm -rf "${TMPDIR}" | ||
} | ||
trap cleanup EXIT | ||
|
||
# Copy the docker-compose.yml file out of the container | ||
docker cp "${CONTAINER_NAME}":/docker-compose.yml "${COMPOSE_FILE}" | ||
|
||
# Copy the volume paths out of the container | ||
docker cp "${CONTAINER_NAME}":/volumes "${TMPDIR}/" | ||
|
||
# Run the docker compose project for one minute without error | ||
${COMPOSE_CMD} up -d | ||
sleep 60 | ||
if ${COMPOSE_CMD} ps -q | xargs docker inspect -f '{{ .State.Status }}' | grep -v 'running'; then | ||
echo "An error occurred." | ||
exit 255 | ||
fi | ||
|
||
# Success! |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Antithesis Testing | ||
|
||
This package supports testing with | ||
[Antithesis](https://antithesis.com/docs/introduction/introduction.html), | ||
a SaaS offering that enables deployment of distributed systems (such | ||
as Avalanche) to a deterministic and simulated environment that | ||
enables discovery and reproduction of anomalous behavior. | ||
|
||
## Package details | ||
|
||
| Filename | Purpose | | ||
|:-------------|:----------------------------------------------------------------------------------| | ||
| compose.go | Enables generation of Docker Compose project files for antithesis testing. | | ||
| avalanchego/ | Contains resources supporting antithesis testing of avalanchego's primary chains. | | ||
|
||
|
||
## Instrumentation | ||
|
||
Software running in Antithesis's environment must be | ||
[instrumented](https://antithesis.com/docs/instrumentation/overview.html) | ||
to take full advantage of the supported traceability. Since the | ||
Antithesis Go SDK only supports the amd64/x86_64 architecture as of this | ||
writing, running of instrumented binaries on Macs (arm64) is not possible | ||
without emulation (which would be very slow). To support test development | ||
on Macs, a local build will not be instrumented. | ||
|
||
## Defining a new test setup | ||
|
||
When defining a new test setup - whether in the avalanchego repo or | ||
for a VM in another repo - following the example of an existing test | ||
setup is suggested. The following table enumerates the files defining | ||
a test setup: | ||
|
||
| Filename | Purpose | | ||
|:-------------------------------------------------------|:-------------------------------------------------------| | ||
| scripts/build_antithesis_images.sh | Builds the test images to deploy to antithesis | | ||
| scripts/build_antithesis_[test setup]_workload.sh | Builds the workload binary | | ||
| scripts/tests.build_antithesis_images.sh | Validates the build of the test images | | ||
| tests/antithesis/[test setup]/main.go | The entrypoint for the workload binary | | ||
| tests/antithesis/[test setup]/Dockerfile.config | Defines how to build the config image | | ||
| tests/antithesis/[test setup]/Dockerfile.node | Defines how to build the instrumented node image | | ||
| tests/antithesis/[test setup]/Dockerfile.workload | Defines how to build the workload image | | ||
| tests/antithesis/[test setup]/gencomposeconfig/main.go | Generates the compose configuration for the test setup | | ||
|
||
In addition, github workflows are suggested to ensure | ||
`scripts/tests.build_antithesis_images.sh` runs against PRs and | ||
`scripts/build_antithesis_images.sh` runs against pushes. |
Oops, something went wrong.