Skip to content
Permalink
Browse files

update code

  • Loading branch information...
naviat committed Nov 27, 2018
1 parent cd29037 commit b119571d3b6fcf1cc1d65e2b3d596ff053fe6705
Showing with 388 additions and 410 deletions.
  1. +14 −25 .gitignore
  2. +18 −49 README.md
  3. +72 −0 Vagrantfile
  4. +72 −0 Vagrantfile.singapore
  5. +72 −0 Vagrantfile.tokyo
  6. +72 −0 Vagrantfile.virginia
  7. +24 −0 apply.sh
  8. +38 −0 config.json.temp
  9. +3 −0 down.sh
  10. +0 −15 main/config/main.tfvars.temp
  11. +0 −278 main/main.tf
  12. +0 −26 main/output.tf
  13. +0 −17 main/user-data.sh
  14. +3 −0 up.sh
@@ -1,31 +1,20 @@
# Local .terraform directories
main/.terraform/*
nodes/.terraform/*
scrips/
*.tfvars
.env*
.sshKeys*
.pwd
.*.sw*
*.log

# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars
# .tfvars files
*.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json
#config
.env*
.sshKeys*
.pwd
.*.sw*
*.log
config.json
.vagrant
nodes
log.*%
@@ -1,69 +1,38 @@
# Step-by-step to provision infrastructure of masternodes on AWS EC2
# Step-by-step to provision infrastructure of masternodes on EC2

## Updating...

1. Preparation

- Download and install `terraform` following this [docs](https://www.terraform.io/intro/getting-started/install.html)

- Config your AWS credentials following this [docs](https://docs.aws.amazon.com/cli/latest/userguide/cli-config-files.html)
## Bring up

1. Configuration

Update `main.tfvars` file at below fields:
Update `config.json` file at below fields (with each region, you need to create config,json):

- "sshKeyName": specify your ssh key registered on AWS
- "accessKeyId": AWS access key
- "secretAccessKey": AWS secret key
- "sshKeyName": specify your ssh key registered on DO
- "privateKeyPath": path to the private ssh key on your machine
- "coinbasePrivateKeySun": private key of the SUN masternode
- "access_key": AWS access key ID
- "secret_key": AWS secret key
- "node": put in information for each masternode

1. Initialization your terraform configuration

The first command to run for a new configuration -- or after checking out an existing configuration from version control -- is terraform init, which initializes various local settings and data that will be used by subsequent commands.
2. Join a node to testnet (select for each region)

```
$ terraform init
Initializing the backend...
Initializing provider plugins...
- downloading plugin for provider "aws"...
The following providers do not have any version constraints in configuration,
so the latest version was installed.
To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.
* provider.aws: version = "~> 1.0"
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your environment. If you forget, other
commands will detect it and remind you to do so if necessary.
$ ./up.sh main
```

1. Start up SUN masternode, which is included TomoMaster, TomoScan, Netstats
3. Start up other masternodes

```
$ terraform plan
$ terraform apply
$ ./up.sh <region>
```

1. Start up other masternodes



## Bring down
```

```
$ ./down.sh main
$ ./down.sh node
```


## Vote for a masternode
## Update code and reload
```
VAGRANT_VAGRANTFILE=Vagrantfile.main vagrant ssh -c "consul kv put tomochain/reset 1"
```
@@ -0,0 +1,72 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'json'

appConfig = JSON.parse(File.read('config.json')) # update config.<region>.json for each region
nodes = appConfig['nodes']

Vagrant.configure("2") do |config|

nodes.each do |node|
config.vm.define node['name'] do |config|
envFile = '.env.' + node['name']
f = File.new(envFile, 'w')
f.write('TOMOMASTER=http://' + appConfig['mainPublicIp'] + ':3001' + "\n")
f.write('RPC_URL=http://' + appConfig['mainPublicIp'] + ':8545' + "\n")
f.write('OWNER_PRIVATE_KEY=' + node['ownerPrivateKey'] + "\n")
f.write('COINBASE_PRIVATE_KEY=' + node['coinbasePrivateKey'] + "\n")
f.write('COINBASE_ADDRESS=' + node['coinbaseAddress'] + "\n")
f.close

ENV['LC_ALL']="C.UTF-8"
ENV['COINBASE_PRIVATE_KEY']=node['coinbasePrivateKey']
ENV['DEBIAN_FRONTEND']='noninteractive'

config.vm.provider :aws do |aws, override|
aws.ami = 'ami-0b4d63df52bb04cb3'
aws.region = node['region']
aws.keypair_name = appConfig['sshKeyName']
aws.instance_type = 't2.xlarge'
aws.security_groups = [ 'vagrant' ]
#aws.subnet_id = "subnet-a10e7ac5"
aws.block_device_mapping = [
{
'DeviceName' => '/dev/sda1',
'Ebs.VolumeSize' => 16
}
]
aws.tags = {
'Name' => 'node-test',
}
#aws.associate_public_ip = true
override.vm.box = 'dummy'
override.ssh.private_key_path = appConfig['privateKeyPath']
override.ssh.username = 'ubuntu'
#aws.security_groups = [ 'ssh', 'masternode', 'testnet', 'bootnode' ]
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provision "file", source: "./apply.sh", destination: "/home/ubuntu/apply.sh"
config.vm.provision "file", source: envFile, destination: "/home/ubuntu/.env"
$post_script = <<-SCRIPT
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update && sudo apt-get install -y docker-ce
sudo usermod -aG docker ubuntu
sudo apt-get update && sudo apt-get install -y python3-pip && pip3 install -U tmn
export LC_ALL=C.UTF-8
(crontab -l -u root; echo "*/2 * * * * bash /home/ubuntu/apply.sh") | crontab -u root -
SCRIPT
config.vm.provision "shell", inline: $post_script
config.vm.provision "shell", inline: <<-SHELL
source /home/ubuntu/.env
tmn start --name anonymous --pkey ${COINBASE_PRIVATE_KEY} --net testnet
SHELL
end
end
end
end
@@ -0,0 +1,72 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'json'

appConfig = JSON.parse(File.read('config.singapore.json')) # update config.<region>.json for each region
nodes = appConfig['nodes']

Vagrant.configure("2") do |config|

nodes.each do |node|
config.vm.define node['name'] do |config|
envFile = '.env.' + node['name']
f = File.new(envFile, 'w')
f.write('TOMOMASTER=http://' + appConfig['mainPublicIp'] + ':3001' + "\n")
f.write('RPC_URL=http://' + appConfig['mainPublicIp'] + ':8545' + "\n")
f.write('OWNER_PRIVATE_KEY=' + node['ownerPrivateKey'] + "\n")
f.write('COINBASE_PRIVATE_KEY=' + node['coinbasePrivateKey'] + "\n")
f.write('COINBASE_ADDRESS=' + node['coinbaseAddress'] + "\n")
f.close

ENV['LC_ALL']="C.UTF-8"
ENV['COINBASE_PRIVATE_KEY']=node['coinbasePrivateKey']
ENV['DEBIAN_FRONTEND']='noninteractive'

config.vm.provider :aws do |aws, override|
aws.ami = 'ami-0b4d63df52bb04cb3'
aws.region = node['region']
aws.keypair_name = appConfig['sshKeyName']
aws.instance_type = 't2.xlarge'
aws.security_groups = [ 'vagrant' ]
#aws.subnet_id = "subnet-a10e7ac5"
aws.block_device_mapping = [
{
'DeviceName' => '/dev/sda1',
'Ebs.VolumeSize' => 16
}
]
aws.tags = {
'Name' => 'node-test',
}
#aws.associate_public_ip = true
override.vm.box = 'dummy'
override.ssh.private_key_path = appConfig['privateKeyPath']
override.ssh.username = 'ubuntu'
#aws.security_groups = [ 'ssh', 'masternode', 'testnet', 'bootnode' ]
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provision "file", source: "./apply.sh", destination: "/home/ubuntu/apply.sh"
config.vm.provision "file", source: envFile, destination: "/home/ubuntu/.env"
$post_script = <<-SCRIPT
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update && sudo apt-get install -y docker-ce
sudo usermod -aG docker ubuntu
sudo apt-get update && sudo apt-get install -y python3-pip && pip3 install -U tmn
export LC_ALL=C.UTF-8
(crontab -l -u root; echo "*/2 * * * * bash /home/ubuntu/apply.sh") | crontab -u root -
SCRIPT
config.vm.provision "shell", inline: $post_script
config.vm.provision "shell", inline: <<-SHELL
source /home/ubuntu/.env
tmn start --name anonymous --pkey ${COINBASE_PRIVATE_KEY} --net testnet
SHELL
end
end
end
end
@@ -0,0 +1,72 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'json'

appConfig = JSON.parse(File.read('config.tokyo.json')) # update config.<region>.json for each region
nodes = appConfig['nodes']

Vagrant.configure("2") do |config|

nodes.each do |node|
config.vm.define node['name'] do |config|
envFile = '.env.' + node['name']
f = File.new(envFile, 'w')
f.write('TOMOMASTER=http://' + appConfig['mainPublicIp'] + ':3001' + "\n")
f.write('RPC_URL=http://' + appConfig['mainPublicIp'] + ':8545' + "\n")
f.write('OWNER_PRIVATE_KEY=' + node['ownerPrivateKey'] + "\n")
f.write('COINBASE_PRIVATE_KEY=' + node['coinbasePrivateKey'] + "\n")
f.write('COINBASE_ADDRESS=' + node['coinbaseAddress'] + "\n")
f.close

ENV['LC_ALL']="C.UTF-8"
ENV['COINBASE_PRIVATE_KEY']=node['coinbasePrivateKey']
ENV['DEBIAN_FRONTEND']='noninteractive'

config.vm.provider :aws do |aws, override|
aws.ami = 'ami-0b4d63df52bb04cb3'
aws.region = node['region']
aws.keypair_name = appConfig['sshKeyName']
aws.instance_type = 't2.xlarge'
aws.security_groups = [ 'vagrant' ]
#aws.subnet_id = "subnet-a10e7ac5"
aws.block_device_mapping = [
{
'DeviceName' => '/dev/sda1',
'Ebs.VolumeSize' => 16
}
]
aws.tags = {
'Name' => 'node-test',
}
#aws.associate_public_ip = true
override.vm.box = 'dummy'
override.ssh.private_key_path = appConfig['privateKeyPath']
override.ssh.username = 'ubuntu'
#aws.security_groups = [ 'ssh', 'masternode', 'testnet', 'bootnode' ]
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provision "file", source: "./apply.sh", destination: "/home/ubuntu/apply.sh"
config.vm.provision "file", source: envFile, destination: "/home/ubuntu/.env"
$post_script = <<-SCRIPT
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update && sudo apt-get install -y docker-ce
sudo usermod -aG docker ubuntu
sudo apt-get update && sudo apt-get install -y python3-pip && pip3 install -U tmn
export LC_ALL=C.UTF-8
(crontab -l -u root; echo "*/2 * * * * bash /home/ubuntu/apply.sh") | crontab -u root -
SCRIPT
config.vm.provision "shell", inline: $post_script
config.vm.provision "shell", inline: <<-SHELL
source /home/ubuntu/.env
tmn start --name anonymous --pkey ${COINBASE_PRIVATE_KEY} --net testnet
SHELL
end
end
end
end
Oops, something went wrong.

0 comments on commit b119571

Please sign in to comment.
You can’t perform that action at this time.