github.com/evdatsion/aphelion-dpos-bft@v0.32.1/networks/remote/integration.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # XXX: this script is intended to be run from a fresh Digital Ocean droplet
     4  
     5  # NOTE: you must set this manually now
     6  echo "export DO_API_TOKEN=\"yourToken\"" >> ~/.profile
     7  
     8  sudo apt-get update -y
     9  sudo apt-get upgrade -y
    10  sudo apt-get install -y jq unzip python-pip software-properties-common make
    11  
    12  # get and unpack golang
    13  curl -O https://storage.googleapis.com/golang/go1.12.linux-amd64.tar.gz
    14  tar -xvf go1.12.linux-amd64.tar.gz
    15  
    16  ## move binary and add to path
    17  mv go /usr/local
    18  echo "export PATH=\$PATH:/usr/local/go/bin" >> ~/.profile
    19  
    20  ## create the goApps directory, set GOPATH, and put it on PATH
    21  mkdir goApps
    22  echo "export GOPATH=/root/goApps" >> ~/.profile
    23  echo "export PATH=\$PATH:\$GOPATH/bin" >> ~/.profile
    24  
    25  source ~/.profile
    26  
    27  ## get the code and move into repo
    28  REPO=github.com/evdatsion/aphelion-dpos-bft
    29  go get $REPO
    30  cd $GOPATH/src/$REPO
    31  
    32  ## build
    33  make get_tools
    34  make build
    35  
    36  # generate an ssh key
    37  ssh-keygen -f $HOME/.ssh/id_rsa -t rsa -N ''
    38  echo "export SSH_KEY_FILE=\"\$HOME/.ssh/id_rsa.pub\"" >> ~/.profile
    39  source ~/.profile
    40  
    41  # install terraform
    42  wget https://releases.hashicorp.com/terraform/0.11.7/terraform_0.11.7_linux_amd64.zip
    43  unzip terraform_0.11.7_linux_amd64.zip -d /usr/bin/
    44  
    45  # install ansible
    46  sudo apt-get update -y
    47  sudo apt-add-repository ppa:ansible/ansible -y
    48  sudo apt-get update -y
    49  sudo apt-get install ansible -y
    50  
    51  # required by ansible
    52  pip install dopy
    53  
    54  # the next two commands are directory sensitive
    55  cd $GOPATH/src/github.com/evdatsion/aphelion-dpos-bft/networks/remote/terraform
    56  
    57  terraform init
    58  terraform apply -var DO_API_TOKEN="$DO_API_TOKEN" -var SSH_KEY_FILE="$SSH_KEY_FILE" -auto-approve
    59  
    60  # let the droplets boot
    61  sleep 60
    62  
    63  # get the IPs
    64  ip0=`terraform output -json public_ips | jq '.value[0]'`
    65  ip1=`terraform output -json public_ips | jq '.value[1]'`
    66  ip2=`terraform output -json public_ips | jq '.value[2]'`
    67  ip3=`terraform output -json public_ips | jq '.value[3]'`
    68  
    69  # to remove quotes
    70  strip() {
    71    opt=$1
    72    temp="${opt%\"}"
    73    temp="${temp#\"}"
    74    echo $temp
    75  }
    76  
    77  ip0=$(strip $ip0)
    78  ip1=$(strip $ip1)
    79  ip2=$(strip $ip2)
    80  ip3=$(strip $ip3)
    81  
    82  # all the ansible commands are also directory specific
    83  cd $GOPATH/src/github.com/evdatsion/aphelion-dpos-bft/networks/remote/ansible
    84  
    85  # create config dirs
    86  tendermint testnet
    87  
    88  ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
    89  ansible-playbook -i inventory/digital_ocean.py -l sentrynet config.yml -e BINARY=$GOPATH/src/github.com/evdatsion/aphelion-dpos-bft/build -e CONFIGDIR=$GOPATH/src/github.com/evdatsion/aphelion-dpos-bft/networks/remote/ansible/mytestnet
    90  
    91  sleep 10
    92  
    93  # get each nodes ID then populate the ansible file
    94  id0=`curl $ip0:26657/status | jq .result.node_info.id`
    95  id1=`curl $ip1:26657/status | jq .result.node_info.id`
    96  id2=`curl $ip2:26657/status | jq .result.node_info.id`
    97  id3=`curl $ip3:26657/status | jq .result.node_info.id`
    98  
    99  id0=$(strip $id0)
   100  id1=$(strip $id1)
   101  id2=$(strip $id2)
   102  id3=$(strip $id3)
   103  
   104  # remove file we'll re-write to with new info
   105  old_ansible_file=$GOPATH/src/github.com/evdatsion/aphelion-dpos-bft/networks/remote/ansible/roles/install/templates/systemd.service.j2
   106  rm $old_ansible_file
   107  
   108  # need to populate the `--p2p.persistent_peers` flag
   109  echo "[Unit]
   110  Description={{service}}
   111  Requires=network-online.target
   112  After=network-online.target
   113  
   114  [Service]
   115  Restart=on-failure
   116  User={{service}}
   117  Group={{service}}
   118  PermissionsStartOnly=true
   119  ExecStart=/usr/bin node --proxy_app=kvstore --p2p.persistent_peers=$id0@$ip0:26656,$id1@$ip1:26656,$id2@$ip2:26656,$id3@$ip3:26656
   120  ExecReload=/bin/kill -HUP \$MAINPID
   121  KillSignal=SIGTERM
   122  
   123  [Install]
   124  WantedBy=multi-user.target
   125  " >> $old_ansible_file
   126  
   127  # now, we can re-run the install command
   128  ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
   129  
   130  # and finally restart it all
   131  ansible-playbook -i inventory/digital_ocean.py -l sentrynet restart.yml
   132  
   133  echo "congratulations, your testnet is now running :)"