Skip to content

Commit

Permalink
update getting started example with latest code (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol1696 authored Sep 20, 2023
1 parent b20428b commit 7d63c46
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 24 deletions.
15 changes: 2 additions & 13 deletions examples/getting-started/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TINY_FILE = configs/tiny-starship.yaml

HELM_REPO = starship
HELM_CHART = devnet
HELM_VERSION = v0.1.36
HELM_VERSION = v0.1.46

###############################################################################
### All commands ###
Expand All @@ -13,12 +13,6 @@ HELM_VERSION = v0.1.36
.PHONY: setup
setup: setup-deps setup-helm setup-kind

.PHONY: start
start: install port-forward

.PHONY: start-tiny
start-tiny: install-tiny port-forward

.PHONY: stop
stop: stop-forward delete

Expand All @@ -37,13 +31,8 @@ setup-deps:
### Helm Charts ###
###############################################################################

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)

install:
helm install -f $(FILE) $(NAME) $(HELM_REPO)/$(HELM_CHART) --version $(HELM_VERSION) --wait --debug --timeout 20m
bash $(CURDIR)/scripts/install.sh --config $(FILE) --name $(NAME) --version $(HELM_VERSION)

install-tiny:
$(MAKE) install FILE=$(TINY_FILE)
Expand Down
12 changes: 5 additions & 7 deletions examples/getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Simple self-contained example to get started with Starship.
```bash
cd getting-started/
# Install dependencies, install startship helm chart, create kind cluster
make setup
# Install the starship instance and run port-forward
make start
make install
# OR, if you are low on resources on local machine
make start-tiny
make install-tiny
# Once the pods are running, run
make port-forward
# Stop the cluster with
make stop
Expand Down Expand Up @@ -43,8 +43,6 @@ make setup-kind
## Deploy Starship
Run the following commands to deploy starship on the cluster.
```bash
make setup-helm
make install
# OR, if low on resources on local machine
make install-tiny
Expand Down
123 changes: 123 additions & 0 deletions examples/getting-started/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/bin/bash

## Script used to install the helm chart for the devnet from a config file
## Usage:
## ./scripts/install.sh --coinfig <config_file>
## 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
18 changes: 14 additions & 4 deletions examples/getting-started/scripts/port-forward.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ function stop_port_forward() {
for p in $PIDS; do
kill -15 $p
done
sleep 2
}

# Default values
CHAIN_RPC_PORT=26657
CHAIN_GRPC_PORT=9090
CHAIN_LCD_PORT=1317
CHAIN_EXPOSER_PORT=8081
CHAIN_FAUCET_PORT=8000
EXPLORER_LCD_PORT=8080
REGISTRY_LCD_PORT=8080
REGISTRY_GRPC_PORT=9090
Expand Down Expand Up @@ -51,15 +54,22 @@ if [[ $num_chains -lt 0 ]]; then
exit 1
fi
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})
[[ "$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=$(yq -r ".chains[$i].ports.faucet" ${CONFIGFILE})
color yellow "chains: forwarded $chain"
[[ "$localrpc" != "null" ]] && color yellow " rpc to http://localhost:$localrpc" && kubectl port-forward pods/$chain-genesis-0 $localrpc:$CHAIN_RPC_PORT > /dev/null 2>&1 &
[[ "$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
color yellow "chains: forwarded $chain lcd to http://localhost:$locallcd, rpc to http://localhost:$localrpc"
done

echo "Port forward services"
Expand Down

0 comments on commit 7d63c46

Please sign in to comment.