Browse Source

use host ip to set initial uri in metadata update for argus and colossus

Mokhtar Naamani 3 years ago
parent
commit
c8de48305a
2 changed files with 24 additions and 7 deletions
  1. 10 7
      storage-playground-config.sh
  2. 14 0
      tests/network-tests/get-host-ip.sh

+ 10 - 7
storage-playground-config.sh

@@ -11,6 +11,8 @@ cd $SCRIPT_PATH
 # Load the worker ids and SURIs as local variables only
 . .env
 
+HOST_IP=$(tests/network-tests/get-host-ip.sh)
+
 ## Colossus 1
 CLI=storage-node-v2/bin/run
 
@@ -21,10 +23,10 @@ ${CLI} operator:accept-invitation -w=${COLOSSUS_1_WORKER_ID} -i=${BUCKET_ID} --a
 ${CLI} leader:update-dynamic-bag-policy -n 1 -t Channel --accountUri ${COLOSSUS_1_ACCOUNT_URI}
 ${CLI} leader:update-data-fee -f 10 --accountUri ${COLOSSUS_1_ACCOUNT_URI} # Optionally - set some data fee per megabyte
 
-# This is only set initially to the name of the container to make it accessible by the distributors running as containers
-# in the same network. This should be updated to the "public" endpoint so the node is accessible from containers and
-# external applications like Atlas for example that depend on discovering the endpoint uri by querying the query-node.
-COLOSSUS_1_NODE_URI=${COLOSSUS_1_NODE_URI:="http://colossus-1:3333"}
+# The node uri should be an accessible endpoint from within a container as well as the host machine.
+# In production it would most likely be the reverse proxy endpoint. If not specified we
+# set it to the host machine address.
+COLOSSUS_1_NODE_URI=${COLOSSUS_1_NODE_URI:="http://${HOST_IP}:3333"}
 ${CLI} operator:set-metadata -w=${COLOSSUS_1_WORKER_ID} -i=${BUCKET_ID} -e="${COLOSSUS_1_NODE_URI}" --accountUri ${COLOSSUS_1_ACCOUNT_URI}
 
 echo "Colossus 1 BUCKET_ID=${BUCKET_ID}"
@@ -43,9 +45,10 @@ ${CLI} leader:update-dynamic-bag-policy -t Channel -p ${FAMILY_ID}:5
 ${CLI} leader:invite-bucket-operator -f ${FAMILY_ID} -B ${BUCKET_ID} -w ${DISTRIBUTOR_1_WORKER_ID}
 ${CLI} operator:accept-invitation -f ${FAMILY_ID} -B ${BUCKET_ID} -w ${DISTRIBUTOR_1_WORKER_ID}
 
-# This should be updated to the "public" endpoint so the node is accessible from containers and
-# external applications like Atlas for example that depend on discovering the endpoint uri by querying the query-node.
-DISTRIBUTOR_1_NODE_URI=${DISTRIBUTOR_1_NODE_URI:="http://localhost:3334"}
+# The node uri should be an accessible endpoint from within a container as well as the host machine.
+# In production it would most likely be the reverse proxy endpoint. If not specified we
+# set it to the host machine address.
+DISTRIBUTOR_1_NODE_URI=${DISTRIBUTOR_1_NODE_URI:="http://${HOST_IP}:3334"}
 ${CLI} operator:set-metadata -f ${FAMILY_ID} -B ${BUCKET_ID} -w ${DISTRIBUTOR_1_WORKER_ID} -e="${DISTRIBUTOR_1_NODE_URI}"
 
 echo "Distributor 1 FAMILY_ID=${FAMILY_ID}"

+ 14 - 0
tests/network-tests/get-host-ip.sh

@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+set -e
+
+if [[ "$OSTYPE" == "linux-gnu" ]]; then
+    # We could get the specific network address for the docker network with
+    #   docker network inspect --format='{{range .IPAM.Config}}{{.Gateway}}{{end}}' joystream_default
+    ip route | awk '/default/ {print $3}'
+elif [[ "$OSTYPE" == "darwin"* ]]; then
+    # try en0 if not set then en1 (Wired or Wireless)
+    ipconfig getifaddr en0 || ipconfig getifaddr en1
+fi
+
+# Some alternative approaches (cross platform)
+# ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'