2022-05-17 09:42:04 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
stty sane # dont show backspace char during prompts
|
|
|
|
|
|
|
|
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
|
|
|
|
|
|
## Get Project Name
|
|
|
|
project=$1
|
|
|
|
if [[ -z "${project}" ]]; then
|
|
|
|
read -rp "Enter the name for the google cloud project (Ex. switchboard-oracle-cluster): " project
|
|
|
|
fi
|
|
|
|
project=$(echo "${project// /-}" | awk '{print tolower($0)}') # Replace spaces with dashes and make lower case
|
|
|
|
echo -e "project: $project"
|
|
|
|
|
|
|
|
envFile="$project.env"
|
|
|
|
if [ -f "$envFile" ]
|
|
|
|
then
|
|
|
|
envFile=$(realpath "${envFile}")
|
|
|
|
echo "env file: $envFile"
|
|
|
|
else
|
|
|
|
echo "failed to find env file: $envFile"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -a
|
|
|
|
. "$envFile"
|
|
|
|
set +a
|
|
|
|
|
|
|
|
prefix="kubernetes-"
|
|
|
|
outputPath=$(realpath "$prefix$project")
|
|
|
|
echo "output path: $outputPath";
|
|
|
|
|
|
|
|
mkdir -p "$outputPath"
|
|
|
|
cp -r "${script_dir}/helm/" "$outputPath/"
|
|
|
|
|
|
|
|
files=(
|
|
|
|
"$outputPath/dashboard.yaml"
|
|
|
|
"$outputPath/grafana-values.yaml"
|
|
|
|
"$outputPath/nginx-values.yaml"
|
|
|
|
"$outputPath/vmetrics-values.yaml"
|
|
|
|
"$outputPath/switchboard-oracle/values.yaml"
|
|
|
|
)
|
|
|
|
|
2022-06-14 09:59:26 -07:00
|
|
|
## Validate env variables
|
2022-05-17 09:42:04 -07:00
|
|
|
if [[ -z "${CLUSTER}" ]]; then
|
|
|
|
echo "failed to set CLUSTER"
|
|
|
|
exit 1
|
|
|
|
elif [[ "$CLUSTER" != "devnet" && "$CLUSTER" != "mainnet-beta" && "$CLUSTER" != "localnet" ]]; then
|
|
|
|
echo "invalid CLUSTER ($CLUSTER) - [devnet, mainnet-beta, or localnet]"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [[ -z "${RPC_URL}" ]]; then
|
|
|
|
echo "failed to set RPC_URL"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [[ -z "${WS_URL}" ]]; then
|
|
|
|
WS_URL=""
|
|
|
|
fi
|
|
|
|
if [[ -z "${BACKUP_MAINNET_RPC}" ]]; then
|
2022-06-14 09:59:26 -07:00
|
|
|
BACKUP_MAINNET_RPC="https://solana-api.projectserum.com"
|
2022-05-17 09:42:04 -07:00
|
|
|
fi
|
|
|
|
if [[ -z "${ORACLE_KEY}" ]]; then
|
|
|
|
echo "failed to set ORACLE_KEY"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [[ -z "${HEARTBEAT_INTERVAL}" ]]; then
|
|
|
|
HEARTBEAT_INTERVAL="15"
|
|
|
|
fi
|
2022-06-14 09:59:26 -07:00
|
|
|
if [[ -z "${UNWRAP_STAKE_THRESHOLD}" ]]; then
|
|
|
|
UNWRAP_STAKE_THRESHOLD=""
|
|
|
|
fi
|
2022-05-17 09:42:04 -07:00
|
|
|
if [[ -z "${GOOGLE_PAYER_SECRET_PATH}" ]]; then
|
|
|
|
echo "failed to set GOOGLE_PAYER_SECRET_PATH"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [[ -z "${GCP_CONFIG_BUCKET}" ]]; then
|
|
|
|
GCP_CONFIG_BUCKET="oracle-configs:configs.json"
|
|
|
|
fi
|
|
|
|
if [[ -z "${SERVICE_ACCOUNT_BASE64}" ]]; then
|
|
|
|
echo "failed to set SERVICE_ACCOUNT_BASE64"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [[ -z "${EXTERNAL_IP}" ]]; then
|
|
|
|
echo "failed to set EXTERNAL_IP"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [[ -z "${PAGERDUTY_EVENT_KEY}" ]]; then
|
|
|
|
PAGERDUTY_EVENT_KEY=""
|
|
|
|
fi
|
|
|
|
if [[ -z "${GRAFANA_HOSTNAME}" ]]; then
|
|
|
|
echo "failed to set GRAFANA_HOSTNAME"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [[ -z "${GRAFANA_ADMIN_PASSWORD}" ]]; then
|
2022-05-24 15:17:11 -07:00
|
|
|
GRAFANA_ADMIN_PASSWORD="${GRAFANA_ADMIN_PASSWORD:-Sbv2K8sPassword123@}"
|
2022-05-17 09:42:04 -07:00
|
|
|
fi
|
|
|
|
if [[ -z "${GRAFANA_TLS_CRT}" ]]; then
|
|
|
|
echo "failed to set GRAFANA_TLS_CRT"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [[ -z "${GRAFANA_TLS_KEY}" ]]; then
|
|
|
|
echo "failed to set GRAFANA_TLS_KEY"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [[ -z "${METRICS_EXPORTER}" ]]; then
|
|
|
|
METRICS_EXPORTER="${METRICS_EXPORTER:-prometheus}"
|
|
|
|
elif [[ "$METRICS_EXPORTER" != "prometheus" && "$CLUSTER" != "gcp" && "$CLUSTER" != "opentelemetry-collector" ]]; then
|
|
|
|
echo "invalid METRICS_EXPORTER ($METRICS_EXPORTER) - [prometheus, gcp, or opentelemetry-collector]"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-06-14 09:59:26 -07:00
|
|
|
if [[ -z "${SBV2_NODE_IMAGE}" ]]; then
|
|
|
|
SBV2_NODE_IMAGE="${SBV2_NODE_IMAGE:-dev-v2-06-08-22}"
|
|
|
|
fi
|
2022-05-17 09:42:04 -07:00
|
|
|
|
2022-06-14 09:59:26 -07:00
|
|
|
## Substitute ENV values
|
2022-05-17 09:42:04 -07:00
|
|
|
for f in "${files[@]}"; do
|
2022-06-14 09:59:26 -07:00
|
|
|
UNWRAP_STAKE_THRESHOLD="$UNWRAP_STAKE_THRESHOLD" \
|
|
|
|
NONCE_QUEUE_SIZE="$NONCE_QUEUE_SIZE" \
|
|
|
|
NONCE_FLAG="$NONCE_FLAG" \
|
2022-05-17 09:42:04 -07:00
|
|
|
PAGERDUTY_EVENT_KEY="$PAGERDUTY_EVENT_KEY" \
|
|
|
|
METRICS_EXPORTER="$METRICS_EXPORTER" \
|
2022-06-14 09:59:26 -07:00
|
|
|
GRAFANA_ADMIN_PASSWORD="$GRAFANA_ADMIN_PASSWORD" \
|
|
|
|
HEARTBEAT_INTERVAL="$HEARTBEAT_INTERVAL" \
|
|
|
|
SBV2_NODE_IMAGE="$SBV2_NODE_IMAGE" \
|
|
|
|
WS_URL="$WS_URL" \
|
|
|
|
GCP_CONFIG_BUCKET="$GCP_CONFIG_BUCKET" \
|
|
|
|
BACKUP_MAINNET_RPC="$BACKUP_MAINNET_RPC" \
|
|
|
|
envsubst '$UNWRAP_STAKE_THRESHOLD $CLUSTER $RPC_URL $WS_URL $BACKUP_MAINNET_RPC $ORACLE_KEY $HEARTBEAT_INTERVAL $GOOGLE_PAYER_SECRET_PATH $GCP_CONFIG_BUCKET $SERVICE_ACCOUNT_BASE64 $EXTERNAL_IP $PAGERDUTY_EVENT_KEY $GRAFANA_HOSTNAME $GRAFANA_ADMIN_PASSWORD $GRAFANA_TLS_CRT $GRAFANA_TLS_KEY $METRICS_EXPORTER $SBV2_NODE_IMAGE' < "$f" \
|
2022-05-17 09:42:04 -07:00
|
|
|
| tee "$outputPath/tmp.txt" \
|
|
|
|
> /dev/null ;
|
|
|
|
cat "$outputPath/tmp.txt" > "$f";
|
|
|
|
done
|
|
|
|
|
|
|
|
rm "$outputPath/tmp.txt"
|
|
|
|
|
|
|
|
exit 0
|