Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Jan 12, 2018
0 parents commit 2bed864
Show file tree
Hide file tree
Showing 53 changed files with 1,610 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
@@ -0,0 +1,17 @@
.env

# Ansible
*.retry

# Vagrant
.vagrant

# Terraform
*.tfstate
*.tfstate.backup
.terraform
/clusters/aws-example.inventory

# CLion
cmake-build-debug
.idea
20 changes: 20 additions & 0 deletions LICENSE
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2017 The Dash Core Group, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 changes: 41 additions & 0 deletions README.md
@@ -0,0 +1,41 @@
Dash Cluster Ansible
====================

What is this?
-------------

This is an Ansible project to setup and manage devnet (and later testnet) networks. Devnets
are like regular Dash networks (mainnet, testnet) but easier to bootstrap and easier to have
multiple in parallel.

This project is work in progress and in its initial state only meant to be used by Dash Core
developers to assist in Dash Evolution development.

Detailed documentation on how to use this repo will come when more interest from the public
arises or when Evolution is released.

Getting started
---------------

Create your own cluster configuration in `clusters`. Use `aws-example.*` as a skeleton. The
following commands will all directly use the aws-example, while you should change it to use
your own config.

Setup the AWS infrastructure with terraform:

```bash
$ cd terraform/aws
$ terraform apply -var-file=../../clusters/aws-example.tfvars
```

Create the inventory file for Ansible

```bash
$ terraform output ansible_inventory > ../../clusters/aws-example.inventory
```

Invoke ansible-playbook
```bash
$ cd ../.. # Go back to root dir of project
$ ansible-playbook -i clusters/aws-example.inventory -e @clusters/aws-example.yml cluster.yml
```
5 changes: 5 additions & 0 deletions ansible.cfg
@@ -0,0 +1,5 @@
[defaults]
host_key_checking = False

[ssh_connection]
pipelining = True
84 changes: 84 additions & 0 deletions cluster.yml
@@ -0,0 +1,84 @@
---
######################
# Bootstrap

- hosts: all
gather_facts: False
become: true
pre_tasks:
- name: install python 2
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
- name: Check if inside AWS.
uri:
url: http://169.254.169.254/latest/meta-data
timeout: 2
register: aws_uri_check
failed_when: False
- set_fact:
is_aws_environment: "{{ aws_uri_check.status == 200 }}"
roles:
- role: aws
when: is_aws_environment

######################

- hosts: all
become: true
vars:
pip_install_packages:
- name: docker
- name: docker-compose
roles:
- geerlingguy.pip
- geerlingguy.docker
- ecr-login
- dash-cli

# private nodes
- hosts: wallet-nodes
become: true
roles:
- role: dashd
dashd_indexes: true
dashd_zmq: true

# public nodes
- hosts: full-nodes, masternodes
become: true
pre_tasks:
- set_fact:
masternode: '{{ masternodes[inventory_hostname] }}'
when: inventory_hostname in masternodes
roles:
- role: dashd
dashd_listen: true
- role: mn-sentinel
when: masternode is defined

# generate first block on seed node so that all nodes leave IBD mode (required for mining)
- hosts: seed-node
become: true
roles:
- role: generate-firstblock
when: dash_network == "devnet" or dash_network == "regtest"

- hosts: miners
become: true
roles:
- role: regtest-miner
when: dash_network == "regtest"
- role: cpuminer
when: dash_network != "regtest"

- hosts: web
become: true
roles:
- multifaucet

- hosts: masternode-wallet
become: true
roles:
- mn-fund-collateral
- mn-pay-faucet
- mn-conf
- mn-start
1 change: 1 addition & 0 deletions clusters/README.md
@@ -0,0 +1 @@
Put your cluster configurations here. See aws-example.yml for an example
9 changes: 9 additions & 0 deletions clusters/aws-example.tfvars
@@ -0,0 +1,9 @@
dash_network="devnet"
dash_devnet_name="aws-example"
dashd_port=20001
dashd_rpc_port=20002
node_count=1
miner_count=2
masternode_count = 13
66 changes: 66 additions & 0 deletions clusters/aws-example.yml
@@ -0,0 +1,66 @@
---

dash_network: devnet
dash_devnet_name: aws-example
dashd_port: 20001
dashd_rpcport: 20002

dashd_rpcuser: dashrpc
dashd_rpcpassword: password

faucet_address: yhvXpqQjfN9S4j5mBKbxeGxiETJrrLETg5
faucet_privkey: cR4t6evwVZoCp1JsLk4wURK4UmBCZzZotNzn9T1mhBT19SH9JtNt

masternodes:
masternode-1:
address: yiRNTUNCS39WPu3VhT7utRWTJYzmUdf1aR
address_key: cSrCXqZ1oVw3vpeuoyPKHBpGiMmf6pQerF64MYMcS11HQ4bGquDF
privkey: 92KdqxzX7HCnxCtwt1yHENGrXq71SAxD4vrrsFArbSU2wUKdQCM
masternode-2:
address: ybpwqoZ2Q4goxrzgPx9b3cbPrvy6UbC1ct
address_key: cN88MoW1XEv1s4wt6zgbQ8aR9KYM4RZihSeoRUcdWmwdAyu6HaDu
privkey: 93Fd7XY2zF4q9YKTZUSFxLgp4Xs7MuaMnvY9kpvH7V8oXWqsCC1
masternode-3:
address: yQuwR1uaci2SCQBgqcaKRzfq7upL4n513j
address_key: cTEGsaAqx9jUFYkNECeGKfixa6vgMiUoSwqsdncc11mS6BZerTpT
privkey: 93EmoMmHgTCg8yVhRtK5sxpv5k4Sq1KoHCVB43VxbbZpVPtHMnc
masternode-4:
address: yQCV7FnK99crDwmiwrLCwgaDKz5qV4my6u
address_key: cSMvsssFKziHctH2d2FNfeCaKuEckC9PB8aQD1E6ecYjSpDdYrLf
privkey: 931yVsW5MFNCRSPDYPR6UFJHp3SVRDkuhGGwqgmPiEaayRrdcoW
masternode-5:
address: yiS4S2aLvXf61WcJEc2mzkuLHCeBgd7wLp
address_key: cVMFBkeZ4X3HAz14CjQnpA9KqDSLGUbxNVx5BxXMxkBj4Us3HDpc
privkey: 92Srupy73xqSbXVK2MARo8Euq9kmdv5KVsaeZtdNCxQREU9xS4x
masternode-6:
address: yZrCcddoxdH16STwQpmpEPbn6urenS8yjf
address_key: cRNS6N2gakrSZWEz4NsxLwSzv9GYxS9wS4efLyntKo66ZiaenZyo
privkey: 92D4QRUTz1svVMgfmXrHqpYV7JZQ1ECP1d65m6j9AuLY9Wr6mGX
masternode-7:
address: yQSQoco2uAR4sc2AkXGNcAcBnbYY4q7a6T
address_key: cNj3itrDW4abS97dv6fE1dy16kDbfB8K63zws8Q65xMTEgZ8Gtqz
privkey: 92mSVHx5eji6QHAiMANYKMFcVeoukwf7cGG9SjvR3jbG9n5nFzu
masternode-8:
address: yXrf4MNYipnGmSQqGv1HGqmD3xxWELs9T9
address_key: cQy6bcyDYwHR97wa4zUnuJAp6Fw3gJHoq1nFBCXqJBs2G17siFki
privkey: 92iu2nJLxreHMVSzMn7XeAS3zScuNPMocp9wrLUcCHJdgzLRFzR
masternode-9:
address: yTezNspASgUWeRvkVbQx7brFzJYnihkCdB
address_key: cQKSAVBd87j5EGtWEf2m5zip1qFmWBWzZ3yRhGeTMvB8wjLarxM2
privkey: 92C4n8apRbzU91ETwM1KxAMGzzsjy9mRtqph9NptbRc5XJV1xAg
masternode-10:
address: yN4YJuZUUCiVTNoKwtNsNTapGvW9PbmzXk
address_key: cMdZCshfc8mhSTb8oauuraWKAZjfGDnx4xX9HE2D4nP74WwEk1HN
privkey: 91f9gi61MzGFSBuwzq5zZq4NHnA8vGL3qUUZyNijGWnimEtfnuq
masternode-11:
address: yTWgsUVk66vV2csfYFDxvYU31BupXDD2mE
address_key: cPaGBsFGjvsxBqZKzSCdERACg7EPkKBJf8kP4h6f9S8ZZeCoBqHh
privkey: 93Mhiq2KS5ZUGo4M7XnvuccMZQSvLvt81Ac5A7LgrH17DcE9Cp2
masternode-12:
address: yUtqnQw3DHgn6BEwjnR1hVabKDM4F8pAuP
address_key: cNsvfpZb3RY3k7LvcxGriGavBqznE4Cn1q1QF8bGZo5eHMu7ngW3
privkey: 91k7JxVWDDBoWpA8DZHc9FZwV5b1wZEf52v1m5dwzrzroyxhxHN
masternode-13:
address: yYzxjiTcG8HuKBXS3VW5yhjfZdMhMV1NqB
address_key: cPknbev5GEhHKug7QNzPRb4jpDM7PaJtfyaZgtivV86NBeCVvPFf
privkey: 933cojtvorhVLJxDdhaM9hf1wp7es7VHFxbms26DQ2tnZjxdgku
66 changes: 66 additions & 0 deletions group_vars/all
@@ -0,0 +1,66 @@
---

dash_docker_repo: dashpay
dashd_image: '{{ dash_docker_repo }}/dashd-develop'

dashd_user: dash
dashd_group: dash
dashd_home: /dash

dash_network: devnet
dash_devnet_name: devnet1
dashd_port: 29999

# Please provide your own credentials in cluster config
dashd_rpcuser: dashrpc
dashd_rpcpassword: password
dashd_rpcport: 29998

# You can provide your own seed node in cluster config. May be useful if you want to connect to another cluster
dashd_seednode: '{{ hostvars[groups["seed-node"][0]]["public_ip"] }}'

# Faucet stuff

faucet_rpc_host: '{{ hostvars[groups["faucet-wallet"][0]]["private_ip"] }}'
faucet_rpc_port: '{{ dashd_rpcport }}'
faucet_rpc_user: '{{ dashd_rpcuser }}'
faucet_rpc_password: '{{ dashd_rpcpassword }}'
faucet_rpc_args: '-rpcconnect={{ faucet_rpc_host }} -rpcport={{ faucet_rpc_port }} -rpcuser={{ faucet_rpc_user }} -rpcpassword={{ faucet_rpc_password }}'

# Example faucet address/privkey (provide your own in cluster config)
#faucet_address: yhvXpqQjfN9S4j5mBKbxeGxiETJrrLETg5
#faucet_privkey: cR4t6evwVZoCp1JsLk4wURK4UmBCZzZotNzn9T1mhBT19SH9JtNt

# Miner stuff

miner_rpc_host: '{{ faucet_rpc_host }}'
miner_rpc_port: '{{ faucet_rpc_port }}'
miner_rpc_user: '{{ faucet_rpc_user }}'
miner_rpc_password: '{{ faucet_rpc_password }}'
miner_payment_address: "{{ faucet_address }}"

# Allow to run miners at 100% by default
miner_cpu_quota: 100000 # 100%

# Masternode stuff

masternode_wallet_rpc_host: '{{ hostvars[groups["masternode-wallet"][0]]["private_ip"] }}'
masternode_wallet_rpc_port: '{{ dashd_rpcport }}'
masternode_wallet_rpc_user: '{{ dashd_rpcuser }}'
masternode_wallet_rpc_password: '{{ dashd_rpcpassword }}'
masternode_wallet_rpc_args: '-rpcconnect={{ masternode_wallet_rpc_host }} -rpcport={{ masternode_wallet_rpc_port }} -rpcuser={{ masternode_wallet_rpc_user }} -rpcpassword={{ masternode_wallet_rpc_password }}'

# Example masternodes list (provide your own in cluster config)
#masternodes:
# masternode-1:
# address: yiRNTUNCS39WPu3VhT7utRWTJYzmUdf1aR
# address_key: cSrCXqZ1oVw3vpeuoyPKHBpGiMmf6pQerF64MYMcS11HQ4bGquDF
# privkey: 92KdqxzX7HCnxCtwt1yHENGrXq71SAxD4vrrsFArbSU2wUKdQCM
# masternode-2:
# address: ybpwqoZ2Q4goxrzgPx9b3cbPrvy6UbC1ct
# address_key: cN88MoW1XEv1s4wt6zgbQ8aR9KYM4RZihSeoRUcdWmwdAyu6HaDu
# privkey: 93Fd7XY2zF4q9YKTZUSFxLgp4Xs7MuaMnvY9kpvH7V8oXWqsCC1
# masternode-3:
# address: yQuwR1uaci2SCQBgqcaKRzfq7upL4n513j
# address_key: cTEGsaAqx9jUFYkNECeGKfixa6vgMiUoSwqsdncc11mS6BZerTpT
# privkey: 93EmoMmHgTCg8yVhRtK5sxpv5k4Sq1KoHCVB43VxbbZpVPtHMnc
5 changes: 5 additions & 0 deletions kill-cluster.yml
@@ -0,0 +1,5 @@
---
- hosts: all
become: true
roles:
- kill-cluster
14 changes: 14 additions & 0 deletions roles/aws/tasks/main.yml
@@ -0,0 +1,14 @@
---

- name: update hostname
hostname:
name: '{{ inventory_hostname }}'

- name: ensure hostname is in /etc/hosts
lineinfile:
path: /etc/hosts
regexp: '^127\.0\.0\.1'
line: '127.0.0.1 localhost {{ inventory_hostname }}'
owner: root
group: root
mode: 0644
3 changes: 3 additions & 0 deletions roles/cpuminer/defaults/main.yml
@@ -0,0 +1,3 @@
---

cpuminer_image: 'ablock/dash-cpuminer'
11 changes: 11 additions & 0 deletions roles/cpuminer/tasks/main.yml
@@ -0,0 +1,11 @@
---

- name: create cpuminer container
docker_container:
name: dash-cpuminer
state: started
#cpu_quota: "{{ miner_cpu_quota }}"
image: '{{ cpuminer_image }}'
pull: true
restart_policy: always
command: '-r 1 -a x11 --no-getwork --no-stratum -o http://{{ miner_rpc_host }}:{{ miner_rpc_port }} -u {{ miner_rpc_user }} -p {{ miner_rpc_password }} --coinbase-addr={{ miner_payment_address }}'
7 changes: 7 additions & 0 deletions roles/dash-cli/tasks/main.yml
@@ -0,0 +1,7 @@
---

- name: pull dashd image
shell: docker pull {{ dashd_image }}

- name: copy dash-cli from docker container
shell: docker run --rm -v /tmp:/host-tmp {{ dashd_image }} cp /usr/bin/dash-cli /host-tmp/ && mv /tmp/dash-cli /usr/local/bin/dash-cli
16 changes: 16 additions & 0 deletions roles/dashd/defaults/main.yml
@@ -0,0 +1,16 @@
---

dashd_debug: 1

dashd_indexes: false
dashd_zmq: false

dashd_listen: false
dashd_externalip: '{{ public_ip }}'
dashd_isseednode: '{{ dashd_externalip == dashd_seednode }}'

dashd_private_net_prefix: 16
dashd_private_cidr: '{{ private_ip|ipsubnet(dashd_private_net_prefix) }}'

# When running devnet/regtest in local networks, we have to allow RFC1918/private addresses
dashd_allowprivatenet: '{% if dashd_externalip|ipaddr("private") == dashd_externalip %}1{% else %}0{% endif %}'

0 comments on commit 2bed864

Please sign in to comment.