This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 297
Refactor Ansible role #2219
Open
bakhtin
wants to merge
3
commits into
develop
Choose a base branch
from
fix/iroha-docker-role
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactor Ansible role #2219
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# How many Iroha peers (containers) are deployed on each host. Can be set on a per-host level. | ||
# Minimum total nodes is 6 (5f+1) in order for consensus to work properly. | ||
# Minimum total nodes is 4 (3f+1) in order for consensus to work properly. | ||
# | ||
# Default: 6 | ||
replicas: 6 | ||
# Default: 4 | ||
iroha_replicas: 4 | ||
|
||
# Whether to use custom hostname for EACH container. | ||
# If set to `true`, Iroha peers will communicate using these hostnames. Hostnames should be set using | ||
|
@@ -11,39 +11,61 @@ replicas: 6 | |
# variable. Container and service names in Docker Compose files will be auto-generated. | ||
# | ||
# Default: false | ||
custom_hostnames: false | ||
iroha_custom_hostnames: false | ||
|
||
# Affects how Iroha peers are communicated. If set to `true`, Docker overlay network with that | ||
# name will be used. It must be created beforehand. The recommended way is to use Calico plugin | ||
# for Docker (projectcalico.org). | ||
# name will be used. It must be created beforehand. The recommended way is to use Swarm cluster | ||
# or create a network manually using a KV storage. | ||
# Setting it to `true` without creating the network will only work for a single host deployment | ||
# (Iroha peers will only be able to communicate within that host). Suitable for local-only | ||
# deployments for testing purposes. | ||
# | ||
# Default: false | ||
overlay_network: false | ||
iroha_overlay_network: false | ||
|
||
## Deployment configs | ||
container_basename: iroha | ||
iroha_container_basename: iroha | ||
# Path on a local machine for generated configs prior moving them on the remote | ||
config_local_dir: /tmp/iroha-ansible-conf | ||
iroha_config_local_dir: /tmp/iroha-ansible-conf | ||
# Path on a remote machine for generated configs | ||
deploy_dir: /opt/iroha-deploy | ||
iroha_deploy_dir: /opt/iroha-deploy | ||
# Overlay network name | ||
# If using overlay network plugin (like Calico) the network must be created prior running this role | ||
# The network will be created automatically if deploying locally or with `overlay_network` | ||
# The network will be created automatically if deploying locally or with `iroha_overlay_network` | ||
# set to `false` | ||
iroha_network_name: iroha-net | ||
|
||
# The role is incompatible with Iroha versions below RC2 since keys format has changed. | ||
# Apply the patch (files/old-keys-format.patch) if you need support for previous Iroha versions. | ||
iroha_docker_tag: 1.0.0_rc2 | ||
postgres_docker_tag: '9.5' | ||
iroha_docker_tag: 1.0.0_rc5 | ||
iroha_postgres_docker_tag: '9.5' | ||
|
||
## The block of variables that toggles certain tasks of the role | ||
# Toggle tasks in `init-vars.yml` file. Will initialize variables for container names, | ||
# Iroha hostnames, etc. No configs will be changed. | ||
# Default: true | ||
iroha_init_vars: true | ||
# Toggle tasks in `config-gen.yml` file. Will generate new keys for Iroha with a new Genesis | ||
# Block | ||
# Default: true | ||
iroha_generate_init_configs: true | ||
# Toggle tasks in `deploy.yml` file. Enable if you just need to update Iroha configs and Docker | ||
# Compose file | ||
# Default: true | ||
iroha_update_runtime_configs: true | ||
|
||
# Toggles usage of a custom Genesis Block. Useful if you have custom roles, users, permissions, | ||
# etc. The role will fill your custom Genesis Block with Iroha peers while preserving everything | ||
# else. | ||
# Default: false | ||
iroha_custom_genesis_block: false | ||
# Path to the custom Genesis Block. Used only when `iroha_custom_genesis_block` set to `true` | ||
iroha_custom_genesis_block_path: '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use a single variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As for me, it is not immediately obvious that setting just |
||
|
||
## Iroha config | ||
# This value will be used as a base peer port for Iroha container. E.g. setting `replicas` option to | ||
# This value will be used as a base peer port for Iroha container. E.g. setting `iroha_replicas` option to | ||
# 6 will generate Docker Compose file with port numbers starting from 10001 counting up to 10006. | ||
# If `custom_hostnames` set to `true` AND contains port numbers this option is ignored | ||
# If `iroha_custom_hostnames` set to `true` AND contains port numbers this option is ignored | ||
iroha_peer_port: 10001 | ||
# As above but for base Torii port | ||
iroha_torii_port: 50051 | ||
|
@@ -66,3 +88,4 @@ iroha_blockstore_path: /tmp/block_store | |
#iroha_mst_expiration_time: 1440 | ||
#iroha_max_rounds_delay: 3000 | ||
#iroha_stale_stream_max_rounds: 2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# handlers file for Iroha | ||
--- | ||
- name: restart Iroha | ||
docker_service: | ||
project_src: "{{ iroha_deploy_dir }}" | ||
pull: yes | ||
state: present | ||
recreate: always |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,63 @@ | ||
- block: | ||
- set_fact: | ||
iroha_nodes: [] | ||
iroha_all_nodes: [] | ||
|
||
- name: generate hostnames (no overlay) | ||
set_fact: | ||
iroha_nodes: "{{ iroha_nodes }} + [ '{{ inventory_hostname }}:{{ iroha_peer_port | int + item | int }}' ]" | ||
loop: "{{ range(0, replicas |int) | list }}" | ||
when: not custom_hostnames and not overlay_network | ||
|
||
- shell: "cat /dev/urandom | tr -cd [:xdigit:] | tr '[:upper:]' '[:lower:]' | head -c {{ 8 * replicas | int}}" | ||
register: random_hex | ||
when: not custom_hostnames and overlay_network | ||
|
||
- name: generate hostnames (overlay) | ||
set_fact: | ||
iroha_nodes: "{{ iroha_nodes }} + [ '{{ container_basename }}-{{ item }}-{{ random_hex.stdout[item|int*8:(item|int+1)*8-1] }}:{{ iroha_peer_port }}' ]" | ||
loop: "{{ range(0, replicas) | list }}" | ||
when: not custom_hostnames and overlay_network | ||
|
||
- name: generate hostnames (custom_hostnames) | ||
set_fact: | ||
iroha_nodes: "{{ iroha_nodes }} + [ '{% if item.split(':') | length < 2 %}{{ item }}:{{ iroha_peer_port | int + idx }}{% else %}{{ item }}{% endif %}' ]" | ||
when: custom_hostnames and hostnames is defined | ||
loop: "{{ hostnames }}" | ||
loop_control: | ||
index_var: idx | ||
|
||
- set_fact: | ||
iroha_peers_map: "{{ iroha_peers_map | default([]) }} + [ {{ {'hostname': item, 'human_hostname': 'c_' + item | regex_replace('\\.', '_') | regex_replace(':', '_'), 'peer_port': item.split(':')[1] } }} ]" | ||
loop: "{{ iroha_nodes }}" | ||
|
||
- debug: | ||
var: iroha_peers_map | ||
|
||
- set_fact: | ||
iroha_nodes: "{{ iroha_peers_map }}" | ||
|
||
- set_fact: | ||
iroha_all_nodes: "{{ iroha_all_nodes }} + {{ hostvars[item]['iroha_nodes'] }}" | ||
loop: "{{ ansible_play_hosts }}" | ||
- name: copy custom genesis block | ||
copy: | ||
src: "{{ iroha_custom_genesis_block_path }}" | ||
dest: "{{ role_path }}/files/genesis.block" | ||
run_once: yes | ||
when: iroha_custom_genesis_block | ||
failed_when: iroha_custom_genesis_block_path is not defined | ||
|
||
- name: generate Iroha configs | ||
command: "./config_gen.sh -p{{ iroha_all_nodes | join(',', attribute='hostname') }} -o{{ config_local_dir }} -f" | ||
command: "./config_gen.sh -p{{ iroha_all_nodes | join(',', attribute='hostname') }} -o{{ iroha_config_local_dir }} -f" | ||
run_once: yes | ||
args: | ||
chdir: "{{ role_path }}/files" | ||
|
||
- name: make config dirs | ||
file: | ||
path: "{{ config_local_dir }}/{{ inventory_hostname }}/conf/{{ item.human_hostname }}" | ||
path: "{{ iroha_config_local_dir }}/{{ inventory_hostname }}/conf/{{ item.human_hostname }}" | ||
state: directory | ||
loop: "{{ iroha_nodes }}" | ||
|
||
- name: move keys | ||
copy: | ||
src: "{{ config_local_dir }}/{{ item[0].hostname }}{{ item[1] }}" | ||
dest: "{{ config_local_dir }}/{{ inventory_hostname }}/conf/{{ item[0].human_hostname }}" | ||
src: "{{ iroha_config_local_dir }}/{{ item[0].hostname }}{{ item[1] }}" | ||
dest: "{{ iroha_config_local_dir }}/{{ inventory_hostname }}/conf/{{ item[0].human_hostname }}" | ||
loop: "{{ iroha_nodes | product(['.priv', '.pub']) | list }}" | ||
|
||
- name: move genesis.block | ||
copy: | ||
src: "{{ config_local_dir }}/genesis.block" | ||
dest: "{{ config_local_dir }}/{{ inventory_hostname }}/conf/{{ item.human_hostname }}" | ||
src: "{{ iroha_config_local_dir }}/genesis.block" | ||
dest: "{{ iroha_config_local_dir }}/{{ inventory_hostname }}/conf/{{ item.human_hostname }}" | ||
loop: "{{ iroha_nodes }}" | ||
|
||
- name: cleanup | ||
file: | ||
path: "{{ config_local_dir }}/{{ item[0].hostname }}{{ item[1] }}" | ||
path: "{{ iroha_config_local_dir }}/{{ item[0].hostname }}{{ item[1] }}" | ||
state: absent | ||
loop: "{{ iroha_nodes | product(['.priv', '.pub']) | list }}" | ||
|
||
- name: cleanup | ||
file: | ||
path: "{{ config_local_dir }}/genesis.block" | ||
path: "{{ iroha_config_local_dir }}/genesis.block" | ||
state: absent | ||
run_once: yes | ||
become: no | ||
delegate_to: localhost | ||
when: iroha_generate_init_configs | ||
tags: ["iroha-config-gen"] | ||
|
||
- name: create deploy dir | ||
file: | ||
state: directory | ||
path: "{{ iroha_deploy_dir }}/conf" | ||
tags: ["iroha-config-gen"] | ||
|
||
- name: copy config files | ||
synchronize: | ||
src: "{{ iroha_config_local_dir }}/{{ inventory_hostname }}/conf/" | ||
dest: "{{ iroha_deploy_dir }}/conf/" | ||
recursive: yes | ||
checksum: yes | ||
when: iroha_generate_init_configs | ||
tags: ["iroha-config-gen"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,37 @@ | ||
- name: create deploy dir | ||
file: | ||
state: directory | ||
path: "{{ deploy_dir }}/conf" | ||
|
||
- stat: | ||
path: "{{ deploy_dir }}/docker-compose.yml" | ||
register: docker_compose_file | ||
|
||
- name: stop Iroha | ||
docker_service: | ||
project_src: "{{ deploy_dir }}" | ||
project_name: ansible_iroha | ||
remove_volumes: yes | ||
state: absent | ||
when: docker_compose_file.stat.exists | ||
|
||
- name: remove Iroha network (overlay) | ||
docker_network: | ||
name: "{{ iroha_network_name }}" | ||
driver: overlay | ||
state: absent | ||
run_once: yes | ||
when: docker_compose_file.stat.exists and overlay_network | ||
|
||
- name: remove Iroha network | ||
docker_network: | ||
name: "{{ iroha_network_name }}" | ||
state: absent | ||
when: docker_compose_file.stat.exists and not overlay_network | ||
|
||
- name: generate Docker compose | ||
template: | ||
src: docker-compose.yml.j2 | ||
dest: "{{ deploy_dir }}/docker-compose.yml" | ||
|
||
- name: copy config files | ||
synchronize: | ||
src: "{{ config_local_dir }}/{{ inventory_hostname }}/conf/" | ||
dest: "{{ deploy_dir }}/conf/" | ||
recursive: yes | ||
delete: yes | ||
|
||
- name: generate config files | ||
template: | ||
src: config.docker.j2 | ||
dest: "{{ deploy_dir }}/conf/{{ item.human_hostname }}/config.docker" | ||
loop: "{{ iroha_nodes }}" | ||
|
||
- name: create Docker network | ||
docker_network: | ||
name: "{{ iroha_network_name }}" | ||
driver: overlay | ||
run_once: yes | ||
when: overlay_network | ||
|
||
- name: create Docker network | ||
docker_network: | ||
name: "{{ iroha_network_name }}" | ||
when: not overlay_network | ||
|
||
- name: pull Iroha | ||
command: docker-compose pull | ||
args: | ||
chdir: "{{ deploy_dir }}" | ||
changed_when: False | ||
|
||
- name: run Iroha | ||
docker_service: | ||
project_src: "{{ deploy_dir }}" | ||
project_name: ansible_iroha | ||
- block: | ||
- name: create deploy dir | ||
file: | ||
state: directory | ||
path: "{{ iroha_deploy_dir }}/conf" | ||
|
||
# Attachable overlay network cannot be created with a `docker_network` module | ||
- name: create Docker network | ||
shell: "docker network create -d overlay --attachable {{ iroha_network_name }} || true" | ||
when: iroha_overlay_network | ||
run_once: yes | ||
|
||
- name: create Docker network | ||
docker_network: | ||
name: "{{ iroha_network_name }}" | ||
when: not iroha_overlay_network | ||
|
||
- name: generate Docker Compose | ||
template: | ||
src: docker-compose.yml.j2 | ||
dest: "{{ iroha_deploy_dir }}/docker-compose.yml" | ||
notify: restart Iroha | ||
tags: ["iroha-deploy"] | ||
|
||
- name: generate config files | ||
template: | ||
src: config.docker.j2 | ||
dest: "{{ iroha_deploy_dir }}/conf/{{ item.human_hostname }}/config.docker" | ||
notify: restart Iroha | ||
loop: "{{ iroha_nodes }}" | ||
tags: ["iroha-deploy"] | ||
|
||
- name: run Iroha | ||
docker_service: | ||
project_src: "{{ iroha_deploy_dir }}" | ||
tags: ["iroha-deploy"] | ||
when: iroha_update_runtime_configs |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we bump version to postures 10?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The minimal supported version of Postgres is 9.5, AFAIK. It is used in CI to verify compatibility of each build. By using v9.5 we are confident that no breaking changes exist in later versions (though, they probably also play nice with Iroha. But we cannot say for sure).