diff --git a/examples/telescope-authz/Makefile b/examples/telescope-authz/Makefile index b361309fc..243f4e795 100644 --- a/examples/telescope-authz/Makefile +++ b/examples/telescope-authz/Makefile @@ -2,14 +2,14 @@ HELM_NAME = telescope-starship HELM_FILE = configs/starship.yaml HELM_REPO = starship HELM_CHART = devnet -HELM_VERSION = v0.1.38 +HELM_VERSION = v0.1.47 ############################################################################### ### All commands ### ############################################################################### .PHONY: setup -setup: check setup-helm +setup: check .PHONY: test test: @@ -25,21 +25,13 @@ clean: stop clean-kind ### Helm commands ### ############################################################################### -.PHONY: setup-helm -setup-helm: - helm repo add $(HELM_REPO) https://cosmology-tech.github.io/starship/ - helm repo update - helm search repo $(HELM_REPO)/$(HELM_CHART) --version $(HELM_VERSION) - .PHONY: install install: - @echo "Installing the helm chart. This is going to take a while....." - @echo "You can check the status with \"kubectl get pods\", run in another terminal please" - helm install -f $(HELM_FILE) $(HELM_NAME) $(HELM_REPO)/$(HELM_CHART) --version $(HELM_VERSION) + bash $(CURDIR)/scripts/install.sh --config $(HELM_FILE) --version $(HELM_VERSION) --name $(HELM_NAME) .PHONY: debug debug: - helm install --dry-run --debug -f $(HELM_FILE) $(HELM_NAME) $(HELM_REPO)/$(HELM_CHART) + bash $(CURDIR)/scripts/install.sh --config $(HELM_FILE) --version $(HELM_VERSION) --name $(HELM_NAME) --dry-run .PHONY: delete delete: diff --git a/examples/telescope-authz/package.json b/examples/telescope-authz/package.json index 4dfcd2b3b..487f9a61a 100644 --- a/examples/telescope-authz/package.json +++ b/examples/telescope-authz/package.json @@ -11,7 +11,7 @@ "locks": "npm run locks:remove && npm run locks:create", "codegen": "node scripts/codegen.js", "e2e": "npm run e2e:test", - "e2e:deps": "make setup", + "e2e:deps": "make setup-deps", "e2e:kind": "make setup-kind", "e2e:start": "make install", "e2e:port": "make port-forward", @@ -89,4 +89,4 @@ "ts-jest": "^29.1.0", "typescript": "4.9.3" } -} \ No newline at end of file +} diff --git a/examples/telescope-authz/scripts/dev-setup.sh b/examples/telescope-authz/scripts/dev-setup.sh index 72beb97fc..b438895f0 100644 --- a/examples/telescope-authz/scripts/dev-setup.sh +++ b/examples/telescope-authz/scripts/dev-setup.sh @@ -13,6 +13,7 @@ function color() { # Define a function to install a binary on macOS install_macos() { case $1 in + docker) color red "Please install docker. Follow: https://docs.docker.com/desktop/install/mac-install/" ;; kubectl) brew install kubectl ;; helm) brew install helm ;; yq) brew install yq ;; @@ -25,10 +26,11 @@ install_linux() { color green "Installing $1 at ~/.local/bin, please add it to PATH" mkdir -p ~/.local/bin case $1 in + docker) color red "Please install docker. Follow: https://docs.docker.com/engine/install/ubuntu/" ;; 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 ;; helm) curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash ;; yq) curl -Lks "https://github.com/mikefarah/yq/releases/download/v4.33.3/yq_linux_amd64" > ~/.local/bin/yq && chmod +x ~/.local/bin/yq ;; - kind) curl -Lks https://kind.sigs.k8s.io/dl/v0.18.0/kind-linux-amd64 > ~/.local/bin/kind && chmod +x ~/.local/bin/kind ;; + kind) curl -Lks https://kind.sigs.k8s.io/dl/v0.18.1/kind-linux-amd64 > ~/.local/bin/kind && chmod +x ~/.local/bin/kind ;; esac } @@ -61,5 +63,7 @@ check_binary kubectl check_binary helm check_binary yq check_binary kind +check_binary docker color green "All binaries are installed" + diff --git a/examples/telescope-authz/scripts/install.sh b/examples/telescope-authz/scripts/install.sh new file mode 100644 index 000000000..101a14dc7 --- /dev/null +++ b/examples/telescope-authz/scripts/install.sh @@ -0,0 +1,125 @@ +#!/bin/bash + +## Script used to install the helm chart for the devnet from a config file +## Usage: +## ./scripts/install.sh --coinfig +## Options: +## -c|--config: config file to use (default: config.yaml) +## -v|--version: helm chart version (default: 0.1.43) + +set -euo pipefail + +# read config file from args into variable +CONFIGFILE="config.yaml" + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +echo "Script dir: ${SCRIPT_DIR}" + +# default values +DRY_RUN="" +TIMEOUT="" +NAMESPACE="" +HELM_REPO="starship" +HELM_CHART="starship/devnet" +HELM_REPO_URL="https://cosmology-tech.github.io/starship/" +HELM_CHART_VERSION="0.1.43" + +# check_helm function verifies the helm binary is installed +function check_helm() { + if ! command -v helm &> /dev/null + then + echo "helm could not be found; please install it first!!!" + exit + fi +} + +# setup_helm function adds the helm repo and updates it +function setup_helm() { + if [ -d "$HELM_CHART" ]; then + echo "using local helm chart" + return + fi + helm repo add ${HELM_REPO} ${HELM_REPO_URL} + helm repo update + helm search repo ${HELM_CHART} --version ${HELM_CHART_VERSION} +} + +function set_helm_args() { + if [[ $TIMEOUT ]]; then + args="$args --timeout $TIMEOUT --wait --debug" + fi + if [[ $NAMESPACE ]]; then + args="$args --namespace $NAMESPACE --create-namespace" + fi + if [[ $DRY_RUN ]]; then + args="$args --dry-run --debug" + fi + num_chains=$(yq -r ".chains | length - 1" ${CONFIGFILE}) + if [[ $num_chains -lt 0 ]]; then + echo "No chains to parse: num: $num_chains" + return 0 + fi + for i in $(seq 0 $num_chains); do + chain=$(yq -r ".chains[$i].name" ${CONFIGFILE}) + scripts=$(yq -r ".chains[$i].scripts" ${CONFIGFILE}) + if [[ "$scripts" == "null" ]]; then + return 0 + fi + datadir="$(cd "$(dirname -- "${CONFIGFILE}")" >/dev/null; pwd -P)" + for script in $(yq -r ".chains[$i].scripts | keys | .[]" ${CONFIGFILE}); do + args="$args --set-file chains[$i].scripts.$script.data=$datadir/$(yq -r ".chains[$i].scripts.$script.file" ${CONFIGFILE})" + done + done +} + +function install_chart() { + args="" + set_helm_args + echo "name: ${HELM_NAME}, args: $args, chart: ${HELM_CHART}, version: ${HELM_CHART_VERSION}" + helm install ${HELM_NAME} ${HELM_CHART} --version ${HELM_CHART_VERSION} -f ${CONFIGFILE} $args +} + +while [ $# -gt 0 ]; do + case "$1" in + -c|--config) + CONFIGFILE="$2" + shift 2 # past argument=value + ;; + -v|--version) + HELM_CHART_VERSION="$2" + shift 2 # past argument + ;; + -t|--timeout) + TIMEOUT="$2" + shift 2 # past argument + ;; + -n|--name) + HELM_NAME="$2" + shift 2 # past argument + ;; + --namespace) + NAMESPACE="$2" + shift 2 # past argument + ;; + --chart) + HELM_CHART="$2" + shift 2 # past argument + ;; + --dry-run) + DRY_RUN=1 + shift # past argument + ;; + -*|--*) + echo "Unknown option $1" + exit 1 + ;; + *) + ;; + esac +done + +check_helm +setup_helm +install_chart + + diff --git a/examples/telescope-authz/scripts/port-forward.sh b/examples/telescope-authz/scripts/port-forward.sh index 1dc1eafb2..96db67a1a 100644 --- a/examples/telescope-authz/scripts/port-forward.sh +++ b/examples/telescope-authz/scripts/port-forward.sh @@ -21,12 +21,18 @@ function stop_port_forward() { # Default values CHAIN_RPC_PORT=26657 +CHAIN_COMETMOCK_PORT=22331 +CHAIN_GRPC_PORT=9090 CHAIN_LCD_PORT=1317 CHAIN_EXPOSER_PORT=8081 CHAIN_FAUCET_PORT=8000 +RELAYER_REST_PORT=3000 +RELAYER_EXPOSER_PORT=8081 EXPLORER_LCD_PORT=8080 REGISTRY_LCD_PORT=8080 REGISTRY_GRPC_PORT=9090 +MONITORING_PROMETHEUS_PORT=8080 +MONITORING_GRAFANA_PORT=8080 for i in "$@"; do case $i in @@ -48,23 +54,54 @@ stop_port_forward echo "Port forwarding for config ${CONFIGFILE}" echo "Port forwarding all chains" num_chains=$(yq -r ".chains | length - 1" ${CONFIGFILE}) -if [[ $num_chains -lt 0 ]]; then +if [[ $num_chains -gt -1 ]]; then + for i in $(seq 0 $num_chains); do + # derive chain pod name from chain id + # https://github.com/cosmology-tech/starship/blob/main/charts/devnet/templates/_helpers.tpl#L56 + chain=$(yq -r ".chains[$i].name" ${CONFIGFILE} ) + chain=${chain/_/"-"} + localrpc=$(yq -r ".chains[$i].ports.rpc" ${CONFIGFILE} ) + localgrpc=$(yq -r ".chains[$i].ports.grpc" ${CONFIGFILE} ) + locallcd=$(yq -r ".chains[$i].ports.rest" ${CONFIGFILE} ) + localexp=$(yq -r ".chains[$i].ports.exposer" ${CONFIGFILE}) + localfaucet=$(yq -r ".chains[$i].ports.faucet" ${CONFIGFILE}) + color yellow "chains: forwarded $chain" + if [[ $(yq -r ".chains[$i].cometmock.enabled" $CONFIGFILE) == "true" ]]; + then + [[ "$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 & + else + [[ "$localrpc" != "null" ]] && color yellow " rpc to http://localhost:$localrpc" && kubectl port-forward pods/$chain-genesis-0 $localrpc:$CHAIN_RPC_PORT > /dev/null 2>&1 & + fi + [[ "$localgrpc" != "null" ]] && color yellow " grpc to http://localhost:$localgrpc" && kubectl port-forward pods/$chain-genesis-0 $localgrpc:$CHAIN_GRPC_PORT > /dev/null 2>&1 & + [[ "$locallcd" != "null" ]] && color yellow " lcd to http://localhost:$locallcd" && kubectl port-forward pods/$chain-genesis-0 $locallcd:$CHAIN_LCD_PORT > /dev/null 2>&1 & + [[ "$localexp" != "null" ]] && color yellow " exposer to http://localhost:$localexp" && kubectl port-forward pods/$chain-genesis-0 $localexp:$CHAIN_EXPOSER_PORT > /dev/null 2>&1 & + [[ "$localfaucet" != "null" ]] && color yellow " faucet to http://localhost:$localfaucet" && kubectl port-forward pods/$chain-genesis-0 $localfaucet:$CHAIN_FAUCET_PORT > /dev/null 2>&1 & + sleep 1 + done +else echo "No chains to port-forward: num: $num_chains" - exit 1 fi -for i in $(seq 0 $num_chains); do - chain=$(yq -r ".chains[$i].name" ${CONFIGFILE} ) - localrpc=$(yq -r ".chains[$i].ports.rpc" ${CONFIGFILE} ) - locallcd=$(yq -r ".chains[$i].ports.rest" ${CONFIGFILE} ) - localexp=$(yq -r ".chains[$i].ports.exposer" ${CONFIGFILE}) - localfaucet=$(yq -r ".chains[$i].ports.faucet" ${CONFIGFILE}) - [[ "$localrpc" != "null" ]] && kubectl port-forward pods/$chain-genesis-0 $localrpc:$CHAIN_RPC_PORT > /dev/null 2>&1 & - [[ "$locallcd" != "null" ]] && kubectl port-forward pods/$chain-genesis-0 $locallcd:$CHAIN_LCD_PORT > /dev/null 2>&1 & - [[ "$localexp" != "null" ]] && kubectl port-forward pods/$chain-genesis-0 $localexp:$CHAIN_EXPOSER_PORT > /dev/null 2>&1 & - [[ "$localfaucet" != "null" ]] && kubectl port-forward pods/$chain-genesis-0 $localfaucet:$CHAIN_FAUCET_PORT > /dev/null 2>&1 & - sleep 1 - color yellow "chains: forwarded $chain lcd to http://localhost:$locallcd, rpc to http://localhost:$localrpc, faucet to http://localhost:$localfaucet" -done + + +echo "Port forward relayers" +num_relayers=$(yq -r ".relayers | length - 1" ${CONFIGFILE}) +if [[ $num_relayers -gt -1 ]]; then + for i in $(seq 0 $num_relayers); do + # derive chain pod name from chain id + # https://github.com/cosmology-tech/starship/blob/main/charts/devnet/templates/_helpers.tpl#L56 + relayer=$(yq -r ".relayers[$i].name" ${CONFIGFILE} ) + relayer=$(yq -r ".relayers[$i].type" ${CONFIGFILE} )-${relayer/_/"-"} + localrest=$(yq -r ".relayers[$i].ports.rest" ${CONFIGFILE} ) + localexposer=$(yq -r ".relayers[$i].ports.exposer" ${CONFIGFILE} ) + color yellow "relayers: forwarded $relayer" + [[ "$localrest" != "null" ]] && color yellow " rpc to http://localhost:$localrest" && kubectl port-forward pods/$relayer-0 $localrest:$RELAYER_REST_PORT > /dev/null 2>&1 & + [[ "$localexposer" != "null" ]] && color yellow " rpc to http://localhost:$localexposer" && kubectl port-forward pods/$relayer-0 $localexposer:$RELAYER_EXPOSER_PORT > /dev/null 2>&1 & + sleep 1 + done +else + echo "No relayer to port-forward: num: $num_relayers" +fi + echo "Port forward services" @@ -82,3 +119,14 @@ then sleep 1 color green "Open the explorer to get started.... http://localhost:8080" fi + +if [[ $(yq -r ".monitoring.enabled" $CONFIGFILE) == "true" ]]; +then + color yellow "monitoring port forward:" + localgrafana=$(yq -r ".monitoring.ports.grafana" ${CONFIGFILE}) + localprometheus=$(yq -r ".monitoring.ports.prometheus" ${CONFIGFILE}) + [[ "$localgrafana" != "null" ]] && color yellow " grafana to http://localhost:$localgrafana" && kubectl port-forward service/grafana $localgrafana:$MONITORING_GRAFANA_PORT > /dev/null 2>&1 & + [[ "$localprometheus" != "null" ]] && color yellow " prometheus to http://localhost:$localprometheus" && kubectl port-forward service/prometheus-service $localprometheus:$MONITORING_PROMETHEUS_PORT > /dev/null 2>&1 & + sleep 1 +fi +