Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a non docker ansible deploy #1

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions ansible/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

You need to have installed [Ansible](https://www.ansible.com/) in your local machine.

The Docker installation and configuration may change if you're using other Operating System
to deploy, let me know if you have problems.
The installation can be donde using Docker or not. The Docker installation and configuration may
change if you're using other Operating System to deploy, let me know if you have problems.

### Configuration

Expand All @@ -28,17 +28,31 @@ so you need to set it to `/usr/bin/python3`.
### Set your node variables

These are the same variables you need to usually set when you create a node manually, but in this case Ansible
will do it for you, you can set them on the `group_vars/regular_nodes` path.
will do it for you, you can set them on the `group_vars/regular_nodes` path. Depending on whether you use Docker
or prefer a native installation you will need to set differents groups of variables.

Once you have the variables set, you can...

## Run the node

### Docker

Execute the command from your local machine:

```bash
ansible-playbook -i host deploy_regular_node.yml -vv
ansible-playbook -i host deploy_regular_node_docker.yml -vv
Anthares101 marked this conversation as resolved.
Show resolved Hide resolved
```

This will install Docker and run the docker container inside with the variables you set when you run the
command.

### Native

Execute the command from your local machine:

```bash
ansible-playbook -i host deploy_regular_node.yml -vv
```

This will install everything natively and start the quorum node with the variables you set when you run the
command.
204 changes: 173 additions & 31 deletions ansible/deploy_regular_node.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,182 @@
---

- hosts: all
remote_user: ubuntu
remote_user: "{{ remote_user|quote }}"
environment:
PATH: /usr/local/go/bin:{{ ansible_env.PATH|quote }}

tasks:
- name: Install docker
- name: Add the deploy user
become: yes
apt:
name: docker.io
user:
name: "{{ deploy_user|quote }}"
state: present

- name: Install dependencies

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd separate basic requirements (as the apt packages) form the more specific quorum installation, just to make it easy to deploy separately using tags. We might want to install a new version of quorum but not launch the apt for example.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is how the deploy works now. The apt dependencies and the quorum installation are separated or i'm misunderstanding something?

become: yes
package:
name:
- sudo
- git
- curl
- dnsutils
- net-tools
- logrotate
- software-properties-common
- unzip
- wget
- make
- gcc
- libsodium-dev
- build-essential
- libdb-dev
- zlib1g-dev
- libtinfo-dev
- sysvbanner
- psmisc
- libleveldb-dev
- libdb5.3-dev
- screen
- logrotate
state: latest

- name: 'add users to docker group'
- name: Install Golang compiler
become: yes
user:
name: '{{ deploy_user }}'
groups: 'docker'
append: 'yes'

- name: Clone and update the repo
git:
repo: '{{ project_repo }}'
dest: '{{ project_path }}'
version: '{{ project_repo_version }}'
force: yes
accept_hostkey: yes

- name: Execute init.sh to create the regular node
shell: ./init.sh
args:
chdir: '{{ project_path }}/docker/general'
environment:
COMPANY_NAME: '{{ company_name }}'
CPU: '{{ cpu_number }}'
RAM: '{{ ram_number }}'
SEQ: '{{ sequential }}'
ENABLE_CONSTELLATION: '{{ enable_constellation }}'
MONITOR_ENABLED: '{{ enable_monitor }}'
NO_LAUNCH_CONFIRM: '{{ no_launch_confirm }}'
EXTRA_DOCKER_ARGUMENTS: '{{ extra_docker_arguments }}'
unarchive:
src: https://storage.googleapis.com/golang/{{ golang_version|quote }}
dest: /usr/local/
remote_src: yes

- name: Install Quorum
become: yes
block:
- name: Clone Quorum repository
git:
repo: https://github.com/ConsenSys/quorum.git
dest: /tmp/quorum
version: "{{ quorum_version|quote }}"
- name: Compile geth
shell: make -C /tmp/quorum all
- name: Copy geth to right location
copy:
remote_src: yes
src: /tmp/quorum/build/bin/geth
dest: /usr/local/bin/geth
mode: a+x
- name: Copy bootnode to right location
copy:
remote_src: yes
src: /tmp/quorum/build/bin/bootnode
dest: /usr/local/bin/bootnode
mode: a+x

- name: Check that the INITIALIZED file exists
stat:
path: ~/data/INITIALIZED
register: INITIALIZED

- name: Initialize the node if necessary
become: yes
become_user: "{{ deploy_user|quote }}"
when: not INITIALIZED.stat.exists
block:
- name: Create the data directory if it does not exist yet
file:
path: ~/data
state: directory

- name: Create the nodekey
shell: /usr/local/bin/bootnode -genkey ~/data/nodekey

- name: Get the enode key
shell: /usr/local/bin/bootnode -nodekey ~/data/nodekey -writeaddress > ~/data/ENODE_ADDRESS

- name: Download genesis.json
get_url:
url: "https://raw.githubusercontent.com/alastria/alastria-node/{{ project_repo_branch|quote }}/data/genesis.json"
dest: ~/genesis.json

- name: Execute geth init command
shell: |
pkill geth
/usr/local/bin/geth --datadir ~/data init ~/genesis.json

- name: Mark the node as initialized
shell: /bin/echo "INITIALIZED" > ~/data/INITIALIZED

- name: Get nodes and start geth node
become: yes
become_user: "{{ deploy_user|quote }}"
block:
- name: Create temporary file
tempfile:
path: /tmp
register: TMPFILE
- name: Create env directory
file:
path: ~/env
state: directory
mode: 0755
- name: Get current nodes and parse databases
shell: |
for i in boot-nodes.json validator-nodes.json regular-nodes.json ; do
wget -q -O ~/env/${i} https://raw.githubusercontent.com/alastria/alastria-node/{{ project_repo_branch|quote }}/data/${i}
done

case {{ node_type|quote }} in
"bootnode")
cat ~/env/boot-nodes.json ~/env/validator-nodes.json ~/env/regular-nodes.json >> {{ TMPFILE.path|quote }}
;;
"validator")
cat ~/env/boot-nodes.json ~/env/validator-nodes.json >> {{ TMPFILE.path|quote }}
;;
"general")
cat ~/env/boot-nodes.json >> {{ TMPFILE.path|quote }}
;;
*)
echo "ERROR: nodetype not recognized"
exit 1
;;
esac

sed -e '1s/^/[\n/' -i {{ TMPFILE.path|quote }}
sed -e '$s/,$/\n]/' -i {{ TMPFILE.path|quote }}

cat {{ TMPFILE.path|quote }} > ~/data/static-nodes.json
cat {{ TMPFILE.path|quote }} > ~/data/permissioned-nodes.json
args:
executable: /bin/bash
- name: Get initialization scripts
shell: |
for i in geth.common.sh geth.node.{{ node_type|quote }}.sh ; do
wget -q -O ~/env/${i} https://raw.githubusercontent.com/alejandroalffer/alastria-node-t/master/alastria-node-data/env/${i}
done
args:
executable: /bin/bash
- name: Prepare geth and launch node
shell: |
source ~/env/geth.common.sh
source ~/env/geth.node.{{ node_type|quote }}.sh

screen -d -m -L -Logfile ~/geth.log /usr/local/bin/geth --datadir ~/data ${GLOBAL_ARGS} ${NETSTATS_METRICS} ${INFLUX_METRICS} ${NODE_ARGS} ${LOCAL_ARGS}
args:
executable: /bin/bash
environment:
PRIVATE_CONFIG: ignore
NODE_NAME: "REG_{{ company_name|quote }}_T_{{ cpu_number|quote }}_{{ ram_number|quote }}_{{ sequential|quote }}"
- name: Add geth logs to logrotate
become: yes
blockinfile:
path: /etc/logrotate.d/geth
block: |
/home/{{ deploy_user }}/geth.log {
weekly
rotate 3
size 10M
compress
missingok
notifempty
delaycompress
create 0640 {{ deploy_user }} {{ deploy_user }}
}
create: true
40 changes: 40 additions & 0 deletions ansible/deploy_regular_node_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---

- hosts: all
remote_user: '{{ remote_user }}'

tasks:
- name: Install docker
become: yes
apt:
name: docker.io
state: present

- name: 'add users to docker group'
become: yes
user:
name: '{{ deploy_user }}'
groups: 'docker'
append: 'yes'

- name: Clone and update the repo
git:
repo: '{{ project_repo }}'
dest: '{{ project_path }}'
version: '{{ project_repo_branch }}'
force: yes
accept_hostkey: yes

- name: Execute init.sh to create the regular node
shell: ./init.sh
args:
chdir: '{{ project_path }}/docker/general'
environment:
COMPANY_NAME: '{{ company_name }}'
CPU: '{{ cpu_number }}'
RAM: '{{ ram_number }}'
SEQ: '{{ sequential }}'
ENABLE_CONSTELLATION: '{{ enable_constellation }}'
MONITOR_ENABLED: '{{ enable_monitor }}'
NO_LAUNCH_CONFIRM: '{{ no_launch_confirm }}'
EXTRA_DOCKER_ARGUMENTS: '{{ extra_docker_arguments }}'
20 changes: 16 additions & 4 deletions ansible/group_vars/regular_nodes
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@

# You can change all these variables to your needs

deploy_user: ubuntu # SSH user connecting to the server
project_path: /home/{{ deploy_user }}/alastria-node
project_repo: https://github.com/alastria-node/alastria-node
project_repo_version: testnet2
# Variables for deploy_regular_node_docker and deploy_regular_node

remote_user: <SETME> # SSH user connecting to the server
deploy_user: ubuntu # User who run the service
company_name: <SETME>
cpu_number: <SETME>
ram_number: <SETME>
sequential: <SETME>
project_repo_branch: testnet2

# Variables for only deploy_regular_node_docker

project_path: /home/{{ deploy_user }}/alastria-node
project_repo: https://github.com/alastria/alastria-node

enable_constellation: <SETME>
enable_monitor: <SETME>
no_launch_confirm: <SETME>
extra_docker_arguments: <SETME>

# Variables for only deploy_regular_node

golang_version: go1.9.5.linux-amd64.tar.gz
quorum_version: v2.2.3
node_type: general