github.com/DFWallet/tendermint-cosmos@v0.0.2/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://dl.google.com/go/go1.15.4.linux-amd64.tar.gz
    14  tar -xvf go1.15.4.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  # **turn on the go module, default is auto. The value is off, if tendermint source code
    25  #is downloaded under $GOPATH/src directory
    26  echo "export GO111MODULE=on" >> ~/.profile
    27  
    28  source ~/.profile
    29  
    30  mkdir -p $GOPATH/src/github.com/tendermint
    31  cd $GOPATH/src/github.com/tendermint
    32  # ** use git clone instead of go get.
    33  # once go module is on, go get will download source code to
    34  # specific version directory under $GOPATH/pkg/mod the make
    35  # script will not work
    36  git clone https://github.com/DFWallet/tendermint-cosmos.git
    37  cd tendermint
    38  ## build
    39  make tools
    40  make build
    41  #** need to install the package, otherwise terdermint testnet will not execute
    42  make install
    43  
    44  # generate an ssh key
    45  ssh-keygen -f $HOME/.ssh/id_rsa -t rsa -N ''
    46  echo "export SSH_KEY_FILE=\"\$HOME/.ssh/id_rsa.pub\"" >> ~/.profile
    47  source ~/.profile
    48  
    49  # install terraform
    50  wget https://releases.hashicorp.com/terraform/0.11.7/terraform_0.11.7_linux_amd64.zip
    51  unzip terraform_0.11.7_linux_amd64.zip -d /usr/bin/
    52  
    53  # install ansible
    54  sudo apt-get update -y
    55  sudo apt-add-repository ppa:ansible/ansible -y
    56  sudo apt-get update -y
    57  sudo apt-get install ansible -y
    58  
    59  # required by ansible
    60  pip install dopy
    61  
    62  # the next two commands are directory sensitive
    63  cd $GOPATH/src/github.com/DFWallet/tendermint-cosmos/networks/remote/terraform
    64  
    65  terraform init
    66  terraform apply -var DO_API_TOKEN="$DO_API_TOKEN" -var SSH_KEY_FILE="$SSH_KEY_FILE" -auto-approve
    67  
    68  # let the droplets boot
    69  sleep 60
    70  
    71  # get the IPs
    72  ip0=`terraform output -json public_ips | jq '.value[0]'`
    73  ip1=`terraform output -json public_ips | jq '.value[1]'`
    74  ip2=`terraform output -json public_ips | jq '.value[2]'`
    75  ip3=`terraform output -json public_ips | jq '.value[3]'`
    76  
    77  # to remove quotes
    78  strip() {
    79    opt=$1
    80    temp="${opt%\"}"
    81    temp="${temp#\"}"
    82    echo $temp
    83  }
    84  
    85  ip0=$(strip $ip0)
    86  ip1=$(strip $ip1)
    87  ip2=$(strip $ip2)
    88  ip3=$(strip $ip3)
    89  
    90  # all the ansible commands are also directory specific
    91  cd $GOPATH/src/github.com/DFWallet/tendermint-cosmos/networks/remote/ansible
    92  
    93  # create config dirs
    94  tendermint testnet
    95  
    96  ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
    97  ansible-playbook -i inventory/digital_ocean.py -l sentrynet config.yml -e BINARY=$GOPATH/src/github.com/DFWallet/tendermint-cosmos/build/tendermint -e CONFIGDIR=$GOPATH/src/github.com/DFWallet/tendermint-cosmos/networks/remote/ansible/mytestnet
    98  
    99  sleep 10
   100  
   101  # get each nodes ID then populate the ansible file
   102  id0=`curl $ip0:26657/status | jq .result.node_info.id`
   103  id1=`curl $ip1:26657/status | jq .result.node_info.id`
   104  id2=`curl $ip2:26657/status | jq .result.node_info.id`
   105  id3=`curl $ip3:26657/status | jq .result.node_info.id`
   106  
   107  id0=$(strip $id0)
   108  id1=$(strip $id1)
   109  id2=$(strip $id2)
   110  id3=$(strip $id3)
   111  
   112  # remove file we'll re-write to with new info
   113  old_ansible_file=$GOPATH/src/github.com/DFWallet/tendermint-cosmos/networks/remote/ansible/roles/install/templates/systemd.service.j2
   114  rm $old_ansible_file
   115  
   116  # need to populate the `--p2p.persistent_peers` flag
   117  echo "[Unit]
   118  Description={{service}}
   119  Requires=network-online.target
   120  After=network-online.target
   121  
   122  [Service]
   123  Restart=on-failure
   124  User={{service}}
   125  Group={{service}}
   126  PermissionsStartOnly=true
   127  ExecStart=/usr/bin/tendermint node --proxy_app=kvstore --p2p.persistent_peers=$id0@$ip0:26656,$id1@$ip1:26656,$id2@$ip2:26656,$id3@$ip3:26656
   128  ExecReload=/bin/kill -HUP \$MAINPID
   129  KillSignal=SIGTERM
   130  
   131  [Install]
   132  WantedBy=multi-user.target
   133  " >> $old_ansible_file
   134  
   135  # now, we can re-run the install command
   136  ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
   137  
   138  # and finally restart it all
   139  ansible-playbook -i inventory/digital_ocean.py -l sentrynet restart.yml
   140  
   141  echo "congratulations, your testnet is now running :)"