Skip to content

Commit

Permalink
Merge pull request cosmos#1044 from cosmos/greg/remotenet
Browse files Browse the repository at this point in the history
Remotenet commands for easy cloud validators setup
  • Loading branch information
cwgoes authored May 25, 2018
2 parents 975668a + 3b9dadd commit 2cafe7d
Show file tree
Hide file tree
Showing 31 changed files with 2,046 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ FEATURES
* [stake] Creation of a validator/delegation generics in `/types`
* [stake] Helper Description of the store in x/stake/store.md
* [stake] removed use of caches in the stake keeper
* [Makefile] Added terraform/ansible playbooks to easily create remote testnets on Digital Ocean

BUG FIXES

Expand Down
27 changes: 26 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,32 @@ devdoc_update:
docker pull tendermint/devdoc


########################################
### Remote validator nodes using terraform and ansible

# Build linux binary
build-linux:
GOOS=linux GOARCH=amd64 $(MAKE) build

TESTNET_NAME?=remotenet
SERVERS?=4
BINARY=$(CURDIR)/build/gaiad
remotenet-start:
@if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
@if ! [ -f $(HOME)/.ssh/id_rsa.pub ]; then ssh-keygen ; fi
@if [ -z "`file $(BINARY) | grep 'ELF 64-bit'`" ]; then echo "Please build a linux binary using 'make build-linux'." ; false ; fi
cd networks/remote/terraform && terraform init && terraform apply -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_PUBLIC_FILE="$(HOME)/.ssh/id_rsa.pub" -var SSH_PRIVATE_FILE="$(HOME)/.ssh/id_rsa" -var TESTNET_NAME="$(TESTNET_NAME)" -var SERVERS="$(SERVERS)"
cd networks/remote/ansible && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory/digital_ocean.py -l "$(TESTNET_NAME)" -e BINARY=$(BINARY) -e TESTNET_NAME="$(TESTNET_NAME)" setup-validators.yml
cd networks/remote/ansible && ansible-playbook -i inventory/digital_ocean.py -l "$(TESTNET_NAME)" start.yml

remotenet-stop:
@if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
cd networks/remote/terraform && terraform destroy -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_PUBLIC_FILE="$(HOME)/.ssh/id_rsa.pub" -var SSH_PRIVATE_FILE="$(HOME)/.ssh/id_rsa"

remotenet-status:
cd networks/remote/ansible && ansible-playbook -i inventory/digital_ocean.py -l "$(TESTNET_NAME)" status.yml

# To avoid unintended conflicts with file names, always add to .PHONY
# unless there is a reason not to.
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: build build_examples install install_examples dist check_tools get_tools get_vendor_deps draw_deps test test_cli test_unit test_cover test_lint benchmark devdoc_init devdoc devdoc_save devdoc_update
.PHONY: build build_examples install install_examples dist check_tools get_tools get_vendor_deps draw_deps test test_cli test_unit test_cover test_lint benchmark devdoc_init devdoc devdoc_save devdoc_update remotenet-start remotenet-stop remotenet-status
67 changes: 67 additions & 0 deletions networks/remote/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Terraform & Ansible
===================

Automated deployments are done using `Terraform <https://www.terraform.io/>`__ to create servers on Digital Ocean then
`Ansible <http://www.ansible.com/>`__ to create and manage testnets on those servers.

Prerequisites
-------------

- Install `Terraform <https://www.terraform.io/downloads.html>`__ and `Ansible <http://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html>`__ on a Linux machine.
- Create a `DigitalOcean API token <https://cloud.digitalocean.com/settings/api/tokens>`__ with read and write capability.
- Install the python dopy package (``pip install dopy``) (This is necessary for the digitalocean.py script for ansible.)
- Create SSH keys

::

export DO_API_TOKEN="abcdef01234567890abcdef01234567890"
export TESTNET_NAME="remotenet"
export SSH_PRIVATE_FILE="$HOME/.ssh/id_rsa"
export SSH_PUBLIC_FILE="$HOME/.ssh/id_rsa.pub"

These will be used by both ``terraform`` and ``ansible``.

Create a remote network
-----------------------

::

make remotenet-start


Optionally, you can set the number of servers you want to launch and the name of the testnet (which defaults to remotenet):

::

TESTNET_NAME="mytestnet" SERVERS=7 make remotenet-start


Quickly see the /status endpoint
--------------------------------

::

make remotenet-status


Delete servers
--------------

::

make remotenet-stop

Logging
-------

You can ship logs to Logz.io, an Elastic stack (Elastic search, Logstash and Kibana) service provider. You can set up your nodes to log there automatically. Create an account and get your API key from the notes on `this page <https://app.logz.io/#/dashboard/data-sources/Filebeat>`__, then:

::

yum install systemd-devel || echo "This will only work on RHEL-based systems."
apt-get install libsystemd-dev || echo "This will only work on Debian-based systems."

go get github.com/mheese/journalbeat
ansible-playbook -i inventory/digital_ocean.py -l remotenet logzio.yml -e LOGZIO_TOKEN=ABCDEFGHIJKLMNOPQRSTUVWXYZ012345


2 changes: 2 additions & 0 deletions networks/remote/ansible/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.retry
files/*
4 changes: 4 additions & 0 deletions networks/remote/ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[defaults]
retry_files_enabled = False
host_key_checking = False

9 changes: 9 additions & 0 deletions networks/remote/ansible/clear-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

- hosts: all
user: root
any_errors_fatal: true
gather_facts: no
roles:
- clear-config

Loading

0 comments on commit 2cafe7d

Please sign in to comment.