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