From 93cca63e3f221bb024848a659ecadd9a5c4e027b Mon Sep 17 00:00:00 2001 From: Anmol Date: Fri, 7 Jun 2024 16:33:35 +0530 Subject: [PATCH] feature: starship 2 compatible (#26) --- .github/workflows/test.yaml | 16 ++--- README.md | 10 +-- action.yaml | 21 +----- install.sh | 2 +- port-forward.sh | 135 ++++++++++++++++++++++++++++++++++++ 5 files changed, 151 insertions(+), 33 deletions(-) create mode 100755 port-forward.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e23e570..be14e96 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -20,8 +20,8 @@ jobs: run: | cat < config.yaml chains: - - name: osmosis-1 - type: osmosis + - id: osmosis-1 + name: osmosis numValidators: 1 ports: rest: 1313 @@ -33,8 +33,8 @@ jobs: requests: cpu: "0.1" memory: "100M" - - name: wasmd - type: wasmd + - id: wasmd + name: wasmd numValidators: 1 ports: rpc: 26659 @@ -116,8 +116,8 @@ jobs: run: | cat < config.yaml chains: - - name: osmosis-1 - type: osmosis + - id: osmosis-1 + name: osmosis numValidators: 1 ports: rest: 1313 @@ -159,8 +159,8 @@ jobs: run: | cat < config.yaml chains: - - name: osmosis-1 - type: osmosis + - id: osmosis-1 + name: osmosis numValidators: 1 resources: cpu: "0.2" diff --git a/README.md b/README.md index 020c78c..0a6fccc 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ For more information on inputs, see the [API Documentation](https://developer.gi - `values`: Required, config for helm chart for starship devnet inputs - `port-forward`: Optional, toggle to perform local port-forwarding, based on the `values.yaml` (default: `false`) - `kubeconfig`: Optional, Kubeconfig for remote cluster, if set, will be used instead of creating local kind cluster -- `version`: Optional, version of devnet chart from starship (default: `0.1.4`) +- `version`: Optional, version of devnet chart from starship (default: `0.2.3`) - `repo`: Optional, Helm repo to fetch the chart from (default: https://cosmology-tech.github.io/starship) - `name`: Optional, Release name for the helm chart deployment (default: `starship-devnet`) - `namespace`: Optional, Kubernetes namespace to which helm charts will be deployed. If not found, namespace will be created. (default: `ci-${{ github.repository }}-${{ github.workflow }}-${{ github.ref }}`) @@ -45,8 +45,8 @@ jobs: with: values: | chains: - - name: osmosis-1 - type: osmosis + - id: osmosis-1 + name: osmosis numValidators: 1 ports: rest: 1313 @@ -58,8 +58,8 @@ jobs: requests: cpu: "0.1" memory: "100M" - - name: wasmd - type: wasmd + - id: wasmd + name: wasmd numValidators: 1 ports: rpc: 26659 diff --git a/action.yaml b/action.yaml index 9c37f8f..92e11bd 100644 --- a/action.yaml +++ b/action.yaml @@ -19,7 +19,7 @@ inputs: version: description: "Version of devnet chart (default: 0.1.45)" required: false - default: "0.1.45" + default: "0.2.3" chart: description: "Name of the help chart to use. Recommended: use default (default: starship/devnet)" required: false @@ -40,10 +40,6 @@ inputs: description: "Timeout for helm install (default: 10m)" required: false default: "10m" - cli-version: - description: "Starship cli version or commit (default: b8b22acaf5531da75a92e7cde579d365e4a8be86)" - required: false - default: "b8b22acaf5531da75a92e7cde579d365e4a8be86" outputs: namespace: @@ -74,19 +70,6 @@ runs: with: version: v1.28.0 - - name: Setup Golang - uses: actions/setup-go@v4 - with: - go-version: "1.21" - check-latest: true - - - name: Install Starship cli - run: | - go install github.com/cosmology-tech/starship/cmd/starship@$CLI_VERSION - shell: bash - env: - CLI_VERSION: ${{ inputs.cli-version }} - - name: Setup kind cluster if: ${{ inputs.kubeconfig == '' }} uses: helm/kind-action@v1.8.0 @@ -176,7 +159,7 @@ runs: if: ${{ inputs.port-forward == 'true' }} run: | kubectl version - starship connect --config=$VALUES_FILE --namespace=$NAMESPACE --verbose 2>&1 & + ${{ github.action_path }}/port-forward.sh --config=$VALUES_FILE --namespace=$NAMESPACE shell: bash env: VALUES_FILE: ${{ inputs.name }}-values.yaml diff --git a/install.sh b/install.sh index 777b45a..24a3c74 100755 --- a/install.sh +++ b/install.sh @@ -21,7 +21,7 @@ TIMEOUT="" NAMESPACE="" HELM_NAME="starship" HELM_CHART="starship/devnet" -HELM_CHART_VERSION="0.1.43" +HELM_CHART_VERSION="0.2.3" function set_helm_args() { if [[ $TIMEOUT ]]; then diff --git a/port-forward.sh b/port-forward.sh new file mode 100755 index 0000000..8c520b1 --- /dev/null +++ b/port-forward.sh @@ -0,0 +1,135 @@ +#!/bin/bash + +set -euo pipefail + +function color() { + local color=$1 + shift + local black=30 red=31 green=32 yellow=33 blue=34 magenta=35 cyan=36 white=37 + local color_code=${!color:-$green} + printf "\033[%sm%s\033[0m\n" "$color_code" "$*" +} + +function stop_port_forward() { + color green "Trying to stop all port-forward, if any...." + PIDS=$(ps -ef | grep -i -e 'kubectl port-forward' | grep -v 'grep' | cat | awk '{print $2}') || true + for p in $PIDS; do + kill -15 $p + done + sleep 2 +} + +# 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 + -c=*|--config=*) + CONFIGFILE="${i#*=}" + shift # past argument=value + ;; + -n=*|--namespace=*) + NAMESPACE="${i#*=}" + shift # past argument=value + ;; + -*|--*) + echo "Unknown option $i" + exit 1 + ;; + *) + ;; + esac +done + +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 -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].id" ${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 --namespace $NAMESPACE > /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 --namespace $NAMESPACE > /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 --namespace $NAMESPACE > /dev/null 2>&1 & + [[ "$locallcd" != "null" ]] && color yellow " lcd to http://localhost:$locallcd" && kubectl port-forward pods/$chain-genesis-0 $locallcd:$CHAIN_LCD_PORT --namespace $NAMESPACE > /dev/null 2>&1 & + [[ "$localexp" != "null" ]] && color yellow " exposer to http://localhost:$localexp" && kubectl port-forward pods/$chain-genesis-0 $localexp:$CHAIN_EXPOSER_PORT --namespace $NAMESPACE > /dev/null 2>&1 & + [[ "$localfaucet" != "null" ]] && color yellow " faucet to http://localhost:$localfaucet" && kubectl port-forward pods/$chain-genesis-0 $localfaucet:$CHAIN_FAUCET_PORT --namespace $NAMESPACE > /dev/null 2>&1 & + sleep 1 + done +else + echo "No chains to port-forward: num: $num_chains" +fi + + +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 --namespace $NAMESPACE > /dev/null 2>&1 & + [[ "$localexposer" != "null" ]] && color yellow " rpc to http://localhost:$localexposer" && kubectl port-forward pods/$relayer-0 $localexposer:$RELAYER_EXPOSER_PORT --namespace $NAMESPACE > /dev/null 2>&1 & + sleep 1 + done +else + echo "No relayer to port-forward: num: $num_relayers" +fi + + +echo "Port forward services" + +if [[ $(yq -r ".registry.enabled" $CONFIGFILE) == "true" ]]; +then + kubectl port-forward service/registry 8081:$REGISTRY_LCD_PORT --namespace $NAMESPACE > /dev/null 2>&1 & + kubectl port-forward service/registry 9091:$REGISTRY_GRPC_PORT --namespace $NAMESPACE > /dev/null 2>&1 & + sleep 1 + color yellow "registry: forwarded registry lcd to grpc http://localhost:8081, to http://localhost:9091" +fi + +if [[ $(yq -r ".explorer.enabled" $CONFIGFILE) == "true" ]]; +then + kubectl port-forward service/explorer 8080:$EXPLORER_LCD_PORT --namespace $NAMESPACE > /dev/null 2>&1 & + 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 --namespace $NAMESPACE > /dev/null 2>&1 & + [[ "$localprometheus" != "null" ]] && color yellow " prometheus to http://localhost:$localprometheus" && kubectl port-forward service/prometheus-service $localprometheus:$MONITORING_PROMETHEUS_PORT --namespace $NAMESPACE > /dev/null 2>&1 & + sleep 1 +fi