From 793e9a66f7fd27a6ba00088fb861e866a6a2f7cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Sat, 23 Mar 2019 09:57:42 +0100 Subject: [PATCH] add consul service definition, fix volume paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- defaults/main.yml | 6 +++-- tasks/beacon_node.yml | 63 ++++++++++++++++++++++++------------------- tasks/main.yml | 11 ++++---- 3 files changed, 45 insertions(+), 35 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index eb1910e..bca5176 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,12 +1,14 @@ --- beacon_node_verbose: false -# https://github.com/status-im/nimbus/docker beacon_node_build_flavour: 'rlpx' beacon_node_network: 'testnet0' -beacon_node_cont_image: 'statusteam/nimbus_beacon_node:{{beacon_node_network}}-{{beacon_node_build_flavour}}' beacon_node_total_nodes: 1 +# Image source: https://github.com/status-im/nimbus/tree/master/docker/beacon_node +beacon_node_cont_tag: '{{ beacon_node_network }}-{{ beacon_node_build_flavour }}' +beacon_node_cont_image: 'statusteam/nimbus_beacon_node:{{ beacon_node_cont_tag }}' + beacon_node_cont_vol: '/docker/beacon_node' beacon_node_disovery_port: 9000 diff --git a/tasks/beacon_node.yml b/tasks/beacon_node.yml index 18f0e9d..2ca01ef 100644 --- a/tasks/beacon_node.yml +++ b/tasks/beacon_node.yml @@ -1,49 +1,58 @@ --- -- name: 'Create {{container_name}} container' +- name: 'Create container dir: {{ container_name }}' + file: + path: '/docker/{{ container_name }}/data' + state: directory + owner: dockremap + group: docker + +- name: 'Create container: {{ container_name }} {{ public_tcp_port }}' docker_container: - name: '{{container_name}}' - image: '{{beacon_node_cont_image}}' + name: '{{ container_name }}' + image: '{{ beacon_node_cont_image }}' pull: true restart_policy: always state: 'started' recreate: false restart: false ports: - - '127.0.0.1:{{public_tcp_port}}:{{beacon_node_listening_port}}' - - '127.0.0.1:{{public_udp_port}}:{{beacon_node_disovery_port}}/udp' - - '{{public_tcp_port}}:{{beacon_node_listening_port}}' - - '{{public_udp_port}}:{{beacon_node_disovery_port}}/udp' + - '{{ public_tcp_port }}:{{ beacon_node_listening_port }}' + - '{{ public_udp_port }}:{{ beacon_node_disovery_port }}/udp' command: | {% if beacon_node_verbose %} --logLevel=DEBUG {% endif %} - --network={{beacon_node_network}} - --tcpPort={{beacon_node_listening_port}} - --udpPort={{beacon_node_disovery_port}} + --network={{ beacon_node_network }} + --tcpPort={{ beacon_node_listening_port }} + --udpPort={{ beacon_node_disovery_port }} volumes: - - '{{beacon_node_cont_vol}}/node-{{index}}:/root/.cache/nimbus' + - '/docker/{{ container_name }}/data:/root/.cache/nimbus' -- name: 'Enable TCP port for beacon node {{index}}' +- name: 'Enable ports for: {{ container_name }}' iptables: - comment: 'TCP port for beacon node {{index}}' + comment: '{{ container_name }} {{ item.protocol }}' action: insert chain: DOCKER-USER jump: ACCEPT source: '0.0.0.0/0' - protocol: 'tcp' - destination_port: '{{public_tcp_port}}' - notify: - - Save iptables rules - -- name: 'Enable UDP port for beacon node {{index}}' - iptables: - comment: 'UDP port for beacon node {{index}}' - action: insert - chain: DOCKER-USER - jump: ACCEPT - source: '0.0.0.0/0' - protocol: 'udp' - destination_port: '{{public_udp_port}}' + protocol: '{{ item.protocol }}' + destination_port: '{{ item.por }}' + with_items: + - { protocol: 'tcp', port: '{{ public_tcp_port }}' } + - { protocol: 'udp', port: '{{ public_udp_port }}' } notify: - Save iptables rules +- name: 'Consul service definition - {{ container_name }}' + include_role: name=consul-service + vars: + consul_config_name: '{{ container_name | replace("-", "_") }}' + consul_services: + - id: '{{ container_name }}-{{ index }}' + name: '{{ container_name }}' + port: '{{ public_tcp_port }}' + tags: ['{{ env }}.{{ stage }}', 'beacon', 'nimbus'] + checks: + - id: beacon-node-health + type: tcp + tcp: 'localhost:{{ public_tcp_port }}' diff --git a/tasks/main.yml b/tasks/main.yml index 43c93bd..564b1f7 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,11 +1,10 @@ --- - include_tasks: beacon_node.yml vars: - public_tcp_port: '{{beacon_node_listening_port + loop_index}}' - public_udp_port: '{{beacon_node_listening_port + loop_index}}' - container_name: 'beacon-node-{{beacon_node_build_flavour}}-{{beacon_node_network}}-{{loop_index}}' - index: '{{loop_index}}' - loop: '{{range(0, beacon_node_total_nodes)|list}}' + public_tcp_port: '{{ beacon_node_listening_port + loop_index }}' + public_udp_port: '{{ beacon_node_disovery_port + loop_index }}' + container_name: 'beacon-node-{{ beacon_node_build_flavour }}-{{ beacon_node_network}}-{{loop_index }}' + index: '{{ loop_index }}' + loop: '{{ range(0, beacon_node_total_nodes) | list }}' loop_control: index_var: loop_index -