From 2d920ab3923dbbbb888f0bc4f9852e92293f1b94 Mon Sep 17 00:00:00 2001 From: Sebastian <379651+czarly@users.noreply.github.com> Date: Wed, 20 Mar 2024 06:06:18 +0100 Subject: [PATCH] get local updatreams too --- get-local-url.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ upstreams.sh | 16 ++++++++++++---- 2 files changed, 60 insertions(+), 4 deletions(-) create mode 100755 get-local-url.sh diff --git a/get-local-url.sh b/get-local-url.sh new file mode 100755 index 00000000..691939ef --- /dev/null +++ b/get-local-url.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +BASEPATH="$(dirname "$0")" +source $BASEPATH/.env + +blacklist=() +while IFS= read -r line; do + # Add each line to the array + blacklist+=("$line") +done < "$BASEPATH/path-blacklist.txt" + +# Parse Docker Compose file to get all services +services=$(yaml2json $BASEPATH/$1.yml | jq -r '.services | keys | .[]') + +for service in $services; do + + IFS=$'\t' read -r -a labels <<< $(yaml2json "$BASEPATH/$1.yml" | jq -r ".services[\"$service\"].labels | @tsv") + + for label in "${labels[@]}"; do + if [[ "$label" == *"stripprefix.prefixes"* ]]; then + path=$(echo "$label" | cut -d "=" -f 2) + break # Stop looping after finding the first match + fi + done + + include=true + for word in "${blacklist[@]}"; do + if echo "$path" | grep -qE "$word"; then + include=false + fi + done + + if $include; then + + for label in "${labels[@]}"; do + if [[ "$label" == *"loadbalancer.server.port"* ]]; then + port=$(echo "$label" | cut -d "=" -f 2) + echo "$service:$port" + #print("Value after '=' for the first string containing 'loadbalancer.server.port':", port) + break # Stop looping after finding the first match + fi + done + fi +done + +#echo "No service found with the specified labels." +exit 1 + diff --git a/upstreams.sh b/upstreams.sh index e5090790..8fba39a5 100755 --- a/upstreams.sh +++ b/upstreams.sh @@ -3,6 +3,8 @@ BASEPATH="$(dirname "$0")" source $BASEPATH/.env +$LOCAL=${1:-false} + IFS=':' read -ra parts <<< $COMPOSE_FILE blacklist=("drpc.yml" "base.yml" "rpc.yml" "monitoring.yml") @@ -37,14 +39,20 @@ for part in "${parts[@]}"; do done if $path_include; then - url="$DOMAIN$path" - #echo "$url" + + if [ "$LOCAL" = "true" ]; then + url=$(./get-local-name.sh "${part%.yml}") + export RPC_URL="http://$url" + export WS_URL="ws://$url" + else + url="$DOMAIN$path" + export RPC_URL="https://$url" + export WS_URL="wss://$url" + fi export ID=$(echo "$url" | sed -E 's/^rpc-(.*)\.stakesquid\.eu\/(.*)$/\1-\2/') export PROVIDER=${ORGANIZATION}-${ID} - export RPC_URL="https://$url" - export WS_URL="wss://$url" chain_id=$(curl --ipv4 -m 1 -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' $RPC_URL | jq -r '.result') chain_id_decimal=$((16#${chain_id#0x}))