github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/scripts/testing-setup/setup_cluster.sh (about) 1 #!/bin/bash 2 3 terraform apply --auto-approve 4 5 echo -n "Sleeping for 60s to allow ssh to start..." 6 sleep 60 7 echo "Done." 8 9 runRemote() { 10 local remote_addr args script 11 12 remote_addr=$1; shift 13 script=$1; shift 14 15 # generate eval-safe quoted version of current argument list 16 # shellcheck disable=SC2034 17 printf -v args '%q ' "$@" 18 19 # pass that through on the command line to bash -s 20 # note that $args is parsed remotely by /bin/sh, not by bash! 21 ssh -o LogLevel=ERROR -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" ubuntu@"${remote_addr}" "sudo ${script}" 22 # ssh -o LogLevel=ERROR -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" ubuntu@"$remote_addr" "sudo bash -s -x -- $args" < "$script" 23 } 24 25 all_nodes_public=() 26 # trunk-ignore(shellcheck/SC2312) 27 while IFS='' read -r line; do all_nodes_public+=("${line}"); done < <(terraform output -json | jq -r '.instance_public_dns.value | .[] ') 28 29 all_nodes_private=() 30 # trunk-ignore(shellcheck/SC2312) 31 while IFS='' read -r line; do all_nodes_private+=("${line}"); done < <(terraform output -json | jq -r '.instance_private_ips.value | .[] ') 32 33 first_node="${all_nodes_public[1]}" 34 echo "Connecting to: ubuntu@${first_node}" 35 runRemote "${first_node}" "/usr/local/bin/scripts/setup_node.sh" 36 runRemote "${first_node}" "touch /tmp/remote_peer_string" 37 38 while true ; do 39 # trunk-ignore(shellcheck/SC2312) 40 peer_string=$(curl -s "${first_node}/peer_token.html" | head -1) 41 if [[ "${peer_string}" == *"html"* ]]; then 42 sleep 5 43 else 44 break 45 fi 46 done 47 48 49 index=1 50 len_nodes=${#all_nodes_public[@]} 51 52 for i in "${!all_nodes_public[@]}"; do 53 if (( index >= len_nodes)); then 54 break 55 fi 56 57 this_node_public="${all_nodes_public[((i+1))]}" 58 # trunk-ignore(shellcheck/SC2034) 59 last_node_private="${all_nodes_private[((i))]}" 60 61 echo "Peer string: ${peer_string}" 62 63 echo "Connecting to: ubuntu@${this_node_public}" 64 runRemote "${this_node_public}" "echo \"${peer_string}\" > /tmp/remote_peer_string" 65 runRemote "${this_node_public}" "/usr/local/bin/scripts/setup_node.sh" 66 ((index=index+1)) 67 done