Skip to content

Commit ebed14f

Browse files
authored
Merge pull request #110 from Agoric/mk/helper-scripts
chore(multichain-testing): add helper scripts
2 parents 2497682 + e33f237 commit ebed14f

File tree

5 files changed

+432
-0
lines changed

5 files changed

+432
-0
lines changed

e2e-testing/scripts/dev-setup.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
## see https://github.com/cosmology-tech/starship/blob/b7dc499ee0114a0d5035708d7a92ca37fbdaf257/examples/getting-started/scripts/dev-setup.sh
4+
5+
set -euo pipefail
6+
7+
function color() {
8+
local color=$1
9+
shift
10+
local black=30 red=31 green=32 yellow=33 blue=34 magenta=35 cyan=36 white=37
11+
local color_code=${!color:-$green}
12+
printf "\033[%sm%s\033[0m\n" "$color_code" "$*"
13+
}
14+
15+
# Define a function to install a binary on macOS
16+
install_macos() {
17+
case $1 in
18+
kubectl) brew install kubectl ;;
19+
helm) brew install helm ;;
20+
yq) brew install yq ;;
21+
kind) brew install kind ;;
22+
esac
23+
}
24+
25+
# Define a function to install a binary on Linux
26+
install_linux() {
27+
color green "Installing $1 at ~/.local/bin, please add it to PATH"
28+
mkdir -p ~/.local/bin
29+
case $1 in
30+
kubectl) curl -Lks "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" > ~/.local/bin/kubectl && chmod +x ~/.local/bin/kubectl ;;
31+
helm) curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash ;;
32+
yq) curl -Lks "https://github.com/mikefarah/yq/releases/download/v4.33.3/yq_linux_amd64" > ~/.local/bin/yq && chmod +x ~/.local/bin/yq ;;
33+
kind) curl -Lks https://kind.sigs.k8s.io/dl/v0.18.1/kind-linux-amd64 > ~/.local/bin/kind && chmod +x ~/.local/bin/kind ;;
34+
esac
35+
}
36+
37+
# Define a function to install a binary
38+
install_binary() {
39+
if [[ $(uname -s) == "Darwin" ]]; then
40+
install_macos $1
41+
else
42+
install_linux $1
43+
fi
44+
}
45+
46+
# Define a function to check for the presence of a binary
47+
check_binary() {
48+
if ! command -v $1 &> /dev/null; then
49+
echo "$1 is not installed"
50+
install_binary $1
51+
if ! command -v $1 &> /dev/null; then
52+
color red "Installation of $1 failed, exiting..."
53+
color red "Please install $1 manually, then run me again to verify the installation"
54+
exit 1
55+
fi
56+
fi
57+
}
58+
59+
# Check the binaries
60+
check_binary kubectl
61+
check_binary helm
62+
check_binary yq
63+
check_binary kind
64+
65+
color green "All binaries are installed"

e2e-testing/scripts/install.sh

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/bin/bash
2+
3+
## see https://github.com/cosmology-tech/starship/blob/7d63c4678a345789d8331dde7654f67953c5cc2b/examples/getting-started/scripts/install.sh
4+
5+
## Script used to install the helm chart for the devnet from a config file
6+
## Usage:
7+
## ./scripts/install.sh --coinfig <config_file>
8+
## Options:
9+
## -c|--config: config file to use (default: config.yaml)
10+
## -v|--version: helm chart version (default: 0.1.43)
11+
12+
set -euo pipefail
13+
14+
# read config file from args into variable
15+
CONFIGFILE="config.yaml"
16+
17+
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
18+
echo "Script dir: ${SCRIPT_DIR}"
19+
20+
# default values
21+
DRY_RUN=""
22+
TIMEOUT=""
23+
NAMESPACE=""
24+
HELM_REPO="starship"
25+
HELM_CHART="starship/devnet"
26+
HELM_REPO_URL="https://hyperweb-io.github.io/starship/"
27+
HELM_CHART_VERSION="0.2.8"
28+
HELM_NAME="agoric-multichain-testing"
29+
30+
# check_helm function verifies the helm binary is installed
31+
function check_helm() {
32+
if ! command -v helm &> /dev/null; then
33+
echo "helm could not be found; please install it first!!!"
34+
exit
35+
fi
36+
}
37+
38+
# setup_helm function adds the helm repo and updates it
39+
function setup_helm() {
40+
if [ -d "$HELM_CHART" ]; then
41+
echo "using local helm chart"
42+
return
43+
fi
44+
helm repo add ${HELM_REPO} ${HELM_REPO_URL}
45+
helm repo update
46+
helm search repo ${HELM_CHART} --version ${HELM_CHART_VERSION}
47+
}
48+
49+
function set_helm_args() {
50+
if [[ $TIMEOUT ]]; then
51+
args="$args --timeout $TIMEOUT --wait --debug"
52+
fi
53+
if [[ $NAMESPACE ]]; then
54+
args="$args --namespace $NAMESPACE --create-namespace"
55+
fi
56+
if [[ $DRY_RUN ]]; then
57+
args="$args --dry-run --debug"
58+
fi
59+
num_chains=$(yq -r ".chains | length - 1" ${CONFIGFILE})
60+
if [[ $num_chains -lt 0 ]]; then
61+
echo "No chains to parse: num: $num_chains"
62+
return 0
63+
fi
64+
for i in $(seq 0 $num_chains); do
65+
scripts=$(yq -r ".chains[$i].scripts" ${CONFIGFILE})
66+
if [[ "$scripts" == "null" ]]; then
67+
return 0
68+
fi
69+
datadir="$(
70+
cd "$(dirname -- "${CONFIGFILE}")" > /dev/null
71+
pwd -P
72+
)"
73+
for script in $(yq -r ".chains[$i].scripts | keys | .[]" ${CONFIGFILE}); do
74+
args="$args --set-file chains[$i].scripts.$script.data=$datadir/$(yq -r ".chains[$i].scripts.$script.file" ${CONFIGFILE})"
75+
done
76+
done
77+
}
78+
79+
function install_chart() {
80+
args=""
81+
set_helm_args
82+
echo "name: ${HELM_NAME}, args: $args, chart: ${HELM_CHART}, version: ${HELM_CHART_VERSION}"
83+
helm install ${HELM_NAME} ${HELM_CHART} --version ${HELM_CHART_VERSION} -f ${CONFIGFILE} $args
84+
}
85+
86+
while [ $# -gt 0 ]; do
87+
case "$1" in
88+
-c | --config)
89+
CONFIGFILE="$2"
90+
shift 2 # past argument=value
91+
;;
92+
-v | --version)
93+
HELM_CHART_VERSION="$2"
94+
shift 2 # past argument
95+
;;
96+
-t | --timeout)
97+
TIMEOUT="$2"
98+
shift 2 # past argument
99+
;;
100+
-n | --name)
101+
HELM_NAME="$2"
102+
shift 2 # past argument
103+
;;
104+
--namespace)
105+
NAMESPACE="$2"
106+
shift 2 # past argument
107+
;;
108+
--chart)
109+
HELM_CHART="$2"
110+
shift 2 # past argument
111+
;;
112+
--dry-run)
113+
DRY_RUN=1
114+
shift # past argument
115+
;;
116+
-)
117+
echo "Unknown option $1"
118+
exit 1
119+
;;
120+
*) ;;
121+
122+
esac
123+
done
124+
125+
check_helm
126+
setup_helm
127+
install_chart

e2e-testing/scripts/pod-readiness.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { execa } from 'execa';
2+
import { sleep } from '../tools/sleep.ts';
3+
4+
const checkPodsReadiness = async (): Promise<boolean> => {
5+
const { stdout } = await execa('kubectl', ['get', 'pods']);
6+
console.clear();
7+
console.log('Current pod status:');
8+
console.log(stdout);
9+
10+
const lines = stdout.split('\n').slice(1); // Skip the header line
11+
return (
12+
lines.length > 0 &&
13+
lines.every(line => {
14+
const [, ready] = line.split(/\s+/);
15+
const [readyCount, totalCount] = ready.split('/');
16+
return readyCount === totalCount;
17+
})
18+
);
19+
};
20+
21+
const main = async () => {
22+
console.log('Starting pod readiness check...');
23+
for (;;) {
24+
const allReady = await checkPodsReadiness();
25+
if (allReady) {
26+
console.log('All pods are ready!');
27+
process.exit(0);
28+
}
29+
await sleep(2 * 1_000);
30+
}
31+
};
32+
33+
main().catch(error => {
34+
console.error('An error occurred:', error);
35+
process.exit(1);
36+
});

e2e-testing/scripts/port-forward.sh

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/bin/bash
2+
3+
## see https://github.com/cosmology-tech/starship/blob/cb14bbc345c0a91a02feb9204ce8abef8d7b0a49/starship/scripts/port-forward.sh
4+
5+
set -euo pipefail
6+
7+
function color() {
8+
local color=$1
9+
shift
10+
local black=30 red=31 green=32 yellow=33 blue=34 magenta=35 cyan=36 white=37
11+
local color_code=${!color:-$green}
12+
printf "\033[%sm%s\033[0m\n" "$color_code" "$*"
13+
}
14+
15+
function stop_port_forward() {
16+
color green "Trying to stop all port-forward, if any...."
17+
PIDS=$(ps -ef | grep -i -e 'kubectl port-forward' | grep -v 'grep' | cat | awk '{print $2}') || true
18+
for p in $PIDS; do
19+
kill -15 $p
20+
done
21+
sleep 2
22+
}
23+
24+
# Default values
25+
CHAIN_RPC_PORT=26657
26+
CHAIN_COMETMOCK_PORT=22331
27+
CHAIN_GRPC_PORT=9090
28+
CHAIN_LCD_PORT=1317
29+
CHAIN_EXPOSER_PORT=8081
30+
CHAIN_FAUCET_PORT=8000
31+
RELAYER_REST_PORT=3000
32+
RELAYER_EXPOSER_PORT=8081
33+
EXPLORER_LCD_PORT=8080
34+
REGISTRY_LCD_PORT=8080
35+
REGISTRY_GRPC_PORT=9090
36+
MONITORING_PROMETHEUS_PORT=8080
37+
MONITORING_GRAFANA_PORT=8080
38+
39+
for i in "$@"; do
40+
case $i in
41+
-c=* | --config=*)
42+
CONFIGFILE="${i#*=}"
43+
shift # past argument=value
44+
;;
45+
-* | --*)
46+
echo "Unknown option $i"
47+
exit 1
48+
;;
49+
*) ;;
50+
51+
esac
52+
done
53+
54+
stop_port_forward
55+
56+
echo "Port forwarding for config ${CONFIGFILE}"
57+
echo "Port forwarding all chains"
58+
num_chains=$(yq -r ".chains | length - 1" ${CONFIGFILE})
59+
if [[ $num_chains -gt -1 ]]; then
60+
for i in $(seq 0 $num_chains); do
61+
# derive chain pod name from chain id
62+
# https://github.com/cosmology-tech/starship/blob/main/charts/devnet/templates/_helpers.tpl#L56
63+
chain=$(yq -r ".chains[$i].id" ${CONFIGFILE})
64+
chain=${chain/_/"-"}
65+
localrpc=$(yq -r ".chains[$i].ports.rpc" ${CONFIGFILE})
66+
localgrpc=$(yq -r ".chains[$i].ports.grpc" ${CONFIGFILE})
67+
locallcd=$(yq -r ".chains[$i].ports.rest" ${CONFIGFILE})
68+
localexp=$(yq -r ".chains[$i].ports.exposer" ${CONFIGFILE})
69+
localfaucet=$(yq -r ".chains[$i].ports.faucet" ${CONFIGFILE})
70+
color yellow "chains: forwarded $chain"
71+
if [[ $(yq -r ".chains[$i].cometmock.enabled" $CONFIGFILE) == "true" ]]; then
72+
[[ "$localrpc" != "null" ]] && color yellow " cometmock rpc to http://localhost:$localrpc" && kubectl port-forward pods/$chain-cometmock-0 $localrpc:$CHAIN_COMETMOCK_PORT > /dev/null 2>&1 &
73+
else
74+
[[ "$localrpc" != "null" ]] && color yellow " rpc to http://localhost:$localrpc" && kubectl port-forward pods/$chain-genesis-0 $localrpc:$CHAIN_RPC_PORT > /dev/null 2>&1 &
75+
fi
76+
[[ "$localgrpc" != "null" ]] && color yellow " grpc to http://localhost:$localgrpc" && kubectl port-forward pods/$chain-genesis-0 $localgrpc:$CHAIN_GRPC_PORT > /dev/null 2>&1 &
77+
[[ "$locallcd" != "null" ]] && color yellow " lcd to http://localhost:$locallcd" && kubectl port-forward pods/$chain-genesis-0 $locallcd:$CHAIN_LCD_PORT > /dev/null 2>&1 &
78+
[[ "$localexp" != "null" ]] && color yellow " exposer to http://localhost:$localexp" && kubectl port-forward pods/$chain-genesis-0 $localexp:$CHAIN_EXPOSER_PORT > /dev/null 2>&1 &
79+
[[ "$localfaucet" != "null" ]] && color yellow " faucet to http://localhost:$localfaucet" && kubectl port-forward pods/$chain-genesis-0 $localfaucet:$CHAIN_FAUCET_PORT > /dev/null 2>&1 &
80+
sleep 1
81+
done
82+
else
83+
echo "No chains to port-forward: num: $num_chains"
84+
fi
85+
86+
echo "Port forward relayers"
87+
num_relayers=$(yq -r ".relayers | length - 1" ${CONFIGFILE})
88+
if [[ $num_relayers -gt -1 ]]; then
89+
for i in $(seq 0 $num_relayers); do
90+
# derive chain pod name from chain id
91+
# https://github.com/cosmology-tech/starship/blob/main/charts/devnet/templates/_helpers.tpl#L56
92+
relayer=$(yq -r ".relayers[$i].name" ${CONFIGFILE})
93+
relayer=$(yq -r ".relayers[$i].type" ${CONFIGFILE})-${relayer/_/"-"}
94+
localrest=$(yq -r ".relayers[$i].ports.rest" ${CONFIGFILE})
95+
localexposer=$(yq -r ".relayers[$i].ports.exposer" ${CONFIGFILE})
96+
color yellow "relayers: forwarded $relayer"
97+
[[ "$localrest" != "null" ]] && color yellow " rpc to http://localhost:$localrest" && kubectl port-forward pods/$relayer-0 $localrest:$RELAYER_REST_PORT > /dev/null 2>&1 &
98+
[[ "$localexposer" != "null" ]] && color yellow " rpc to http://localhost:$localexposer" && kubectl port-forward pods/$relayer-0 $localexposer:$RELAYER_EXPOSER_PORT > /dev/null 2>&1 &
99+
sleep 1
100+
done
101+
else
102+
echo "No relayer to port-forward: num: $num_relayers"
103+
fi
104+
105+
echo "Port forward services"
106+
107+
if [[ $(yq -r ".registry.enabled" $CONFIGFILE) == "true" ]]; then
108+
kubectl port-forward service/registry 8081:$REGISTRY_LCD_PORT > /dev/null 2>&1 &
109+
kubectl port-forward service/registry 9091:$REGISTRY_GRPC_PORT > /dev/null 2>&1 &
110+
sleep 1
111+
color yellow "registry: forwarded registry lcd to grpc http://localhost:8081, to http://localhost:9091"
112+
fi
113+
114+
if [[ $(yq -r ".explorer.enabled" $CONFIGFILE) == "true" ]]; then
115+
kubectl port-forward service/explorer 8080:$EXPLORER_LCD_PORT > /dev/null 2>&1 &
116+
sleep 1
117+
color green "Open the explorer to get started.... http://localhost:8080"
118+
fi
119+
120+
if [[ $(yq -r ".monitoring.enabled" $CONFIGFILE) == "true" ]]; then
121+
color yellow "monitoring port forward:"
122+
localgrafana=$(yq -r ".monitoring.ports.grafana" ${CONFIGFILE})
123+
localprometheus=$(yq -r ".monitoring.ports.prometheus" ${CONFIGFILE})
124+
[[ "$localgrafana" != "null" ]] && color yellow " grafana to http://localhost:$localgrafana" && kubectl port-forward service/grafana $localgrafana:$MONITORING_GRAFANA_PORT > /dev/null 2>&1 &
125+
[[ "$localprometheus" != "null" ]] && color yellow " prometheus to http://localhost:$localprometheus" && kubectl port-forward service/prometheus-service $localprometheus:$MONITORING_PROMETHEUS_PORT > /dev/null 2>&1 &
126+
sleep 1
127+
fi

0 commit comments

Comments
 (0)