Skip to content

Commit

Permalink
deploy iroha network on clean machines
Browse files Browse the repository at this point in the history
Signed-off-by: dumitru <[email protected]>
  • Loading branch information
x3medima17 committed Nov 20, 2017
1 parent c310584 commit 76c2ac1
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ build/*
*.o
*.pb.cc
*.pb.h
*.retry
.gradle/*
.vscode/*
.idea/*
Expand Down
12 changes: 12 additions & 0 deletions deploy/ansible/data/config.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"block_store_path" : "/tmp/block_store/",
"torii_port" : 50051,
"internal_port" : 10001,
"pg_opt" : "host=iroha_postgres port=5432 user=iroha password=aaa",
"redis_host" : "iroha_redis",
"redis_port" : 6379,
"max_proposal_size" : 10,
"proposal_delay" : 5000,
"vote_delay" : 5000,
"load_delay" : 5000
}
36 changes: 36 additions & 0 deletions deploy/ansible/generate_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import optparse
from pathlib import Path


home = str(Path.home())

parser = optparse.OptionParser()

parser.add_option('-p', '--postgres-password',
help="postgress password")

parser.add_option('-u', '--postgres-user',
help="postgress user")


options, args = parser.parse_args()

if not options.postgres_password or not options.postgres_user:
raise ValueError("No user or pass provided")


with open(home+"/iroha_data/config.sample", "w") as f:
s = """{{
"block_store_path" : "/tmp/block_store/",
"torii_port" : 50051,
"internal_port" : 10001,
"pg_opt" : "host=iroha_postgres port=5432 user={} password={}",
"redis_host" : "iroha_redis",
"redis_port" : 6379,
"max_proposal_size" : 10,
"proposal_delay" : 5000,
"vote_delay" : 5000,
"load_delay" : 5000
}}""".format(options.postgres_user, options.postgres_password)

f.write(s)
1 change: 1 addition & 0 deletions deploy/ansible/host_vars/104.155.94.58
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
key: 0
1 change: 1 addition & 0 deletions deploy/ansible/host_vars/35.205.142.238
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
key: 1
11 changes: 4 additions & 7 deletions deploy/ansible/hosts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
[centos7]
[hosts]
104.155.94.58
35.205.142.238

[ubuntu16]
35.195.78.162
35.195.60.152
35.195.251.237
35.195.52.118
35.195.159.165

[all:vars]
ansible_ssh_user=iroha
#Does not check host ssh keys. If we check keys and recreate VM with the same IP, it will cause troubles.
host_key_checking=False
82 changes: 64 additions & 18 deletions deploy/ansible/provisioning.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
---
- hosts: all
- hosts: localhost
connection: local

tasks:
#It will generate a file for each host with its number, it is needed for iterating over hosts and running iroha
# with different keys
- name: Create Variable File for Each host
template: src=template.yml.j2 dest=host_vars/{{ item.1 }}
with_indexed_items: "{{ groups['hosts'] }}"


- hosts: hosts
vars:
user: iroha #your user on the remote machine
tmp: "{{9999999 | random | to_uuid }}"

postgres_host: iroha_postgres
postgres_user: '{{ user }}'
postgres_passwd: "{{ tmp[:8] }}"
postgres_user: iroha
postgres_port: 5432

redis_host: iroha_redis
redis_port: 6379

IROHA_HOME: '{{playbook_dir}}/../../'

pre_tasks:
- name: Load Host Specific Generated Variables
include_vars: host_vars/{{ inventory_hostname }}


tasks:

- name: Set postgres password
set_fact:
postgres_passwd: '{{ tmp[:32] }}'


- name: Test if docker is installed
command: docker --version
register: docker_exists
Expand Down Expand Up @@ -81,45 +104,68 @@
name: iroha_postgres
image: postgres:9.5
state: started
recreate: yes
restart: yes
env:
POSTGRES_USER: '{{ user }}'
POSTGRES_USER: '{{ postgres_user }}'
POSTGRES_PASSWORD: '{{ postgres_passwd }}'
networks:
- name: iroha_network
volumes:
- /opt/iroha/data/postgres:/var/lib/postgresql/data

- name: Run redis in docker
docker_container:
name: iroha_redis
image: redis:3.2.8
state: started
recreate: yes
restart: yes
networks:
- name: iroha_network

- name: Make data dir
file:
path: '{{ansible_env.HOME}}/iroha_data'
state: directory
mode: 0755
owner: '{{ user }}'

become: yes

- name: Copy peers list
copy:
src: '{{playbook_dir}}/data/peers.list'
dest: '{{ansible_env.HOME}}/iroha_data/peers.list'


- name: Copy config generator
copy:
src: '{{playbook_dir}}/generate_config.py'
dest: '{{ansible_env.HOME}}/iroha_data/generate_config.py'

- name: Generate config
command: python3 '{{ansible_env.HOME}}'/iroha_data/generate_config.py -p '{{ postgres_passwd }}' -u '{{ postgres_user }}'

- name: Run iroha in docker
docker_container:
name: iroha
image: hyperledger/iroha-docker
image: hyperledger/iroha-docker:test
state: started
restart: yes
recreate: yes
pull: yes
ports:
- "50051:50051"
- "10001:10001"
networks:
- name: iroha_network
volumes:
- ../:/opt/iroha
- ccache-data:/tmp/ccache
working_dir: /opt/iroha
- '{{ansible_env.HOME}}/iroha_data:/opt/iroha_data'
env:
POSTGRES_HOST={{ postgres_host }}
POSTGRES_PORT={{ postgres_port }}
POSTGRES_PASSWORD={{ postgres_passwd }}
POSTGRES_USER={{ postgres_user }}
REDIS_HOST={{ redis_host }}
REDIS_PORT={{ redis_port }}

command: /bin/bash -c "while sleep 1; do echo 1; done"
POSTGRES_HOST: '{{ postgres_host }}'
POSTGRES_PORT: '{{ postgres_port }}'
POSTGRES_PASSWORD: '{{ postgres_passwd }}'
POSTGRES_USER: '{{ postgres_user }}'
REDIS_HOST: '{{ redis_host }}'
REDIS_PORT: '{{ redis_port }}'
KEY: node{{ key }}

1 change: 1 addition & 0 deletions deploy/ansible/template.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
key: {{ item.0 }}
6 changes: 3 additions & 3 deletions docker/release/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM ubuntu:16.04

ENV IROHA_HOME /opt/iroha
ENV IROHA_BUILD /opt/iroha/build

ARG node

RUN apt-get update;\
Expand All @@ -14,7 +13,8 @@ RUN apt-get update;\
COPY iroha.deb /tmp/iroha.deb
RUN gdebi --non-interactive /tmp/iroha.deb

WORKDIR /opt/iroha
WORKDIR /opt/iroha_data

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/sbin/init"]
7 changes: 4 additions & 3 deletions docker/release/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
echo node$1
iroha-cli --genesis_block --peers_address /data/peers.list
irohad --genesis_block genesis.block --config /data/config.sample --keypair_name node$1
echo key=$KEY
echo $PWD
iroha-cli --genesis_block --peers_address peers.list
irohad --genesis_block genesis.block --config config.sample --keypair_name $KEY
Binary file added docker/release/iroha.deb
Binary file not shown.

0 comments on commit 76c2ac1

Please sign in to comment.