mirror of
https://github.com/luxfi/node.git
synced 2026-07-27 03:39:39 +00:00
clean: squash history (binaries stripped via filter-repo)
This commit is contained in:
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.1 "$@"
|
||||
Executable
+139
@@ -0,0 +1,139 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
print_usage() {
|
||||
printf "Usage: build [OPTIONS] [BUILD_ARGS]
|
||||
|
||||
Build node
|
||||
|
||||
Options:
|
||||
|
||||
-r Build with race detector
|
||||
-p Build profile (default: minimal)
|
||||
Profiles:
|
||||
minimal - ZAP transport, all VMs, stripped (~30MB)
|
||||
core - ZAP, P/X/C only, stripped (~25MB) [plugin-ready]
|
||||
full - gRPC+ZAP, all features, stripped (~36MB)
|
||||
dev - ZAP, all VMs, debug symbols (~40MB)
|
||||
tiny - all VMs + UPX compressed (~20MB)
|
||||
|
||||
BUILD_ARGS: Additional arguments to pass to go build (e.g., -tags purego)
|
||||
|
||||
Examples:
|
||||
./scripts/build.sh # minimal stripped build
|
||||
./scripts/build.sh -p full # full build with all VMs and gRPC
|
||||
./scripts/build.sh -p dev # development build with debug symbols
|
||||
./scripts/build.sh -p tiny # smallest binary (UPX compressed)
|
||||
./scripts/build.sh -r # minimal with race detector
|
||||
"
|
||||
}
|
||||
|
||||
race=''
|
||||
profile='minimal'
|
||||
while getopts 'rp:' flag; do
|
||||
case "${flag}" in
|
||||
r)
|
||||
echo "Building with race detection enabled"
|
||||
race='-race'
|
||||
;;
|
||||
p)
|
||||
profile="${OPTARG}"
|
||||
;;
|
||||
*) print_usage
|
||||
exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Shift to get remaining arguments (build tags, etc.)
|
||||
shift $((OPTIND-1))
|
||||
|
||||
REPO_ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
|
||||
# Configure the build environment
|
||||
source "${REPO_ROOT}"/scripts/constants.sh
|
||||
# Determine the git commit hash to use for the build
|
||||
source "${REPO_ROOT}"/scripts/git_commit.sh
|
||||
|
||||
# Configure build based on profile
|
||||
tags=""
|
||||
ldflags="-X github.com/luxfi/node/version.GitCommit=$git_commit \
|
||||
-X github.com/luxfi/node/version.VersionMajor=$version_major \
|
||||
-X github.com/luxfi/node/version.VersionMinor=$version_minor \
|
||||
-X github.com/luxfi/node/version.VersionPatch=$version_patch \
|
||||
$static_ld_flags"
|
||||
strip_flags=""
|
||||
upx_compress=false
|
||||
|
||||
case "${profile}" in
|
||||
minimal)
|
||||
echo "Profile: minimal (ZAP, all VMs, NAT, stripped)"
|
||||
tags="nattraversal"
|
||||
strip_flags="-s -w"
|
||||
;;
|
||||
core)
|
||||
echo "Profile: core (ZAP, P/X/C chains only, stripped)"
|
||||
# No optional VMs - future plugin-ready build
|
||||
strip_flags="-s -w"
|
||||
;;
|
||||
full)
|
||||
echo "Profile: full (gRPC+ZAP, all VMs, all features, stripped)"
|
||||
tags="grpc,nattraversal,zxcvbn,metrics"
|
||||
strip_flags="-s -w"
|
||||
;;
|
||||
dev)
|
||||
echo "Profile: dev (ZAP, core VMs, debug symbols)"
|
||||
# No strip flags, keep debug symbols
|
||||
;;
|
||||
tiny)
|
||||
echo "Profile: tiny (all VMs, NAT + UPX compressed)"
|
||||
tags="nattraversal"
|
||||
strip_flags="-s -w"
|
||||
upx_compress=true
|
||||
;;
|
||||
*)
|
||||
echo "Unknown profile: ${profile}"
|
||||
print_usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Apply strip flags to ldflags
|
||||
if [ -n "$strip_flags" ]; then
|
||||
ldflags="$strip_flags $ldflags"
|
||||
fi
|
||||
|
||||
# Build tags argument
|
||||
tags_arg=""
|
||||
if [ -n "$tags" ]; then
|
||||
tags_arg="-tags=$tags"
|
||||
fi
|
||||
|
||||
# Enable Go 1.26 experimental features if not already set
|
||||
export GOEXPERIMENT="${GOEXPERIMENT:-runtimesecret}"
|
||||
|
||||
echo "Building Lux Node v${version_major}.${version_minor}.${version_patch} with [$(go version)] GOEXPERIMENT=${GOEXPERIMENT}..."
|
||||
go build -trimpath ${race} ${tags_arg} "$@" -o "${node_path}" \
|
||||
-ldflags "$ldflags" \
|
||||
"${REPO_ROOT}"/main
|
||||
|
||||
# Apply UPX compression if requested
|
||||
if [ "$upx_compress" = true ]; then
|
||||
if command -v upx &> /dev/null; then
|
||||
echo "Compressing with UPX..."
|
||||
upx_flags="--best --lzma"
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
upx_flags="$upx_flags --force-macos"
|
||||
fi
|
||||
# shellcheck disable=SC2086
|
||||
upx $upx_flags "${node_path}"
|
||||
else
|
||||
echo "Warning: UPX not found, skipping compression"
|
||||
echo "Install with: brew install upx (macOS) or apt install upx (Linux)"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Show binary size
|
||||
echo ""
|
||||
echo "Binary: ${node_path}"
|
||||
# shellcheck disable=SC2012
|
||||
ls -lh "${node_path}" | awk '{print "Size: " $5}'
|
||||
Executable
+91
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Builds docker images for antithesis testing.
|
||||
|
||||
# e.g.,
|
||||
# TEST_SETUP=node ./scripts/build_antithesis_images.sh # Build local images for node
|
||||
# TEST_SETUP=node NODE_ONLY=1 ./scripts/build_antithesis_images.sh # Build only a local node image for node
|
||||
# TEST_SETUP=xsvm ./scripts/build_antithesis_images.sh # Build local images for xsvm
|
||||
# TEST_SETUP=xsvm IMAGE_PREFIX=<registry>/<repo> IMAGE_TAG=latest ./scripts/build_antithesis_images.sh # Specify a prefix to enable image push and use a specific tag
|
||||
|
||||
TEST_SETUP="${TEST_SETUP:-}"
|
||||
if [[ "${TEST_SETUP}" != "node" && "${TEST_SETUP}" != "xsvm" ]]; then
|
||||
echo "TEST_SETUP must be set. Valid values are 'node' or 'xsvm'"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# Directory above this script
|
||||
LUX_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
|
||||
|
||||
source "${LUX_PATH}"/scripts/constants.sh
|
||||
source "${LUX_PATH}"/scripts/git_commit.sh
|
||||
|
||||
# Import common functions used to build images for antithesis test setups
|
||||
source "${LUX_PATH}"/scripts/lib_build_antithesis_images.sh
|
||||
|
||||
# Specifying an image prefix will ensure the image is pushed after build
|
||||
IMAGE_PREFIX="${IMAGE_PREFIX:-}"
|
||||
|
||||
IMAGE_TAG="${IMAGE_TAG:-}"
|
||||
if [[ -z "${IMAGE_TAG}" ]]; then
|
||||
# Default to tagging with the commit hash
|
||||
IMAGE_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}}')"
|
||||
|
||||
# Helper to simplify calling build_builder_image for test setups in this repo
|
||||
function build_builder_image_for_node {
|
||||
echo "Building builder image"
|
||||
build_antithesis_builder_image "${GO_VERSION}" "antithesis-node-builder:${IMAGE_TAG}" "${LUX_PATH}" "${LUX_PATH}"
|
||||
}
|
||||
|
||||
# Helper to simplify calling build_antithesis_images for test setups in this repo
|
||||
function build_antithesis_images_for_node {
|
||||
local test_setup=$1
|
||||
local image_prefix=$2
|
||||
local uninstrumented_node_dockerfile=$3
|
||||
local node_only=${4:-}
|
||||
|
||||
if [[ -z "${node_only}" ]]; then
|
||||
echo "Building node image for ${test_setup}"
|
||||
else
|
||||
echo "Building images for ${test_setup}"
|
||||
fi
|
||||
build_antithesis_images "${GO_VERSION}" "${image_prefix}" "antithesis-${test_setup}" "${IMAGE_TAG}" "${IMAGE_TAG}" \
|
||||
"${LUX_PATH}/tests/antithesis/${test_setup}/Dockerfile" "${uninstrumented_node_dockerfile}" \
|
||||
"${LUX_PATH}" "${node_only}" "${git_commit}"
|
||||
}
|
||||
|
||||
if [[ "${TEST_SETUP}" == "node" ]]; then
|
||||
build_builder_image_for_node
|
||||
|
||||
echo "Generating compose configuration for ${TEST_SETUP}"
|
||||
gen_antithesis_compose_config "${IMAGE_TAG}" "${LUX_PATH}/tests/antithesis/node/gencomposeconfig" \
|
||||
"${LUX_PATH}/build/antithesis/node"
|
||||
|
||||
build_antithesis_images_for_node "${TEST_SETUP}" "${IMAGE_PREFIX}" "${LUX_PATH}/Dockerfile" "${NODE_ONLY:-}"
|
||||
else
|
||||
build_builder_image_for_node
|
||||
|
||||
# Only build the node node image to use as the base for the xsvm image. Provide an empty
|
||||
# image prefix (the 1st argument) to prevent the image from being pushed
|
||||
NODE_ONLY=1
|
||||
build_antithesis_images_for_node node "" "${LUX_PATH}/Dockerfile" "${NODE_ONLY}"
|
||||
|
||||
# Ensure node and xsvm binaries are available to create an initial db state that includes chains.
|
||||
echo "Building binaries required for configuring the ${TEST_SETUP} test setup"
|
||||
"${LUX_PATH}"/scripts/build.sh
|
||||
"${LUX_PATH}"/scripts/build_xsvm.sh
|
||||
|
||||
echo "Generating compose configuration for ${TEST_SETUP}"
|
||||
gen_antithesis_compose_config "${IMAGE_TAG}" "${LUX_PATH}/tests/antithesis/xsvm/gencomposeconfig" \
|
||||
"${LUX_PATH}/build/antithesis/xsvm" \
|
||||
"LUXD_PATH=${LUX_PATH}/build/node LUXD_PLUGIN_DIR=${LUX_PATH}/build/plugins"
|
||||
|
||||
build_antithesis_images_for_node "${TEST_SETUP}" "${IMAGE_PREFIX}" "${LUX_PATH}/vms/example/xsvm/Dockerfile"
|
||||
fi
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Luxgo root folder
|
||||
LUX_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
|
||||
# Load the constants
|
||||
source "$LUX_PATH"/scripts/constants.sh
|
||||
source "$LUX_PATH"/scripts/git_commit.sh
|
||||
|
||||
echo "Building bootstrap-monitor..."
|
||||
go build -ldflags\
|
||||
"-X github.com/luxfi/node/version.GitCommit=$git_commit $static_ld_flags"\
|
||||
-o "$LUX_PATH/build/bootstrap-monitor"\
|
||||
"$LUX_PATH/tests/fixture/bootstrapmonitor/cmd/"*.go
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# e.g.,
|
||||
# ./scripts/build_bootstrap_monitor_image.sh # Build local image
|
||||
# DOCKER_IMAGE=my-bootstrap-monitor ./scripts/build_bootstrap_monitor_image.sh # Build local single arch image with a custom image name
|
||||
# DOCKER_IMAGE=avaplatform/bootstrap-monitor ./scripts/build_bootstrap_monitor_image.sh # Build and push image to docker hub
|
||||
|
||||
# Builds the image for the bootstrap monitor
|
||||
|
||||
# Directory above this script
|
||||
LUX_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
|
||||
|
||||
# Load the constants
|
||||
source "$LUX_PATH"/scripts/constants.sh
|
||||
|
||||
# The published name should be 'avaplatform/bootstrap-monitor', but to avoid unintentional pushes it
|
||||
# is defaulted to 'bootstrap-monitor' (without a repo or registry name) which can only be used to
|
||||
# create local images.
|
||||
export DOCKER_IMAGE=${DOCKER_IMAGE:-"bootstrap-monitor"}
|
||||
|
||||
# Skip building the race image
|
||||
export SKIP_BUILD_RACE=1
|
||||
|
||||
# Reuse the node build script for convenience. The image will have a CMD of "./node", so
|
||||
# to run the bootstrap monitor will need to specify ./bootstrap-monitor".
|
||||
#
|
||||
# TODO(marun) Figure out how to set the CMD for a multi-arch image.
|
||||
bash -x "${LUX_PATH}"/scripts/build_image.sh --build-arg BUILD_SCRIPT=build_bootstrap_monitor.sh
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# First argument is the time, in seconds, to run each fuzz test for.
|
||||
# If not provided, defaults to 1 second.
|
||||
#
|
||||
# Second argument is the directory to run fuzz tests in.
|
||||
# If not provided, defaults to the current directory.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Mostly taken from https://github.com/golang/go/issues/46312#issuecomment-1153345129
|
||||
|
||||
# Directory above this script
|
||||
LUX_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
|
||||
# Load the constants
|
||||
source "$LUX_PATH"/scripts/constants.sh
|
||||
|
||||
fuzzTime=${1:-1}
|
||||
fuzzDir=${2:-.}
|
||||
|
||||
# Add buffer to avoid context deadline exceeded errors at timeout boundary.
|
||||
# Go's fuzzer can report failures when interrupted during heavy setup (e.g. merkledb creation).
|
||||
# Use 5s buffer for short runs (≤15s), 3s for longer runs.
|
||||
if [ "$fuzzTime" -le 15 ]; then
|
||||
actualFuzzTime=$((fuzzTime > 5 ? fuzzTime - 5 : 1))
|
||||
else
|
||||
actualFuzzTime=$((fuzzTime - 3))
|
||||
fi
|
||||
|
||||
files=$(grep -r --include='**_test.go' --files-with-matches 'func Fuzz' "$fuzzDir")
|
||||
failed=false
|
||||
for file in ${files}
|
||||
do
|
||||
# Skip files that have build constraints requiring grpc (these won't build without -tags grpc)
|
||||
if head -5 "$file" | grep -q "//go:build.*grpc"; then
|
||||
echo "Skipping $file (requires grpc build tag)"
|
||||
continue
|
||||
fi
|
||||
# Use sed instead of grep -P for macOS compatibility
|
||||
funcs=$(sed -n 's/^func \(Fuzz[a-zA-Z0-9_]*\).*/\1/p' "$file")
|
||||
for func in ${funcs}
|
||||
do
|
||||
echo "Fuzzing $func in $file"
|
||||
parentDir=$(dirname "$file")
|
||||
# If any of the fuzz tests fail, return exit code 1
|
||||
if ! go test -tags test "$parentDir" -run="$func" -fuzz="$func" -fuzztime="${actualFuzzTime}"s; then
|
||||
failed=true
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
if $failed; then
|
||||
exit 1
|
||||
fi
|
||||
Executable
+123
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# e.g.,
|
||||
# ./scripts/build_image.sh # Build local single-arch image
|
||||
# ./scripts/build_image.sh --no-cache # All arguments are provided to `docker buildx build`
|
||||
# SKIP_BUILD_RACE=1 ./scripts/build_image.sh # Build local single-arch image but skip building -r image
|
||||
# DOCKER_IMAGE=mynode ./scripts/build_image.sh # Build local single arch image with a custom image name
|
||||
# DOCKER_IMAGE=avaplatform/node ./scripts/build_image.sh # Build and push multi-arch image to docker hub
|
||||
# DOCKER_IMAGE=localhost:5001/node ./scripts/build_image.sh # Build and push multi-arch image to private registry
|
||||
# DOCKER_IMAGE=localhost:5001/node FORCE_TAG_LATEST=1 ./scripts/build_image.sh # Build and push image to private registry with tag `latest`
|
||||
|
||||
# Multi-arch builds require Docker Buildx and QEMU. buildx should be enabled by
|
||||
# default in the version of docker included with Ubuntu 22.04, and qemu can be
|
||||
# installed as follows:
|
||||
#
|
||||
# sudo apt-get install qemu qemu-user-static
|
||||
#
|
||||
# After installing qemu, it will also be necessary to start a new builder that
|
||||
# supports multiplatform builds and can use the host's network:
|
||||
#
|
||||
# docker buildx create --use --driver-opt network=host
|
||||
#
|
||||
# Without `network=host`, the builder will timeout running `go mod download`.
|
||||
#
|
||||
# Reference: https://docs.docker.com/buildx/working-with-buildx/
|
||||
|
||||
# Directory above this script
|
||||
LUX_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
|
||||
|
||||
# Skip building the race image
|
||||
SKIP_BUILD_RACE="${SKIP_BUILD_RACE:-}"
|
||||
|
||||
# Force tagging as latest even if not the master branch
|
||||
FORCE_TAG_LATEST="${FORCE_TAG_LATEST:-}"
|
||||
|
||||
# Load the constants
|
||||
source "$LUX_PATH"/scripts/constants.sh
|
||||
source "$LUX_PATH"/scripts/git_commit.sh
|
||||
source "$LUX_PATH"/scripts/image_tag.sh
|
||||
|
||||
if [[ -z "${SKIP_BUILD_RACE}" && $image_tag == *"-r" ]]; then
|
||||
echo "Branch name must not end in '-r'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# The published name should be 'luxfi/node', but to avoid unintentional
|
||||
# pushes it is defaulted to 'node' (without a repo or registry name) which can
|
||||
# only be used to create local images.
|
||||
DOCKER_IMAGE="${DOCKER_IMAGE:-node}"
|
||||
|
||||
# If set to non-empty, prompts the building of a multi-arch image when the image
|
||||
# name indicates use of a registry.
|
||||
#
|
||||
# A registry is required to build a multi-arch image since a multi-arch image is
|
||||
# not really an image at all. A multi-arch image (also called a manifest) is
|
||||
# basically a list of arch-specific images available from the same registry that
|
||||
# hosts the manifest. Manifests are not supported for local images.
|
||||
#
|
||||
# Reference: https://docs.docker.com/build/building/multi-platform/
|
||||
BUILD_MULTI_ARCH="${BUILD_MULTI_ARCH:-}"
|
||||
|
||||
# buildx (BuildKit) improves the speed and UI of builds over the legacy builder and
|
||||
# simplifies creation of multi-arch images.
|
||||
#
|
||||
# Reference: https://docs.docker.com/build/buildkit/
|
||||
DOCKER_CMD="docker buildx build ${*}"
|
||||
|
||||
# The dockerfile doesn'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}}')"
|
||||
DOCKER_CMD="${DOCKER_CMD} --build-arg GO_VERSION=${GO_VERSION}"
|
||||
|
||||
# Provide the git commit as a build argument to avoid requiring this
|
||||
# to be discovered within the image. This enables image builds from
|
||||
# git worktrees since a non-primary worktree won't have a .git
|
||||
# directory to copy into the image.
|
||||
DOCKER_CMD="${DOCKER_CMD} --build-arg LUXD_COMMIT=${git_commit}"
|
||||
|
||||
if [[ "${DOCKER_IMAGE}" == *"/"* ]]; then
|
||||
# Default to pushing when the image name includes a slash which indicates the
|
||||
# use of a registry e.g.
|
||||
#
|
||||
# - dockerhub: [repo]/[image name]:[tag]
|
||||
# - private registry: [private registry hostname]/[image name]:[tag]
|
||||
DOCKER_CMD="${DOCKER_CMD} --push"
|
||||
|
||||
# Build a multi-arch image if requested
|
||||
if [[ -n "${BUILD_MULTI_ARCH}" ]]; then
|
||||
DOCKER_CMD="${DOCKER_CMD} --platform=${PLATFORMS:-linux/amd64,linux/arm64}"
|
||||
fi
|
||||
|
||||
# A populated DOCKER_USERNAME env var triggers login
|
||||
if [[ -n "${DOCKER_USERNAME:-}" ]]; then
|
||||
echo "$DOCKER_PASS" | docker login --username "$DOCKER_USERNAME" --password-stdin
|
||||
fi
|
||||
else
|
||||
# Build a single-arch image since the image name does not include a slash which
|
||||
# indicates that a registry is not available.
|
||||
#
|
||||
# Building a single-arch image with buildx and having the resulting image show up
|
||||
# in the local store of docker images (ala 'docker build') requires explicitly
|
||||
# loading it from the buildx store with '--load'.
|
||||
DOCKER_CMD="${DOCKER_CMD} --load"
|
||||
fi
|
||||
|
||||
echo "Building Docker Image with tags: $DOCKER_IMAGE:$commit_hash , $DOCKER_IMAGE:$image_tag"
|
||||
${DOCKER_CMD} -t "$DOCKER_IMAGE:$commit_hash" -t "$DOCKER_IMAGE:$image_tag" \
|
||||
"$LUX_PATH" -f "$LUX_PATH/Dockerfile"
|
||||
|
||||
if [[ -z "${SKIP_BUILD_RACE}" ]]; then
|
||||
echo "Building Docker Image with tags (race detector): $DOCKER_IMAGE:$commit_hash-r , $DOCKER_IMAGE:$image_tag-r"
|
||||
${DOCKER_CMD} --build-arg="RACE_FLAG=-r" -t "$DOCKER_IMAGE:$commit_hash-r" -t "$DOCKER_IMAGE:$image_tag-r" \
|
||||
"$LUX_PATH" -f "$LUX_PATH/Dockerfile"
|
||||
fi
|
||||
|
||||
# Only tag the latest image for the master branch when images are pushed to a registry
|
||||
if [[ "${DOCKER_IMAGE}" == *"/"* && ($image_tag == "master" || -n "${FORCE_TAG_LATEST}") ]]; then
|
||||
echo "Tagging current node images as $DOCKER_IMAGE:latest"
|
||||
docker buildx imagetools create -t "$DOCKER_IMAGE:latest" "$DOCKER_IMAGE:$commit_hash"
|
||||
fi
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Directory above this script
|
||||
LUX_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
|
||||
# Load the constants
|
||||
source "$LUX_PATH"/scripts/constants.sh
|
||||
|
||||
EXCLUDED_TARGETS="| grep -v /mocks | grep -v proto | grep -v tests/e2e | grep -v tests/load/c | grep -v tests/upgrade | grep -v tests/fixture/bootstrapmonitor/e2e"
|
||||
|
||||
if [[ "$(go env GOOS)" == "windows" ]]; then
|
||||
# Test discovery for the antithesis test setups is broken due to
|
||||
# their dependence on the linux-only Antithesis SDK.
|
||||
EXCLUDED_TARGETS="${EXCLUDED_TARGETS} | grep -v tests/antithesis"
|
||||
fi
|
||||
|
||||
# Get test targets
|
||||
TEST_TARGETS="$(eval "go list ./... ${EXCLUDED_TARGETS}")"
|
||||
|
||||
# Run tests (with race detection if CGO is enabled)
|
||||
# -short flag skips long-running integration tests (MPC protocol execution, etc.)
|
||||
RACE_FLAG=""
|
||||
if [[ "${CGO_ENABLED:-1}" != "0" ]]; then
|
||||
RACE_FLAG="-race"
|
||||
fi
|
||||
# shellcheck disable=SC2086
|
||||
go test -tags test -shuffle=on ${RACE_FLAG} -short -timeout="${TIMEOUT:-120s}" -coverprofile="coverage.out" -covermode="atomic" ${TEST_TARGETS}
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Luxgo root folder
|
||||
LUX_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
|
||||
# Load the constants
|
||||
source "$LUX_PATH"/scripts/constants.sh
|
||||
source "$LUX_PATH"/scripts/git_commit.sh
|
||||
|
||||
echo "Building tmpnetctl..."
|
||||
go build -ldflags\
|
||||
"-X github.com/luxfi/node/version.GitCommit=$git_commit $static_ld_flags"\
|
||||
-o "$LUX_PATH/build/tmpnetctl"\
|
||||
"$LUX_PATH/tests/fixture/tmpnet/tmpnetctl/"*.go
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if ! [[ "$0" =~ scripts/build_xsvm.sh ]]; then
|
||||
echo "must be run from repository root"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
source ./scripts/constants.sh
|
||||
|
||||
echo "Building xsvm plugin..."
|
||||
# xsvm requires grpc build tag for the CLI entrypoint
|
||||
go build -tags=grpc -o ./build/xsvm ./vms/example/xsvm/cmd/xsvm/
|
||||
|
||||
# Symlink to both global and local plugin directories to simplify
|
||||
# usage for testing. The local directory should be preferred but the
|
||||
# global directory remains supported for backwards compatibility.
|
||||
LOCAL_PLUGIN_PATH="${PWD}/build/plugins"
|
||||
GLOBAL_PLUGIN_PATH="${HOME}/.node/plugins"
|
||||
for plugin_dir in "${GLOBAL_PLUGIN_PATH}" "${LOCAL_PLUGIN_PATH}"; do
|
||||
PLUGIN_PATH="${plugin_dir}/v3m4wPxaHpvGr8qfMeyK6PRW3idZrPHmYcMTt7oXdK47yurVH"
|
||||
echo "Symlinking ./build/xsvm to ${PLUGIN_PATH}"
|
||||
mkdir -p "${plugin_dir}"
|
||||
ln -sf "${PWD}/build/xsvm" "${PLUGIN_PATH}"
|
||||
done
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# e.g.,
|
||||
# ./scripts/build_image.sh # Build local single-arch image
|
||||
# LUXD_IMAGE=localhost:5001/node ./scripts/build_xsvm_image.sh # Build and push image to private registry
|
||||
|
||||
if ! [[ "$0" =~ scripts/build_xsvm_image.sh ]]; then
|
||||
echo "must be run from repository root"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
source ./scripts/image_tag.sh
|
||||
|
||||
LUXD_IMAGE="${LUXD_IMAGE:-node}"
|
||||
XSVM_IMAGE="${XSVM_IMAGE:-node-xsvm}"
|
||||
|
||||
# Build the node base image
|
||||
SKIP_BUILD_RACE=1 DOCKER_IMAGE="${LUXD_IMAGE}" bash -x ./scripts/build_image.sh
|
||||
|
||||
DOCKER_CMD=("docker" "buildx" "build")
|
||||
if [[ "${XSVM_IMAGE}" == *"/"* ]]; then
|
||||
# Push to a registry when the image name includes a slash which indicates the
|
||||
# use of a registry e.g.
|
||||
#
|
||||
# - dockerhub: [repo]/[image name]:[tag]
|
||||
# - private registry: [private registry hostname]/[image name]:[tag]
|
||||
DOCKER_CMD+=("--push")
|
||||
fi
|
||||
|
||||
GO_VERSION="$(go list -m -f '{{.GoVersion}}')"
|
||||
|
||||
"${DOCKER_CMD[@]}" --build-arg GO_VERSION="${GO_VERSION}" --build-arg LUXD_NODE_IMAGE="${LUXD_IMAGE}:${image_tag}" \
|
||||
-t "${XSVM_IMAGE}" -f ./vms/example/xsvm/Dockerfile .
|
||||
Executable
+59
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Ignore warnings about variables appearing unused since this file is not the consumer of the variables it defines.
|
||||
# shellcheck disable=SC2034
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Use lower_case variables in the scripts and UPPER_CASE variables for override
|
||||
# Use the constants.sh for env overrides
|
||||
|
||||
LUX_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) # Directory above this script
|
||||
|
||||
# Where Lux Node binary goes
|
||||
node_path="$LUX_PATH/build/luxd"
|
||||
|
||||
# Docker Hub repository for node images
|
||||
node_dockerhub_repo="luxfi/node"
|
||||
|
||||
# Static compilation
|
||||
static_ld_flags=''
|
||||
if [ "${STATIC_COMPILATION:-}" = 1 ]
|
||||
then
|
||||
export CC=musl-gcc
|
||||
which $CC > /dev/null || ( echo $CC must be available for static compilation && exit 1 )
|
||||
static_ld_flags=' -extldflags "-static" -linkmode external '
|
||||
fi
|
||||
|
||||
# Set the CGO flags to use the portable version of BLST
|
||||
#
|
||||
# We use "export" here instead of just setting a bash variable because we need
|
||||
# to pass this flag to all child processes spawned by the shell.
|
||||
export CGO_CFLAGS="-O2 -D__BLST_PORTABLE__"
|
||||
# Only set CGO_ENABLED if not already set (allows CGO_ENABLED=0 for cross-compilation)
|
||||
export CGO_ENABLED="${CGO_ENABLED:-1}"
|
||||
|
||||
# Disable version control fallbacks
|
||||
export GOPROXY="${GOPROXY:-https://proxy.golang.org}"
|
||||
|
||||
# Use GOPRIVATE to bypass Go proxy for luxfi packages (zip too large for proxy)
|
||||
export GOPRIVATE="${GOPRIVATE:-github.com/luxfi/*}"
|
||||
export GONOSUMDB="${GONOSUMDB:-github.com/luxfi/*}"
|
||||
|
||||
# Configure pkg-config path for C++ libraries (luxcpp)
|
||||
# Searches for installed libraries in common locations
|
||||
LUXCPP_ROOT="${LUXCPP_ROOT:-}"
|
||||
if [ -z "$LUXCPP_ROOT" ]; then
|
||||
# Try to find luxcpp relative to this repo
|
||||
if [ -d "$LUX_PATH/../luxcpp/install/lib/pkgconfig" ]; then
|
||||
LUXCPP_ROOT="$LUX_PATH/../luxcpp/install"
|
||||
elif [ -d "$HOME/work/luxcpp/install/lib/pkgconfig" ]; then
|
||||
LUXCPP_ROOT="$HOME/work/luxcpp/install"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$LUXCPP_ROOT" ] && [ -d "$LUXCPP_ROOT/lib/pkgconfig" ]; then
|
||||
export PKG_CONFIG_PATH="${LUXCPP_ROOT}/lib/pkgconfig:${PKG_CONFIG_PATH:-}"
|
||||
export LD_LIBRARY_PATH="${LUXCPP_ROOT}/lib:${LD_LIBRARY_PATH:-}"
|
||||
export DYLD_LIBRARY_PATH="${LUXCPP_ROOT}/lib:${DYLD_LIBRARY_PATH:-}"
|
||||
fi
|
||||
Executable
+93
@@ -0,0 +1,93 @@
|
||||
#!/bin/bash
|
||||
# dev-instance.sh - Start isolated luxd dev instances for testing
|
||||
# Usage: ./scripts/dev-instance.sh [name] [http_port] [staking_port]
|
||||
#
|
||||
# Examples:
|
||||
# ./scripts/dev-instance.sh dex 7545 7546 # Start DEX testing instance
|
||||
# ./scripts/dev-instance.sh amm 7645 7646 # Start AMM testing instance
|
||||
# ./scripts/dev-instance.sh exchange 7745 7746 # Start Exchange testing instance
|
||||
#
|
||||
# To stop: kill $(cat /tmp/lux-$NAME/luxd.pid) or just `pkill -f "data-dir=/tmp/lux-$NAME"`
|
||||
# To clean: rm -rf /tmp/lux-$NAME
|
||||
|
||||
set -e
|
||||
|
||||
NAME="${1:-dev}"
|
||||
HTTP_PORT="${2:-7545}"
|
||||
STAKING_PORT="${3:-7546}"
|
||||
DATA_DIR="/tmp/lux-$NAME"
|
||||
PID_FILE="$DATA_DIR/luxd.pid"
|
||||
LOG_FILE="$DATA_DIR/luxd.log"
|
||||
|
||||
# Find luxd binary
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
LUXD="$SCRIPT_DIR/../build/luxd"
|
||||
|
||||
if [[ ! -x "$LUXD" ]]; then
|
||||
echo "Error: luxd not found at $LUXD"
|
||||
echo "Build with: cd $(dirname "$SCRIPT_DIR") && go build -o build/luxd ./main"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if already running
|
||||
if [[ -f "$PID_FILE" ]]; then
|
||||
OLD_PID=$(cat "$PID_FILE")
|
||||
if kill -0 "$OLD_PID" 2>/dev/null; then
|
||||
echo "Instance '$NAME' already running (PID: $OLD_PID)"
|
||||
echo "Stop with: kill $OLD_PID"
|
||||
echo "Or clean restart with: rm -rf $DATA_DIR && $0 $NAME $HTTP_PORT $STAKING_PORT"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check port availability
|
||||
if lsof -i ":$HTTP_PORT" >/dev/null 2>&1; then
|
||||
echo "Error: Port $HTTP_PORT is already in use"
|
||||
lsof -i ":$HTTP_PORT" | head -3
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Starting isolated luxd instance: $NAME"
|
||||
echo " Data directory: $DATA_DIR"
|
||||
echo " HTTP port: $HTTP_PORT"
|
||||
echo " Staking port: $STAKING_PORT"
|
||||
echo ""
|
||||
|
||||
# Clean and create data dir
|
||||
rm -rf "$DATA_DIR"
|
||||
mkdir -p "$DATA_DIR"
|
||||
|
||||
# Start luxd in background
|
||||
nohup "$LUXD" --dev \
|
||||
--data-dir="$DATA_DIR" \
|
||||
--http-port="$HTTP_PORT" \
|
||||
--staking-port="$STAKING_PORT" \
|
||||
> "$LOG_FILE" 2>&1 &
|
||||
|
||||
echo $! > "$PID_FILE"
|
||||
|
||||
echo "Started luxd with PID $(cat "$PID_FILE")"
|
||||
echo ""
|
||||
|
||||
# Wait for RPC to be ready
|
||||
echo -n "Waiting for RPC..."
|
||||
for _ in {1..30}; do
|
||||
if curl -s "http://127.0.0.1:$HTTP_PORT/ext/info" >/dev/null 2>&1; then
|
||||
echo " ready!"
|
||||
break
|
||||
fi
|
||||
echo -n "."
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# Show status
|
||||
echo ""
|
||||
echo "=== Instance Ready ==="
|
||||
echo " C-Chain RPC: http://127.0.0.1:$HTTP_PORT/ext/bc/C/rpc"
|
||||
echo " X-Chain RPC: http://127.0.0.1:$HTTP_PORT/ext/bc/X"
|
||||
echo " P-Chain RPC: http://127.0.0.1:$HTTP_PORT/ext/bc/P"
|
||||
echo " Info API: http://127.0.0.1:$HTTP_PORT/ext/info"
|
||||
echo ""
|
||||
echo " Logs: tail -f $LOG_FILE"
|
||||
echo " Stop: kill $(cat "$PID_FILE")"
|
||||
echo " Clean: rm -rf $DATA_DIR"
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Ignore warnings about variables appearing unused since this file is not the consumer of the variables it defines.
|
||||
# shellcheck disable=SC2034
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
LUX_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) # Directory above this script
|
||||
|
||||
# WARNING: this will use the most recent commit even if there are un-committed changes present
|
||||
git_commit="${LUXD_COMMIT:-$(git --git-dir="${LUX_PATH}/.git" rev-parse HEAD)}"
|
||||
commit_hash="${git_commit::8}"
|
||||
|
||||
# Extract version from git tag - try git first, then fallback to version file
|
||||
# Examples: v1.22.19 -> 1.22.19, v1.22.19-0-g7dc749f -> 1.22.19
|
||||
git_raw_version="${LUXD_VERSION:-$(git --git-dir="${LUX_PATH}/.git" describe --tags --always 2>/dev/null || echo "")}"
|
||||
|
||||
# Strip leading 'v' if present
|
||||
git_raw_version="${git_raw_version#v}"
|
||||
|
||||
# Extract just the semver part (Major.Minor.Patch) - strips anything after patch number
|
||||
# Handles: 1.22.19, 1.22.19-0-g7dc749f, 1.22.19-beta, etc.
|
||||
if [[ "$git_raw_version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
|
||||
version_major="${BASH_REMATCH[1]}"
|
||||
version_minor="${BASH_REMATCH[2]}"
|
||||
version_patch="${BASH_REMATCH[3]}"
|
||||
elif [[ -f "${LUX_PATH}/version.txt" ]]; then
|
||||
# Fallback to version.txt file for CI builds without tags
|
||||
version_content=$(cat "${LUX_PATH}/version.txt")
|
||||
if [[ "$version_content" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
|
||||
version_major="${BASH_REMATCH[1]}"
|
||||
version_minor="${BASH_REMATCH[2]}"
|
||||
version_patch="${BASH_REMATCH[3]}"
|
||||
else
|
||||
echo "ERROR: VERSION file content '$version_content' is not semantic version format (X.Y.Z)"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# Default version for development/CI builds without git tags
|
||||
echo "WARNING: No git tag found and no VERSION file - using default 0.0.0-dev"
|
||||
version_major="0"
|
||||
version_minor="0"
|
||||
version_patch="0"
|
||||
fi
|
||||
|
||||
git_version="${version_major}.${version_minor}.${version_patch}"
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Defines an image tag derived from the current branch or tag
|
||||
|
||||
image_tag="$( git symbolic-ref -q --short HEAD || git describe --tags --exact-match || true )"
|
||||
if [[ -z "${image_tag}" ]]; then
|
||||
# Supply a default tag when one is not discovered
|
||||
image_tag=ci_dummy
|
||||
elif [[ "${image_tag}" == */* ]]; then
|
||||
# Slashes are not legal for docker image tags - replace with dashes
|
||||
image_tag="$( echo "${image_tag}" | tr '/' '-' )"
|
||||
fi
|
||||
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# This script defines helper functions to enable building images for antithesis test setups. It is
|
||||
# intended to be reusable by repos other than node so almost all inputs are accepted as parameters
|
||||
# rather than being discovered from the environment.
|
||||
#
|
||||
# Since this file only defines functions, it is intended to be sourced rather than executed.
|
||||
|
||||
# Build the image that enables compiling golang binaries for the node and workload image
|
||||
# builds. The builder image is intended to enable building instrumented binaries if built
|
||||
# on amd64 and non-instrumented binaries if built on arm64.
|
||||
function build_antithesis_builder_image {
|
||||
local go_version=$1
|
||||
local image_name=$2
|
||||
local node_path=$3
|
||||
local target_path=$4
|
||||
|
||||
local base_dockerfile="${node_path}/tests/antithesis/Dockerfile"
|
||||
local builder_dockerfile="${base_dockerfile}.builder-instrumented"
|
||||
if [[ "$(go env GOARCH)" == "arm64" ]]; then
|
||||
# Antithesis instrumentation is only supported on amd64. On apple silicon (arm64),
|
||||
# an uninstrumented Dockerfile will be used to enable local test development.
|
||||
builder_dockerfile="${base_dockerfile}.builder-uninstrumented"
|
||||
fi
|
||||
|
||||
docker buildx build --build-arg GO_VERSION="${go_version}" -t "${image_name}" -f "${builder_dockerfile}" "${target_path}"
|
||||
}
|
||||
|
||||
# Build the antithesis node, workload, and config images.
|
||||
function build_antithesis_images {
|
||||
local go_version=$1
|
||||
local image_prefix=$2
|
||||
local base_image_name=$3
|
||||
local image_tag=$4
|
||||
local node_image_tag=$5
|
||||
local base_dockerfile=$6
|
||||
local uninstrumented_node_dockerfile=$7
|
||||
local target_path=$8
|
||||
local node_only=${9:-}
|
||||
local node_commit=${10:-}
|
||||
|
||||
# Define image names
|
||||
if [[ -n "${image_prefix}" ]]; then
|
||||
base_image_name="${image_prefix}/${base_image_name}"
|
||||
fi
|
||||
local node_image_name="${base_image_name}-node:${image_tag}"
|
||||
local workload_image_name="${base_image_name}-workload:${image_tag}"
|
||||
local config_image_name="${base_image_name}-config:${image_tag}"
|
||||
|
||||
# Define dockerfiles
|
||||
local node_dockerfile="${base_dockerfile}.node"
|
||||
# Working directory for instrumented builds
|
||||
local builder_workdir="/instrumented/customer"
|
||||
if [[ "$(go env GOARCH)" == "arm64" ]]; then
|
||||
# Antithesis instrumentation is only supported on amd64. On apple silicon (arm64),
|
||||
# uninstrumented Dockerfiles will be used to enable local test development.
|
||||
node_dockerfile="${uninstrumented_node_dockerfile}"
|
||||
# Working directory for uninstrumented builds
|
||||
builder_workdir="/build"
|
||||
fi
|
||||
|
||||
# Define default build command
|
||||
local docker_cmd="docker buildx build\
|
||||
--build-arg GO_VERSION=${go_version}\
|
||||
--build-arg BUILDER_IMAGE_TAG=${image_tag}\
|
||||
--build-arg BUILDER_WORKDIR=${builder_workdir}"
|
||||
if [[ -n "${node_commit}" ]]; then
|
||||
docker_cmd="${docker_cmd} --build-arg LUXD_COMMIT=${node_commit}"
|
||||
fi
|
||||
|
||||
# By default the node image is intended to be local-only.
|
||||
LUXD_NODE_IMAGE="antithesis-node-node:${node_image_tag}"
|
||||
|
||||
if [[ -n "${image_prefix}" && -z "${node_only}" ]]; then
|
||||
# Push images with an image prefix since the prefix defines a registry location, and only if building
|
||||
# all images. When building just the node image the image is only intended to be used locally.
|
||||
docker_cmd="${docker_cmd} --push"
|
||||
|
||||
# When the node image is pushed as part of the build, references to the image must be qualified.
|
||||
LUXD_NODE_IMAGE="${image_prefix}/${LUXD_NODE_IMAGE}"
|
||||
fi
|
||||
|
||||
# Ensure the correct node image name is configured
|
||||
docker_cmd="${docker_cmd} --build-arg LUXD_NODE_IMAGE=${LUXD_NODE_IMAGE}"
|
||||
|
||||
# Build node image first to allow the workload image to use it.
|
||||
${docker_cmd} -t "${node_image_name}" -f "${node_dockerfile}" "${target_path}"
|
||||
|
||||
if [[ -n "${node_only}" ]]; then
|
||||
# Skip building the config and workload images. Supports building the node node image as the
|
||||
# base image for a VM node image.
|
||||
return
|
||||
fi
|
||||
|
||||
# Build the config image
|
||||
${docker_cmd} -t "${config_image_name}" -f "${base_dockerfile}.config" "${target_path}"
|
||||
|
||||
# Build the workload image
|
||||
${docker_cmd} -t "${workload_image_name}" -f "${base_dockerfile}.workload" "${target_path}"
|
||||
}
|
||||
|
||||
# Generate the docker compose configuration for the antithesis config image.
|
||||
function gen_antithesis_compose_config {
|
||||
local image_tag=$1
|
||||
local exe_path=$2
|
||||
local target_path=$3
|
||||
local extra_compose_args=${4:-}
|
||||
|
||||
if [[ -d "${target_path}" ]]; then
|
||||
# Ensure the target path is empty before generating the compose config
|
||||
rm -r "${target_path:?}"
|
||||
fi
|
||||
mkdir -p "${target_path}"
|
||||
|
||||
# Define the env vars for the compose config generation
|
||||
local compose_env="TARGET_PATH=${target_path} IMAGE_TAG=${image_tag} ${extra_compose_args}"
|
||||
|
||||
# Generate compose config for copying into the config image
|
||||
# shellcheck disable=SC2086
|
||||
env ${compose_env} go run "${exe_path}"
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Validates the compose configuration of the antithesis config image
|
||||
# identified by IMAGE_NAME and IMAGE_TAG by:
|
||||
#
|
||||
# 1. Extracting the docker compose configuration from the image
|
||||
# 2. Running the workload and its target network without error for a minute
|
||||
# 3. Stopping the workload and its target network
|
||||
#
|
||||
# This script is intended to be sourced rather than executed directly.
|
||||
|
||||
if [[ -z "${IMAGE_NAME:-}" || -z "${IMAGE_TAG:-}" ]]; then
|
||||
echo "IMAGE_NAME and IMAGE_TAG must be set"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create a container from the config image to extract compose configuration from
|
||||
CONTAINER_NAME="tmp-${IMAGE_NAME}"
|
||||
docker create --name "${CONTAINER_NAME}" "${IMAGE_NAME}:${IMAGE_TAG}" /bin/true
|
||||
|
||||
# Create a temporary directory to write the compose configuration to
|
||||
TMPDIR="$(mktemp -d)"
|
||||
echo "using temporary directory ${TMPDIR} as the docker compose path"
|
||||
|
||||
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
|
||||
if [[ -z "${DEBUG:-}" ]]; then
|
||||
echo "removing temporary dir"
|
||||
rm -rf "${TMPDIR}"
|
||||
fi
|
||||
}
|
||||
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}/"
|
||||
|
||||
# Wait for up to TIMEOUT for the workload to emit HEALTHY_MESSAGE to indicate that all nodes are
|
||||
# reporting healthy. This indicates that the workload has been correctly configured. Subsequent
|
||||
# validation will need to be tailored to a given workload implementation.
|
||||
|
||||
TIMEOUT=30s
|
||||
HEALTHY_MESSAGE="all nodes reported healthy"
|
||||
|
||||
if timeout "${TIMEOUT}" bash -c "${COMPOSE_CMD} up 2>&1 | grep -m 1 '${HEALTHY_MESSAGE}'"; then
|
||||
echo "Saw log containing '${HEALTHY_MESSAGE}'"
|
||||
echo "Successfully invoked the antithesis test setup configured by ${IMAGE_NAME}:${IMAGE_TAG}"
|
||||
else
|
||||
echo "Failed to see log containing '${HEALTHY_MESSAGE}' within ${TIMEOUT}"
|
||||
exit 1
|
||||
fi
|
||||
Executable
+150
@@ -0,0 +1,150 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if ! [[ "$0" =~ scripts/lint.sh ]]; then
|
||||
echo "must be run from repository root"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# The -P option is not supported by the grep version installed by
|
||||
# default on macos. Since `-o errexit` is ignored in an if
|
||||
# conditional, triggering the problem here ensures script failure when
|
||||
# using an unsupported version of grep.
|
||||
grep -P 'lint.sh' scripts/lint.sh &> /dev/null || (\
|
||||
>&2 echo "error: This script requires a recent version of gnu grep.";\
|
||||
>&2 echo " On macos, gnu grep can be installed with 'brew install grep'.";\
|
||||
>&2 echo " It will also be necessary to ensure that gnu grep is available in the path.";\
|
||||
exit 255 )
|
||||
|
||||
if [ "$#" -eq 0 ]; then
|
||||
# by default, check all source code
|
||||
# to test only "consensus" package
|
||||
# ./scripts/lint.sh ./consensus/...
|
||||
TARGET="./..."
|
||||
else
|
||||
TARGET="${1}"
|
||||
fi
|
||||
|
||||
# by default, "./scripts/lint.sh" runs all lint tests
|
||||
# to run only "license_header" test
|
||||
# TESTS='license_header' ./scripts/lint.sh
|
||||
# NOTE: Some checks disabled temporarily - need codebase cleanup:
|
||||
# - license_header: mixed copyright formats
|
||||
# - require_error_is_no_funcs_as_params: test files need refactoring
|
||||
# - single_import: many files use parenthesized single imports
|
||||
# - require_no_error_inline_func: test files need inline error handling
|
||||
# - import_testing_only_in_tests: test helper files need moving to *test packages
|
||||
TESTS=${TESTS:-"golangci_lint interface_compliance_nil"}
|
||||
|
||||
function test_golangci_lint {
|
||||
go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6 run --config .golangci.yml
|
||||
}
|
||||
|
||||
# automatically checks license headers
|
||||
# to modify the file headers (if missing), remove "--verify" flag
|
||||
# TESTS='license_header' ADDLICENSE_FLAGS="--debug" ./scripts/lint.sh
|
||||
_addlicense_flags=${ADDLICENSE_FLAGS:-"--verify --debug"}
|
||||
function test_license_header {
|
||||
local files=()
|
||||
while IFS= read -r line; do files+=("$line"); done < <(
|
||||
find . -type f -name '*.go' \
|
||||
! -name '*.pb.go' \
|
||||
! -name '*.connect.go' \
|
||||
! -name 'mock_*.go' \
|
||||
! -name 'mocks_*.go' \
|
||||
! -path './**/*mock/*.go' \
|
||||
! -name '*.canoto.go' \
|
||||
! -name '*.bindings.go'
|
||||
)
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
go run github.com/palantir/go-license@v1.25.0 \
|
||||
--config=./header.yml \
|
||||
${_addlicense_flags} \
|
||||
"${files[@]}"
|
||||
}
|
||||
|
||||
function test_single_import {
|
||||
if grep -R -zo -P 'import \(\n\t".*"\n\)' .; then
|
||||
echo ""
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function test_require_error_is_no_funcs_as_params {
|
||||
if grep -R -zo -P 'require.ErrorIs\(.+?\)[^\n]*\)\n' .; then
|
||||
echo ""
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function test_require_no_error_inline_func {
|
||||
if grep -R -zo -P '\t+err :?= ((?!require|if).|\n)*require\.NoError\((t, )?err\)' .; then
|
||||
echo ""
|
||||
echo "Checking that a function with a single error return doesn't error should be done in-line."
|
||||
echo ""
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Ref: https://go.dev/doc/effective_go#blank_implements
|
||||
function test_interface_compliance_nil {
|
||||
if grep -R -o -P '_ .+? = &.+?\{\}' .; then
|
||||
echo ""
|
||||
echo "Interface compliance checks need to be of the form:"
|
||||
echo " var _ json.Marshaler = (*RawMessage)(nil)"
|
||||
echo ""
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function test_import_testing_only_in_tests {
|
||||
ROOT=$( git rev-parse --show-toplevel )
|
||||
NON_TEST_GO_FILES=$( find "${ROOT}" -iname '*.go' ! -iname '*_test.go' ! -path "${ROOT}/tests/*" );
|
||||
|
||||
IMPORT_TESTING=$( echo "${NON_TEST_GO_FILES}" | xargs grep -lP '^\s*(import\s+)?"testing"');
|
||||
IMPORT_TESTIFY=$( echo "${NON_TEST_GO_FILES}" | xargs grep -l '"github.com/stretchr/testify');
|
||||
IMPORT_FROM_TESTS=$( echo "${NON_TEST_GO_FILES}" | xargs grep -l '"github.com/luxfi/node/tests/');
|
||||
IMPORT_TEST_PKG=$( echo "${NON_TEST_GO_FILES}" | xargs grep -lP '"github.com/luxfi/node/.*?test"');
|
||||
|
||||
# TODO(arr4n): send a PR to add support for build tags in `mockgen` and then enable this.
|
||||
# IMPORT_GOMOCK=$( echo "${NON_TEST_GO_FILES}" | xargs grep -l '"go.uber.org/mock');
|
||||
HAVE_TEST_LOGIC=$( printf "%s\n%s\n%s\n%s" "${IMPORT_TESTING}" "${IMPORT_TESTIFY}" "${IMPORT_FROM_TESTS}" "${IMPORT_TEST_PKG}" );
|
||||
|
||||
IN_TEST_PKG=$( echo "${NON_TEST_GO_FILES}" | grep -P '.*test/[^/]+\.go$' ) # directory (hence package name) ends in "test"
|
||||
|
||||
# Files in /tests/ are already excluded by the `find ... ! -path`
|
||||
INTENDED_FOR_TESTING="${IN_TEST_PKG}"
|
||||
|
||||
# -3 suppresses files that have test logic and have the "test" build tag
|
||||
# -2 suppresses files that are tagged despite not having detectable test logic
|
||||
UNTAGGED=$( comm -23 <( echo "${HAVE_TEST_LOGIC}" | sort -u ) <( echo "${INTENDED_FOR_TESTING}" | sort -u ) );
|
||||
if [ -z "${UNTAGGED}" ];
|
||||
then
|
||||
return 0;
|
||||
fi
|
||||
|
||||
echo 'Non-test Go files importing test-only packages MUST (a) be in *test package; or (b) be in /tests/ directory:';
|
||||
echo "${UNTAGGED}";
|
||||
return 1;
|
||||
}
|
||||
|
||||
function run {
|
||||
local test="${1}"
|
||||
shift 1
|
||||
echo "START: '${test}' at $(date)"
|
||||
if "test_${test}" "$@" ; then
|
||||
echo "SUCCESS: '${test}' completed at $(date)"
|
||||
else
|
||||
echo "FAIL: '${test}' failed at $(date)"
|
||||
exit 255
|
||||
fi
|
||||
}
|
||||
|
||||
echo "Running '$TESTS' at: $(date)"
|
||||
for test in $TESTS; do
|
||||
run "${test}" "${TARGET}"
|
||||
done
|
||||
|
||||
echo "ALL SUCCESS!"
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if ! [[ "$0" =~ scripts/mock.gen.sh ]]; then
|
||||
echo "must be run from repository root"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# https://github.com/uber-go/mock
|
||||
# Using go run to execute mockgen within the module context
|
||||
# This allows mockgen to resolve local imports correctly
|
||||
MOCKGEN="go run go.uber.org/mock/mockgen@v0.6.0"
|
||||
|
||||
source ./scripts/constants.sh
|
||||
|
||||
outputted_files=()
|
||||
|
||||
# tuples of (source import path, comma-separated interface names, output file path)
|
||||
input="scripts/mocks.mockgen.txt"
|
||||
while IFS= read -r line
|
||||
do
|
||||
IFS='=' read -r src_import_path interface_name output_path <<< "${line}"
|
||||
package_name="$(basename "$(dirname "$output_path")")"
|
||||
echo "Generating ${output_path}..."
|
||||
outputted_files+=("${output_path}")
|
||||
$MOCKGEN -package="${package_name}" -destination="${output_path}" "${src_import_path}" "${interface_name}"
|
||||
|
||||
done < "$input"
|
||||
|
||||
# tuples of (source import path, comma-separated interface names to exclude, output file path)
|
||||
input="scripts/mocks.mockgen.source.txt"
|
||||
while IFS= read -r line
|
||||
do
|
||||
IFS='=' read -r source_path exclude_interfaces output_path <<< "${line}"
|
||||
package_name=$(basename "$(dirname "$output_path")")
|
||||
outputted_files+=("${output_path}")
|
||||
echo "Generating ${output_path}..."
|
||||
|
||||
$MOCKGEN \
|
||||
-source="${source_path}" \
|
||||
-destination="${output_path}" \
|
||||
-package="${package_name}" \
|
||||
-exclude_interfaces="${exclude_interfaces}"
|
||||
|
||||
done < "$input"
|
||||
|
||||
mapfile -t all_generated_files < <(grep -Rl 'Code generated by MockGen. DO NOT EDIT.')
|
||||
|
||||
# Exclude certain files
|
||||
outputted_files+=('scripts/mock.gen.sh') # This file
|
||||
outputted_files+=('vms/components/lux/mock_transferable_out.go') # Embedded verify.IsState
|
||||
outputted_files+=('vms/platformvm/fx/mock_fx.go') # Embedded verify.IsNotState
|
||||
|
||||
mapfile -t diff_files < <(echo "${all_generated_files[@]}" "${outputted_files[@]}" | tr ' ' '\n' | sort | uniq -u)
|
||||
|
||||
if (( ${#diff_files[@]} )); then
|
||||
printf "\nFAILURE\n"
|
||||
echo "Detected MockGen generated files that are not in scripts/mocks.mockgen.source.txt or scripts/mocks.mockgen.txt:"
|
||||
printf "%s\n" "${diff_files[@]}"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
echo "SUCCESS"
|
||||
@@ -0,0 +1,9 @@
|
||||
consensus/engine/core/sender.go=StateSummarySender,AcceptedStateSummarySender,FrontierSender,AcceptedSender,FetchSender,Sender,QuerySender,CrossChainSender,NetworkSender,Gossiper=consensus/engine/core/mock_sender.go
|
||||
consensus/networking/router/router.go=InternalHandler=consensus/networking/router/mock_router.go
|
||||
consensus/networking/sender/external_sender.go==consensus/networking/sender/mock_external_sender.go
|
||||
vms/xvm/block/executor/manager.go==vms/xvm/block/executor/mock_manager.go
|
||||
vms/xvm/txs/tx.go==vms/xvm/txs/mock_unsigned_tx.go
|
||||
vms/platformvm/block/executor/manager.go==vms/platformvm/block/executor/mock_manager.go
|
||||
vms/platformvm/txs/staker_tx.go=ValidatorTx,DelegatorTx,StakerTx,PermissionlessStaker=vms/platformvm/txs/mock_staker_tx.go
|
||||
vms/platformvm/txs/unsigned_tx.go==vms/platformvm/txs/mock_unsigned_tx.go
|
||||
x/merkledb/db.go=ChangeProofer,RangeProofer,Clearer,Prefetcher=x/merkledb/mock_db.go
|
||||
@@ -0,0 +1,42 @@
|
||||
github.com/luxfi/node/server/http=Server=api/server/mock_server.go
|
||||
github.com/luxfi/node/codec=Manager=codec/mock_manager.go
|
||||
github.com/luxfi/node/database=Batch=database/mock_batch.go
|
||||
github.com/luxfi/node/database=Iterator=database/mock_iterator.go
|
||||
github.com/luxfi/node/message=OutboundMessage=message/mock_message.go
|
||||
github.com/luxfi/node/message=OutboundMsgBuilder=message/mock_outbound_message_builder.go
|
||||
github.com/luxfi/node/consensus/consensus/linear=Block=consensus/consensus/linear/lineartest/mock_block.go
|
||||
github.com/luxfi/node/consensus/engine/dag/vertex=LinearizableVM=consensus/engine/dag/vertex/mock_vm.go
|
||||
github.com/luxfi/node/consensus/engine/linear/block=BuildBlockWithRuntimeChainVM=consensus/engine/linear/block/mock_build_block_with_context_vm.go
|
||||
github.com/luxfi/node/consensus/engine/linear/block=ChainVM=consensus/engine/linear/block/mock_chain_vm.go
|
||||
github.com/luxfi/node/consensus/engine/linear/block=StateSyncableVM=consensus/engine/linear/block/mock_state_syncable_vm.go
|
||||
github.com/luxfi/node/consensus/engine/linear/block=WithVerifyRuntime=consensus/engine/linear/block/mock_with_verify_context.go
|
||||
github.com/luxfi/node/consensus/networking/handler=Handler=consensus/networking/handler/mock_handler.go
|
||||
github.com/luxfi/node/consensus/networking/timeout=Manager=consensus/networking/timeout/mock_manager.go
|
||||
github.com/luxfi/node/consensus/networking/tracker=Targeter=consensus/networking/tracker/mock_targeter.go
|
||||
github.com/luxfi/node/consensus/networking/tracker=Tracker=consensus/networking/tracker/mock_resource_tracker.go
|
||||
github.com/luxfi/node/consensus/uptime=Calculator=consensus/uptime/mock_calculator.go
|
||||
github.com/luxfi/node/consensus/validators=State=consensus/validators/mock_state.go
|
||||
github.com/luxfi/node/consensus/validators=NetConnector=consensus/validators/mock_chain_connector.go
|
||||
github.com/luxfi/node/utils/filesystem=Reader=utils/filesystem/mock_io.go
|
||||
github.com/luxfi/node/utils/hashing=Hasher=utils/hashing/mock_hasher.go
|
||||
github.com/luxfi/node/utils/resource=User=utils/resource/mock_user.go
|
||||
github.com/luxfi/node/vms/xvm/block=Block=vms/xvm/block/mock_block.go
|
||||
github.com/luxfi/node/vms/xvm/metrics=Metrics=vms/xvm/metrics/mock_metrics.go
|
||||
github.com/luxfi/node/vms/xvm/state=Chain,State,Diff=vms/xvm/state/mock_state.go
|
||||
github.com/luxfi/node/vms/xvm/txs/mempool=Mempool=vms/xvm/txs/mempool/mock_mempool.go
|
||||
github.com/luxfi/node/vms/components/lux=TransferableIn=vms/components/lux/mock_transferable_in.go
|
||||
github.com/luxfi/node/vms/components/verify=Verifiable=vms/components/verify/mock_verifiable.go
|
||||
github.com/luxfi/node/vms/platformvm/block=Block=vms/platformvm/block/mock_block.go
|
||||
github.com/luxfi/node/vms/platformvm/state=Chain,Diff,State,Versions=vms/platformvm/state/mock_state.go
|
||||
github.com/luxfi/node/vms/platformvm/state=StakerIterator=vms/platformvm/state/mock_staker_iterator.go
|
||||
github.com/luxfi/node/vms/platformvm/txs/mempool=Mempool=vms/platformvm/txs/mempool/mock_mempool.go
|
||||
github.com/luxfi/node/vms/platformvm/utxo=Verifier=vms/platformvm/utxo/mock_verifier.go
|
||||
github.com/luxfi/node/vms/proposervm/proposer=Windower=vms/proposervm/proposer/mock_windower.go
|
||||
github.com/luxfi/node/vms/proposervm/scheduler=Scheduler=vms/proposervm/scheduler/mock_scheduler.go
|
||||
github.com/luxfi/node/vms/proposervm/state=State=vms/proposervm/state/mock_state.go
|
||||
github.com/luxfi/node/vms/proposervm=PostForkBlock=vms/proposervm/mock_post_fork_block.go
|
||||
github.com/luxfi/node/vms/registry=VMGetter=vms/registry/mock_vm_getter.go
|
||||
github.com/luxfi/node/vms/registry=VMRegistry=vms/registry/mock_vm_registry.go
|
||||
github.com/luxfi/node/vms=Factory,Manager=vms/mock_manager.go
|
||||
github.com/luxfi/node/x/sync=Client=x/sync/mock_client.go
|
||||
github.com/luxfi/node/x/sync=NetworkClient=x/sync/mock_network_client.go
|
||||
Executable
+60
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if ! [[ "$0" =~ scripts/protobuf_codegen.sh ]]; then
|
||||
echo "must be run from repository root"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# the versions here should match those of the binaries installed in the nix dev shell
|
||||
|
||||
## ensure the correct version of "buf" is installed
|
||||
BUF_VERSION='1.47.2'
|
||||
if [[ $(buf --version | cut -f2 -d' ') != "${BUF_VERSION}" ]]; then
|
||||
echo "could not find buf ${BUF_VERSION}, is it installed + in PATH?"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
## ensure the correct version of "protoc-gen-go" is installed
|
||||
PROTOC_GEN_GO_VERSION='v1.35.1'
|
||||
if [[ $(protoc-gen-go --version | cut -f2 -d' ') != "${PROTOC_GEN_GO_VERSION}" ]]; then
|
||||
echo "could not find protoc-gen-go ${PROTOC_GEN_GO_VERSION}, is it installed + in PATH?"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
## ensure the correct version of "protoc-gen-go-grpc" is installed
|
||||
PROTOC_GEN_GO_GRPC_VERSION='1.3.0'
|
||||
if [[ $(protoc-gen-go-grpc --version | cut -f2 -d' ') != "${PROTOC_GEN_GO_GRPC_VERSION}" ]]; then
|
||||
echo "could not find protoc-gen-go-grpc ${PROTOC_GEN_GO_GRPC_VERSION}, is it installed + in PATH?"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
BUF_MODULES=("proto" "connectproto")
|
||||
|
||||
REPO_ROOT=$PWD
|
||||
for BUF_MODULE in "${BUF_MODULES[@]}"; do
|
||||
TARGET=$REPO_ROOT/$BUF_MODULE
|
||||
if [ -n "${1:-}" ]; then
|
||||
TARGET="$1"
|
||||
fi
|
||||
|
||||
# move to buf module directory
|
||||
cd "$TARGET"
|
||||
|
||||
echo "Generating for buf module $BUF_MODULE"
|
||||
echo "Running protobuf fmt for..."
|
||||
buf format -w
|
||||
|
||||
echo "Running protobuf lint check..."
|
||||
if ! buf lint; then
|
||||
echo "ERROR: protobuf linter failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Re-generating protobuf..."
|
||||
if ! buf generate; then
|
||||
echo "ERROR: protobuf generation failed"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
Executable
+120
@@ -0,0 +1,120 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Starts a metric instance in agent-mode, forwarding to a central
|
||||
# instance. Intended to enable metrics collection from temporary networks running
|
||||
# locally and in CI.
|
||||
#
|
||||
# The metric instance will remain running in the background and will forward
|
||||
# metrics to the central instance for all tmpnet networks.
|
||||
#
|
||||
# To stop it:
|
||||
#
|
||||
# $ kill -9 `cat ~/.tmpnet/metric/run.pid` && rm ~/.tmpnet/metric/run.pid
|
||||
#
|
||||
|
||||
# e.g.,
|
||||
# PROMETHEUS_ID=<id> PROMETHEUS_PASSWORD=<password> ./scripts/run_metric.sh
|
||||
if ! [[ "$0" =~ scripts/run_metric.sh ]]; then
|
||||
echo "must be run from repository root"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
PROMETHEUS_WORKING_DIR="${HOME}/.tmpnet/metric"
|
||||
PIDFILE="${PROMETHEUS_WORKING_DIR}"/run.pid
|
||||
|
||||
# First check if an agent-mode metric is already running. A single instance can collect
|
||||
# metrics from all local temporary networks.
|
||||
if pgrep --pidfile="${PIDFILE}" -f 'metric.*enable-feature=agent' &> /dev/null; then
|
||||
echo "metric is already running locally with --enable-feature=agent"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
PROMETHEUS_URL="${PROMETHEUS_URL:-https://metric-experimental.lux-dev.network}"
|
||||
if [[ -z "${PROMETHEUS_URL}" ]]; then
|
||||
echo "Please provide a value for PROMETHEUS_URL"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PROMETHEUS_ID="${PROMETHEUS_ID:-}"
|
||||
if [[ -z "${PROMETHEUS_ID}" ]]; then
|
||||
echo "Please provide a value for PROMETHEUS_ID"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PROMETHEUS_PASSWORD="${PROMETHEUS_PASSWORD:-}"
|
||||
if [[ -z "${PROMETHEUS_PASSWORD}" ]]; then
|
||||
echo "Plase provide a value for PROMETHEUS_PASSWORD"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# This was the LTS version when this script was written. Probably not
|
||||
# much reason to update it unless something breaks since the usage
|
||||
# here is only to collect metrics from temporary networks.
|
||||
VERSION="2.45.3"
|
||||
|
||||
# Ensure the metric command is locally available
|
||||
CMD=metric
|
||||
if ! command -v "${CMD}" &> /dev/null; then
|
||||
# Try to use a local version
|
||||
CMD="${PWD}/bin/metric"
|
||||
if ! command -v "${CMD}" &> /dev/null; then
|
||||
echo "metric not found, attempting to install..."
|
||||
|
||||
# Determine the arch
|
||||
if which sw_vers &> /dev/null; then
|
||||
echo "on macos, only amd64 binaries are available so rosetta is required on apple silicon machines."
|
||||
echo "to avoid using rosetta, install via homebrew: brew install metric"
|
||||
DIST=darwin
|
||||
else
|
||||
ARCH="$(uname -i)"
|
||||
if [[ "${ARCH}" != "x86_64" ]]; then
|
||||
echo "on linux, only amd64 binaries are available. manual installation of metric is required."
|
||||
exit 1
|
||||
else
|
||||
DIST="linux"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Install the specified release
|
||||
PROMETHEUS_FILE="metric-${VERSION}.${DIST}-amd64"
|
||||
URL="https://github.com/metric/metric/releases/download/v${VERSION}/${PROMETHEUS_FILE}.tar.gz"
|
||||
curl -s -L "${URL}" | tar zxv -C /tmp > /dev/null
|
||||
mkdir -p "$(dirname "${CMD}")"
|
||||
cp /tmp/"${PROMETHEUS_FILE}/metric" "${CMD}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Configure metric
|
||||
FILE_SD_PATH="${PROMETHEUS_WORKING_DIR}/file_sd_configs"
|
||||
mkdir -p "${FILE_SD_PATH}"
|
||||
|
||||
echo "writing configuration..."
|
||||
cat >"${PROMETHEUS_WORKING_DIR}"/metric.yaml <<EOL
|
||||
# my global config
|
||||
global:
|
||||
# Make sure this value takes into account the network-shutdown-delay in tests/fixture/e2e/env.go
|
||||
scrape_interval: 10s # Default is every 1 minute.
|
||||
evaluation_interval: 10s # The default is every 1 minute.
|
||||
scrape_timeout: 5s # The default is every 10s
|
||||
|
||||
scrape_configs:
|
||||
- job_name: "node"
|
||||
metrics_path: "/ext/metrics"
|
||||
file_sd_configs:
|
||||
- files:
|
||||
- '${FILE_SD_PATH}/*.json'
|
||||
|
||||
remote_write:
|
||||
- url: "${PROMETHEUS_URL}/api/v1/write"
|
||||
basic_auth:
|
||||
username: "${PROMETHEUS_ID}"
|
||||
password: "${PROMETHEUS_PASSWORD}"
|
||||
EOL
|
||||
|
||||
echo "starting metric..."
|
||||
cd "${PROMETHEUS_WORKING_DIR}"
|
||||
nohup "${CMD}" --config.file=metric.yaml --web.listen-address=localhost:0 --enable-feature=agent > metric.log 2>&1 &
|
||||
echo $! > "${PIDFILE}"
|
||||
echo "running with pid $(cat "${PIDFILE}")"
|
||||
Executable
+115
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Starts a promtail instance to collect logs from temporary networks
|
||||
# running locally and in CI.
|
||||
#
|
||||
# The promtail instance will remain running in the background and will forward
|
||||
# logs to the central instance for all tmpnet networks.
|
||||
#
|
||||
# To stop it:
|
||||
#
|
||||
# $ kill -9 `cat ~/.tmpnet/promtail/run.pid` && rm ~/.tmpnet/promtail/run.pid
|
||||
#
|
||||
|
||||
# e.g.,
|
||||
# LOKI_ID=<id> LOKI_PASSWORD=<password> ./scripts/run_promtail.sh
|
||||
if ! [[ "$0" =~ scripts/run_promtail.sh ]]; then
|
||||
echo "must be run from repository root"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
PROMTAIL_WORKING_DIR="${HOME}/.tmpnet/promtail"
|
||||
PIDFILE="${PROMTAIL_WORKING_DIR}"/run.pid
|
||||
|
||||
# First check if promtail is already running. A single instance can
|
||||
# collect logs from all local temporary networks.
|
||||
if pgrep --pidfile="${PIDFILE}" &> /dev/null; then
|
||||
echo "promtail is already running"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
LOKI_URL="${LOKI_URL:-https://loki-experimental.lux-dev.network}"
|
||||
if [[ -z "${LOKI_URL}" ]]; then
|
||||
echo "Please provide a value for LOKI_URL"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LOKI_ID="${LOKI_ID:-}"
|
||||
if [[ -z "${LOKI_ID}" ]]; then
|
||||
echo "Please provide a value for LOKI_ID"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LOKI_PASSWORD="${LOKI_PASSWORD:-}"
|
||||
if [[ -z "${LOKI_PASSWORD}" ]]; then
|
||||
echo "Plase provide a value for LOKI_PASSWORD"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Version as of this writing
|
||||
VERSION="v2.9.5"
|
||||
|
||||
# Ensure the promtail command is locally available
|
||||
CMD=promtail
|
||||
if ! command -v "${CMD}" &> /dev/null; then
|
||||
# Try to use a local version
|
||||
CMD="${PWD}/bin/promtail"
|
||||
if ! command -v "${CMD}" &> /dev/null; then
|
||||
echo "promtail not found, attempting to install..."
|
||||
# Determine the arch
|
||||
if which sw_vers &> /dev/null; then
|
||||
DIST="darwin-$(uname -m)"
|
||||
else
|
||||
ARCH="$(uname -i)"
|
||||
if [[ "${ARCH}" == "aarch64" ]]; then
|
||||
ARCH="arm64"
|
||||
elif [[ "${ARCH}" == "x86_64" ]]; then
|
||||
ARCH="amd64"
|
||||
fi
|
||||
DIST="linux-${ARCH}"
|
||||
fi
|
||||
|
||||
# Install the specified release
|
||||
PROMTAIL_FILE="promtail-${DIST}"
|
||||
ZIP_PATH="/tmp/${PROMTAIL_FILE}.zip"
|
||||
BIN_DIR="$(dirname "${CMD}")"
|
||||
URL="https://github.com/grafana/loki/releases/download/${VERSION}/promtail-${DIST}.zip"
|
||||
curl -L -o "${ZIP_PATH}" "${URL}"
|
||||
unzip "${ZIP_PATH}" -d "${BIN_DIR}"
|
||||
mv "${BIN_DIR}/${PROMTAIL_FILE}" "${CMD}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Configure promtail
|
||||
FILE_SD_PATH="${PROMTAIL_WORKING_DIR}/file_sd_configs"
|
||||
mkdir -p "${FILE_SD_PATH}"
|
||||
|
||||
echo "writing configuration..."
|
||||
cat >"${PROMTAIL_WORKING_DIR}"/promtail.yaml <<EOL
|
||||
server:
|
||||
http_listen_port: 0
|
||||
grpc_listen_port: 0
|
||||
|
||||
positions:
|
||||
filename: "${PROMTAIL_WORKING_DIR}/positions.yaml"
|
||||
|
||||
client:
|
||||
url: "${LOKI_URL}/api/prom/push"
|
||||
basic_auth:
|
||||
username: "${LOKI_ID}"
|
||||
password: "${LOKI_PASSWORD}"
|
||||
|
||||
scrape_configs:
|
||||
- job_name: "node"
|
||||
file_sd_configs:
|
||||
- files:
|
||||
- '${FILE_SD_PATH}/*.json'
|
||||
EOL
|
||||
|
||||
echo "starting promtail..."
|
||||
cd "${PROMTAIL_WORKING_DIR}"
|
||||
nohup "${CMD}" -config.file=promtail.yaml > promtail.log 2>&1 &
|
||||
echo $! > "${PIDFILE}"
|
||||
echo "running with pid $(cat "${PIDFILE}")"
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Assume the system-installed task is compatible with the taskfile version
|
||||
if command -v task > /dev/null 2>&1; then
|
||||
exec task "${@}"
|
||||
else
|
||||
go run github.com/go-task/task/v3/cmd/task@v3.39.2 "${@}"
|
||||
fi
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# This script can also be used to correct the problems detected by shellcheck by invoking as follows:
|
||||
#
|
||||
# ./scripts/tests.shellcheck.sh -f diff | git apply
|
||||
#
|
||||
|
||||
if ! [[ "$0" =~ scripts/shellcheck.sh ]]; then
|
||||
echo "must be run from repository root"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# `find *` is the simplest way to ensure find does not include a
|
||||
# leading `.` in filenames it emits. A leading `.` will prevent the
|
||||
# use of `git apply` to fix reported shellcheck issues. This is
|
||||
# compatible with both macos and linux (unlike the use of -printf).
|
||||
#
|
||||
# shellcheck disable=SC2035
|
||||
find * -name "*.sh" -type f -print0 | xargs -0 shellcheck "${@}"
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# --kubeconfig and --kubeconfig-context should be provided in the form --arg=value
|
||||
# to work with the simplistic mechanism enabling flag reuse.
|
||||
|
||||
# Enable reuse of the arguments to ginkgo relevant to starting a cluster
|
||||
START_CLUSTER_ARGS=()
|
||||
for arg in "$@"; do
|
||||
if [[ "${arg}" =~ "--kubeconfig=" || "${arg}" =~ "--kubeconfig-context=" || "${arg}" =~ "--start-metrics-collector" || "${arg}" =~ "--start-logs-collector" ]]; then
|
||||
START_CLUSTER_ARGS+=("${arg}")
|
||||
fi
|
||||
done
|
||||
./bin/tmpnetctl start-kind-cluster "${START_CLUSTER_ARGS[@]}"
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Validates the construction of the antithesis images for a test setup specified by TEST_SETUP by:
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# `docker compose` is used (docker compose v2 plugin) due to it being installed by default on
|
||||
# public github runners. `docker-compose` (the v1 plugin) is not installed by default.
|
||||
|
||||
# e.g.,
|
||||
# TEST_SETUP=node ./scripts/tests.build_antithesis_images.sh # Test build of images for node test setup
|
||||
# DEBUG=1 TEST_SETUP=node ./scripts/tests.build_antithesis_images.sh # Retain the temporary compose path for troubleshooting
|
||||
|
||||
LUX_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
|
||||
|
||||
# Discover the default tag that will be used for the image
|
||||
source "${LUX_PATH}"/scripts/git_commit.sh
|
||||
export IMAGE_TAG="${commit_hash}"
|
||||
|
||||
# Build the images for the specified test setup
|
||||
export TEST_SETUP="${TEST_SETUP:-}"
|
||||
bash -x "${LUX_PATH}"/scripts/build_antithesis_images.sh
|
||||
|
||||
# Test the images
|
||||
export IMAGE_NAME="antithesis-${TEST_SETUP}-config"
|
||||
export DEBUG="${DEBUG:-}"
|
||||
set -x
|
||||
. "${LUX_PATH}"/scripts/lib_test_antithesis_images.sh
|
||||
Executable
+86
@@ -0,0 +1,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
|
||||
LUX_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
|
||||
|
||||
source "$LUX_PATH"/scripts/constants.sh
|
||||
source "$LUX_PATH"/scripts/git_commit.sh
|
||||
source "$LUX_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 'node --version'"
|
||||
docker run -t --rm --platform "linux/$arch" "$target_image" /node/build/node --version
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
echo "checking build of single-arch images"
|
||||
build_and_test node
|
||||
|
||||
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}/node"
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Run e2e tests for bootstrap monitor.
|
||||
#
|
||||
# --kubeconfig and --kubeconfig-context should be provided in the form --arg=value
|
||||
# to work with the simplistic mechanism enabling flag reuse.
|
||||
|
||||
if ! [[ "$0" =~ scripts/tests.e2e.bootstrap_monitor.sh ]]; then
|
||||
echo "must be run from repository root"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
./scripts/start_kind_cluster.sh "$@"
|
||||
./bin/ginkgo -v ./tests/fixture/bootstrapmonitor/e2e "$@"
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# This script verifies that a network can be reused across test runs.
|
||||
|
||||
# e.g.,
|
||||
# ./scripts/build.sh
|
||||
# ./scripts/tests.e2e.sh --ginkgo.label-filter=x # All arguments are supplied to ginkgo
|
||||
# LUXD_PATH=./build/node ./scripts/tests.e2e.existing.sh # Customization of node path
|
||||
if ! [[ "$0" =~ scripts/tests.e2e.existing.sh ]]; then
|
||||
echo "must be run from repository root"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# Provide visual separation between testing and setup/teardown
|
||||
function print_separator {
|
||||
printf '%*s\n' "${COLUMNS:-80}" '' | tr ' ' ─
|
||||
}
|
||||
|
||||
# Ensure network cleanup on teardown
|
||||
function cleanup {
|
||||
print_separator
|
||||
echo "cleaning up reusable network"
|
||||
./bin/ginkgo -v ./tests/e2e -- --stop-network
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# TMPNET_NETWORK_DIR needs to be unset to ensure --reuse-network won't target an existing network
|
||||
unset TMPNET_NETWORK_DIR
|
||||
|
||||
print_separator
|
||||
echo "starting initial test run that should create the reusable network"
|
||||
./scripts/tests.e2e.sh --reuse-network --ginkgo.focus-file=xsvm.go "${@}"
|
||||
|
||||
print_separator
|
||||
echo "determining the network path of the reusable network created by the first test run"
|
||||
SYMLINK_PATH="${HOME}/.tmpnet/networks/latest_node-e2e"
|
||||
INITIAL_NETWORK_DIR="$(realpath "${SYMLINK_PATH}")"
|
||||
|
||||
print_separator
|
||||
echo "starting second test run that should reuse the network created by the first run"
|
||||
echo "the network is first restarted to verify that the network state was correctly serialized"
|
||||
./scripts/tests.e2e.sh --restart-network --ginkgo.focus-file=xsvm.go "${@}"
|
||||
|
||||
SUBSEQUENT_NETWORK_DIR="$(realpath "${SYMLINK_PATH}")"
|
||||
echo "checking that the symlink path remains the same, indicating that the network was reused"
|
||||
if [[ "${INITIAL_NETWORK_DIR}" != "${SUBSEQUENT_NETWORK_DIR}" ]]; then
|
||||
print_separator
|
||||
echo "network was not reused across test runs"
|
||||
exit 1
|
||||
fi
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Run e2e tests against nodes deployed to a kind cluster.
|
||||
|
||||
# TODO(marun) Support testing against a remote cluster
|
||||
|
||||
if ! [[ "$0" =~ scripts/tests.e2e.kube.sh ]]; then
|
||||
echo "must be run from repository root"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# This script will use kubeconfig arguments if supplied
|
||||
./scripts/start_kind_cluster.sh "$@"
|
||||
|
||||
# Use an image that will be pushed to the local registry that the kind cluster is configured to use.
|
||||
LUXD_IMAGE="localhost:5001/node"
|
||||
XSVM_IMAGE="${LUXD_IMAGE}-xsvm"
|
||||
if [[ -n "${SKIP_BUILD_IMAGE:-}" ]]; then
|
||||
echo "Skipping build of xsvm image due to SKIP_BUILD_IMAGE=${SKIP_BUILD_IMAGE}"
|
||||
else
|
||||
XSVM_IMAGE="${XSVM_IMAGE}" LUXD_IMAGE="${LUXD_IMAGE}" bash -x ./scripts/build_xsvm_image.sh
|
||||
fi
|
||||
|
||||
bash -x ./scripts/tests.e2e.sh --runtime=kube --kube-image="${XSVM_IMAGE}" "$@"
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# e.g.,
|
||||
# ./scripts/tests.e2e.sh
|
||||
# ./scripts/tests.e2e.sh --ginkgo.label-filter=x # All arguments are supplied to ginkgo
|
||||
# E2E_SERIAL=1 ./scripts/tests.e2e.sh # Run tests serially
|
||||
# E2E_RANDOM_SEED=1234882 ./scripts/tests.e2e.sh # Specify a specific seed to order test execution by
|
||||
# LUXD_PATH=./build/node ./scripts/tests.e2e.sh # Customization of node path
|
||||
if ! [[ "$0" =~ scripts/tests.e2e.sh ]]; then
|
||||
echo "must be run from repository root"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
#################################
|
||||
# Sourcing constants.sh ensures that the necessary CGO flags are set to
|
||||
# build the portable version of BLST. Without this, ginkgo may fail to
|
||||
# build the test binary if run on a host (e.g. github worker) that lacks
|
||||
# the instructions to build non-portable BLST.
|
||||
source ./scripts/constants.sh
|
||||
|
||||
E2E_ARGS=("${@}")
|
||||
|
||||
# If not running in kubernetes, default to using a local node binary
|
||||
if ! [[ "${E2E_ARGS[*]}" =~ "--runtime=kube" && ! "${E2E_ARGS[*]}" =~ "--node-path" ]]; then
|
||||
# Ensure an absolute path to avoid dependency on the working directory of script execution.
|
||||
LUXD_PATH="$(realpath "${LUXD_PATH:-./build/node}")"
|
||||
E2E_ARGS+=("--node-path=${LUXD_PATH}")
|
||||
fi
|
||||
|
||||
#################################
|
||||
# Determine ginkgo args
|
||||
GINKGO_ARGS=""
|
||||
if [[ -n "${E2E_SERIAL:-}" ]]; then
|
||||
# Specs will be executed serially. This supports running e2e tests in CI
|
||||
# where parallel execution of tests that start new nodes beyond the
|
||||
# initial set of validators could overload the free tier CI workers.
|
||||
# Forcing serial execution in this test script instead of marking
|
||||
# resource-hungry tests as serial supports executing the test suite faster
|
||||
# on powerful development workstations.
|
||||
echo "tests will be executed serially to minimize resource requirements"
|
||||
else
|
||||
# Enable parallel execution of specs defined in the test binary by
|
||||
# default. This requires invoking the binary via the ginkgo cli
|
||||
# since the test binary isn't capable of executing specs in
|
||||
# parallel.
|
||||
echo "tests will be executed in parallel"
|
||||
GINKGO_ARGS="-p"
|
||||
fi
|
||||
# Reference: https://onsi.github.io/ginkgo/#spec-randomization
|
||||
if [[ -n "${E2E_RANDOM_SEED:-}" ]]; then
|
||||
# Supply a specific seed to simplify reproduction of test failures
|
||||
GINKGO_ARGS+=" --seed=${E2E_RANDOM_SEED}"
|
||||
else
|
||||
# Execute in random order to identify unwanted dependency
|
||||
GINKGO_ARGS+=" --randomize-all"
|
||||
fi
|
||||
|
||||
#################################
|
||||
# shellcheck disable=SC2086
|
||||
./bin/ginkgo ${GINKGO_ARGS} -v ./tests/e2e -- "${E2E_ARGS[@]}"
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Run load test against nodes deployed to a kind cluster
|
||||
|
||||
if ! [[ "$0" =~ scripts/tests.load.kube.kind.sh ]]; then
|
||||
echo "must be run from repository root"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# This script will use kubeconfig arguments if supplied
|
||||
./scripts/start_kind_cluster.sh "$@"
|
||||
|
||||
# Build Lux Node image
|
||||
LUXD_IMAGE="localhost:5001/node"
|
||||
if [[ -n "${SKIP_BUILD_IMAGE:-}" ]]; then
|
||||
echo "Skipping build of node image due to SKIP_BUILD_IMAGE=${SKIP_BUILD_IMAGE}"
|
||||
else
|
||||
DOCKER_IMAGE="$LUXD_IMAGE" FORCE_TAG_LATEST=1 ./scripts/build_image.sh
|
||||
fi
|
||||
|
||||
# Determine kubeconfig context to use
|
||||
KUBECONFIG_CONTEXT=""
|
||||
|
||||
# Check if --kubeconfig-context is already provided in arguments
|
||||
if [[ "$*" =~ --kubeconfig-context ]]; then
|
||||
# User provided a context, use it as-is
|
||||
echo "Using provided kubeconfig context from arguments"
|
||||
else
|
||||
# Default to the RBAC context
|
||||
KUBECONFIG_CONTEXT="--kubeconfig-context=kind-kind-tmpnet"
|
||||
echo "Defaulting to limited-permission context 'kind-kind-tmpnet' to test RBAC Role permissions"
|
||||
fi
|
||||
|
||||
go run ./tests/load/c/main --runtime=kube --kube-image="$LUXD_IMAGE" "$KUBECONFIG_CONTEXT" "$@"
|
||||
Executable
+70
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# e.g.,
|
||||
# ./scripts/tests.upgrade.sh # Use default version
|
||||
# ./scripts/tests.upgrade.sh 1.11.0 # Specify a version
|
||||
# LUXD_PATH=./path/to/node ./scripts/tests.upgrade.sh 1.11.0 # Customization of node path
|
||||
if ! [[ "$0" =~ scripts/tests.upgrade.sh ]]; then
|
||||
echo "must be run from repository root"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# The Lux Node local network does not support long-lived
|
||||
# backwards-compatible networks. When a breaking change is made to the
|
||||
# local network, this flag must be updated to the last compatible
|
||||
# version with the latest code.
|
||||
#
|
||||
# v1.13.0 is the earliest version that supports Fortuna.
|
||||
DEFAULT_VERSION="1.13.0"
|
||||
|
||||
VERSION="${1:-${DEFAULT_VERSION}}"
|
||||
if [[ -z "${VERSION}" ]]; then
|
||||
echo "Missing version argument!"
|
||||
echo "Usage: ${0} [VERSION]" >>/dev/stderr
|
||||
exit 255
|
||||
fi
|
||||
|
||||
LUXD_PATH="$(realpath "${LUXD_PATH:-./build/node}")"
|
||||
|
||||
#################################
|
||||
# download node
|
||||
# https://github.com/luxfi/node/releases
|
||||
GOARCH=$(go env GOARCH)
|
||||
GOOS=$(go env GOOS)
|
||||
DOWNLOAD_URL=https://github.com/luxfi/node/releases/download/v${VERSION}/node-linux-${GOARCH}-v${VERSION}.tar.gz
|
||||
DOWNLOAD_PATH=/tmp/node.tar.gz
|
||||
if [[ ${GOOS} == "darwin" ]]; then
|
||||
DOWNLOAD_URL=https://github.com/luxfi/node/releases/download/v${VERSION}/node-macos-v${VERSION}.zip
|
||||
DOWNLOAD_PATH=/tmp/node.zip
|
||||
fi
|
||||
|
||||
rm -f ${DOWNLOAD_PATH}
|
||||
rm -rf "/tmp/node-v${VERSION}"
|
||||
rm -rf /tmp/node-build
|
||||
|
||||
echo "downloading node ${VERSION} at ${DOWNLOAD_URL}"
|
||||
curl -L "${DOWNLOAD_URL}" -o "${DOWNLOAD_PATH}"
|
||||
|
||||
echo "extracting downloaded node"
|
||||
if [[ ${GOOS} == "linux" ]]; then
|
||||
tar xzvf ${DOWNLOAD_PATH} -C /tmp
|
||||
elif [[ ${GOOS} == "darwin" ]]; then
|
||||
unzip ${DOWNLOAD_PATH} -d /tmp/node-build
|
||||
mv /tmp/node-build/build "/tmp/node-v${VERSION}"
|
||||
fi
|
||||
find "/tmp/node-v${VERSION}"
|
||||
|
||||
# Sourcing constants.sh ensures that the necessary CGO flags are set to
|
||||
# build the portable version of BLST. Without this, ginkgo may fail to
|
||||
# build the test binary if run on a host (e.g. github worker) that lacks
|
||||
# the instructions to build non-portable BLST.
|
||||
source ./scripts/constants.sh
|
||||
|
||||
#################################
|
||||
# By default, it runs all upgrade test cases!
|
||||
echo "running upgrade tests against the local cluster with ${LUXD_PATH}"
|
||||
./bin/ginkgo -v ./tests/upgrade -- \
|
||||
--node-path="/tmp/node-v${VERSION}/node" \
|
||||
--node-path-to-upgrade-to="${LUXD_PATH}"
|
||||
Reference in New Issue
Block a user