refactor to use Docker Compose file

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2021-03-25 12:16:43 +01:00
parent b49b5dde83
commit f446b09f19
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
6 changed files with 143 additions and 122 deletions

View File

@ -1,32 +1,37 @@
--- ---
geth_service_name: 'geth'
geth_service_path: '/docker/{{ geth_service_name }}'
geth_compose_path: '{{ geth_service_path }}/docker-compose.yml'
# Security, json is optional # Security, json is optional
#geth_account_addr: ~ #geth_account_addr: ~
#geth_account_pass: ~ #geth_account_pass: ~
#geth_account_json: ~ #geth_account_json: ~
# account
geth_account_json_file: '{{ geth_cont_vol }}/keys/account.json'
geth_account_pass_file: '{{ geth_cont_vol }}/keys/account.pass'
geth_account_addr_file: '{{ geth_cont_vol }}/keys/account.addr'
# Container config # Container config
geth_cont_tag: 'v1.10.1' geth_cont_tag: 'v1.10.1'
geth_cont_image: 'ethereum/client-go:{{ geth_cont_tag }}' geth_cont_image: 'ethereum/client-go:{{ geth_cont_tag }}'
geth_cont_name: 'geth' geth_cont_name: '{{ geth_service_name }}-node'
geth_cont_vol: '{{ geth_service_path }}/node'
geth_cont_vol: '/docker/{{ geth_cont_name }}' geth_enode_file: '{{ geth_cont_vol }}/keys/enode'
geth_data_path: '{{ geth_cont_vol }}/data'
geth_keys_path: '{{ geth_cont_vol }}/keys'
# account
geth_account_json_file: '{{ geth_keys_path }}/account.json'
geth_account_pass_file: '{{ geth_keys_path }}/account.pass'
geth_account_addr_file: '{{ geth_keys_path }}/account.addr'
geth_enode_file: '{{ geth_keys_path }}/enode'
geth_sync_check_script: '/usr/local/bin/check_sync_{{ geth_cont_name | replace("-", "_") }}.sh' geth_sync_check_script: '/usr/local/bin/check_sync_{{ geth_cont_name | replace("-", "_") }}.sh'
# Enable metrics
geth_metrics_enabled: true
geth_metrics_port: 6060
# RPC port of administration # RPC port of administration
geth_rpc_enabled: true geth_rpc_enabled: true
geth_rpc_addr: '127.0.0.1' geth_rpc_addr: '127.0.0.1'
geth_rpc_port: 8545 geth_rpc_port: 8545
# Available: admin, clique, debug, eth, les, miner, net, personal, rpc, txpool, web3 # Available: admin, clique, debug, eth, les, miner, net, personal, rpc, txpool, web3
geth_rcp_api: 'eth,net,web3,personal,admin' geth_rcp_api: 'eth,net,web3,personal,admin'
# Alternative IPC socket
geth_ipc_path: '/data/geth.ipc'
# Web Sockets API # Web Sockets API
geth_websocket_enabled: true geth_websocket_enabled: true
geth_websocket_port: '{{ geth_rpc_port + 1 | int }}' geth_websocket_port: '{{ geth_rpc_port + 1 | int }}'
@ -54,15 +59,11 @@ geth_discovery_enabled: true
geth_v5disc_enabled: true geth_v5disc_enabled: true
# List of trusted peers to connect to # List of trusted peers to connect to
geth_trusted_peers: [] geth_trusted_peers: []
geth_trusted_peers_file: '{{ geth_data_path }}/trusted-nodes.json' geth_trusted_peers_file: '{{ geth_cont_vol }}/data/trusted-nodes.json'
# Custom bootnodes # Custom bootnodes
geth_bootnodes: [] geth_bootnodes: []
# Enable metrics
geth_metrics_enabled: true
geth_metrics_port: 6060
# Mining settings # Mining settings
geth_miner_enabled: false geth_miner_enabled: false
geth_miner_threads: '{{ ansible_processor_vcpus }}' geth_miner_threads: '{{ ansible_processor_vcpus }}'
@ -92,8 +93,6 @@ geth_port: 30303
geth_public_addr: '{{ ansible_host }}' geth_public_addr: '{{ ansible_host }}'
# Consul config # Consul config
geth_consul_address: '{{ ansible_host }}'
geth_consul_rpc_address: '{{ ansible_local.tinc.vpn_ip }}'
geth_consul_enabled: true geth_consul_enabled: true
geth_consul_default_tags: geth_consul_default_tags:
- geth - geth
@ -109,8 +108,7 @@ geth_cont_mem_ratio: 0.6
geth_cont_mem_limit: '{{ (ansible_memtotal_mb * geth_cont_mem_ratio|float) | int }}' geth_cont_mem_limit: '{{ (ansible_memtotal_mb * geth_cont_mem_ratio|float) | int }}'
geth_cont_swap_limit: '{{ (geth_cont_mem_limit|int) + (ansible_swaptotal_mb * geth_cont_mem_ratio|float) | int }}' geth_cont_swap_limit: '{{ (geth_cont_mem_limit|int) + (ansible_swaptotal_mb * geth_cont_mem_ratio|float) | int }}'
# generic container beaviour # general container management
cont_state: started compose_recreate: 'smart'
cont_restart: false compose_state: 'present'
cont_recreate: false compose_restart: false
cont_restart_policy: always

View File

@ -18,37 +18,39 @@
- name: Geth | Create Consul service definition - name: Geth | Create Consul service definition
include_role: name=consul-service include_role: name=consul-service
vars: vars:
consul_config_name: '{{ geth_cont_name | replace("-", "_") }}' consul_config_name: '{{ geth_service_name | replace("-", "_") }}'
consul_services: consul_services:
- name: '{{ geth_cont_name }}' - name: '{{ geth_service_name }}'
tags: '{{ geth_consul_tags }}' tags: '{{ geth_consul_tags }}'
port: '{{ geth_port }}' port: '{{ geth_port }}'
address: '{{ geth_consul_address }}' address: '{{ ansible_host }}'
meta: meta:
env: '{{ env }}' env: '{{ env }}'
stage: '{{ stage }}' stage: '{{ stage }}'
node_addr: '{{ node_info.json.result.id }}' node_addr: '{{ node_info.json.result.id }}'
node_enode: '{{ node_info.json.result.enode }}' node_enode: '{{ node_info.json.result.enode }}'
checks: checks:
- id: '{{ geth_cont_name }}-status' - id: '{{ geth_service_name }}-status'
type: tcp type: tcp
tcp: '127.0.0.1:{{ geth_port }}' tcp: '127.0.0.1:{{ geth_port }}'
- name: '{{ geth_cont_name }}-rpc'
- name: '{{ geth_service_name }}-rpc'
tags: '{{ geth_consul_tags + ["rpc"] }}' tags: '{{ geth_consul_tags + ["rpc"] }}'
port: '{{ geth_rpc_port }}' port: '{{ geth_rpc_port }}'
address: '{{ geth_consul_rpc_address }}' address: '{{ ansible_local.tinc.vpn_ip }}'
meta: meta:
env: '{{ env }}' env: '{{ env }}'
stage: '{{ stage }}' stage: '{{ stage }}'
checks: checks:
- id: '{{ geth_cont_name }}-rpc-status' - id: '{{ geth_service_name }}-rpc-status'
type: script type: script
script: '{{ geth_sync_check_script }}' script: '{{ geth_sync_check_script }}'
timeout: '5s' timeout: '5s'
- name: '{{ geth_cont_name }}-ws'
- name: '{{ geth_service_name }}-ws'
tags: '{{ geth_consul_tags + ["websocket"] }}' tags: '{{ geth_consul_tags + ["websocket"] }}'
port: '{{ geth_websocket_port }}' port: '{{ geth_websocket_port }}'
address: '{{ geth_consul_rpc_address }}' address: '{{ ansible_local.tinc.vpn_ip }}'
meta: meta:
env: '{{ env }}' env: '{{ env }}'
stage: '{{ stage }}' stage: '{{ stage }}'

View File

@ -1,87 +1,26 @@
--- ---
- name: Geth | Create the container - name: Geth | Create compose file
docker_container: template:
name: '{{ geth_cont_name }}' src: 'docker-compose.yml.j2'
image: '{{ geth_cont_image }}' dest: '{{ geth_compose_path }}'
user: root owner: 'dockremap'
group: 'docker'
mode: 0640
# Take into account additional docker-compose.yml files.
- name: Find all Docker Compose files
find:
paths: '{{ geth_service_path }}'
patterns: 'docker-compose*.yml'
recurse: false
register: geth_all_compose
- name: Geth | Create containers
docker_compose:
project_src: '{{ geth_service_path }}'
files: '{{ geth_all_compose.files | map(attribute="path") | list }}'
state: '{{ compose_state }}'
restarted: '{{ compose_restart }}'
recreate: '{{ compose_recreate | default("smart") }}'
pull: true pull: true
restart_policy: '{{ cont_restart_policy }}' build: false
state: '{{ cont_state }}'
recreate: '{{ cont_recreate }}'
restart: '{{ cont_restart }}'
# some limits due to statusd hogging resources
memory: '{{ geth_cont_mem_limit }}m'
memory_swap: '{{ geth_cont_swap_limit }}m'
ports:
- '{{ geth_port }}:{{ geth_port }}/tcp'
- '{{ geth_port }}:{{ geth_port }}/udp'
- '{{ geth_metrics_port }}:{{ geth_metrics_port }}/tcp'
- '{{ geth_websocket_port }}:{{ geth_websocket_port }}/tcp'
- '{{ geth_rpc_addr }}:{{ geth_rpc_port }}:{{ geth_rpc_port }}'
labels:
# These are just for documentation
org.ethereum.geth.network_name: '{{ geth_network_name }}'
command: |
{% if geth_network_name != "mainnet" %}
--{{ geth_network_name }}
{% endif %}
{% if not geth_discovery_enabled %}
--nodiscover
{% endif %}
{% if geth_v5disc_enabled %}
--v5disc
{% endif %}
--syncmode={{ geth_sync_mode }}
{% if geth_sync_mode != 'light' %}
--light.serve={{ geth_light_serv }}
{% endif %}
{% if geth_miner_enabled %}
--mine
--miner.threads="{{ geth_miner_threads }}"
--miner.etherbase="{{ geth_miner_account | mandatory }}"
{% endif %}
{% if geth_whisper_enabled %}
--shh
--shh.pow={{ geth_whisper_pow }}
{% endif %}
{% if geth_metrics_enabled %}
--metrics
--metrics.addr=0.0.0.0
--metrics.port={{ geth_metrics_port }}
{% endif %}
{% if geth_cache_size %}
--cache={{ geth_cache_size }}
{% endif %}
--nousb
--verbosity={{ geth_log_level_id }}
--maxpeers={{ geth_max_peers }}
--maxpendpeers="{{ geth_max_pend_peers }}"
--port={{ geth_port }}
--nat=extip:{{ geth_public_addr }}
--unlock={{ geth_account_addr }}
--allow-insecure-unlock
--datadir=/data
--password=/keys/account.pass
--keystore=/keys
{% if geth_rpc_enabled %}
--http
--http.addr=0.0.0.0
--http.port={{ geth_rpc_port }}
--http.vhosts={{ geth_aliases | join(",") }}
--http.api={{ geth_rcp_api }}
--ipcpath={{ geth_ipc_path }}
{% endif %}
{% if geth_websocket_enabled %}
--ws
--ws.addr=0.0.0.0
--ws.port={{ geth_websocket_port }}
--ws.api={{ geth_websocket_api }}
--ws.origins='{{ geth_websocket_origins }}'
{% endif %}
{% if (geth_bootnodes|length) > 0 %}
--bootnodes="{{ geth_bootnodes | join(',') }}"
{% endif %}
volumes:
- '{{ geth_cont_vol }}/keys:/keys:rw'
# WARNING: This assumes /data is mounted, see bootstrap role
- '{{ geth_data_path }}:/data:rw'

View File

@ -5,10 +5,9 @@
owner: dockremap owner: dockremap
group: docker group: docker
state: directory state: directory
recurse: true
with_items: with_items:
- '{{ geth_data_path }}' - '{{ geth_cont_vol }}/data'
- '{{ geth_keys_path }}' - '{{ geth_cont_vol }}/keys'
- name: Geth | Check if account file exists - name: Geth | Check if account file exists
stat: stat:
@ -60,7 +59,7 @@
- name: Geth | Find newly generate account file - name: Geth | Find newly generate account file
find: find:
paths: '{{ geth_keys_path }}' paths: '{{ geth_cont_vol }}/keys'
patterns: 'UTC*' patterns: 'UTC*'
file_type: file file_type: file
register: found_account_files register: found_account_files

View File

@ -4,6 +4,7 @@
host: 'localhost' host: 'localhost'
port: '{{ geth_rpc_port }}' port: '{{ geth_rpc_port }}'
delay: 5 delay: 5
connect_timeout: 10
state: drained state: drained
- name: Geth | Get enode address - name: Geth | Get enode address

View File

@ -0,0 +1,82 @@
---
version: '3.7'
services:
geth:
container_name: '{{ geth_cont_name }}'
image: '{{ geth_cont_image }}'
user: root
restart: 'always'
mem_limit: '{{ geth_cont_mem_limit }}m'
memswap_limit: '{{ geth_cont_swap_limit }}m'
ports:
- '{{ geth_port }}:{{ geth_port }}/tcp'
- '{{ geth_port }}:{{ geth_port }}/udp'
- '{{ geth_metrics_port }}:{{ geth_metrics_port }}/tcp'
- '{{ geth_websocket_port }}:{{ geth_websocket_port }}/tcp'
- '{{ geth_rpc_addr }}:{{ geth_rpc_port }}:{{ geth_rpc_port }}'
labels:
# These are just for documentation
org.ethereum.geth.network_name: '{{ geth_network_name }}'
volumes:
- '{{ geth_cont_vol }}/keys:/keys:rw'
- '{{ geth_cont_vol }}/data:/data:rw'
command: |
{% if geth_network_name != "mainnet" %}
--{{ geth_network_name }}
{% endif %}
{% if not geth_discovery_enabled %}
--nodiscover
{% endif %}
{% if geth_v5disc_enabled %}
--v5disc
{% endif %}
--syncmode={{ geth_sync_mode }}
{% if geth_sync_mode != 'light' %}
--light.serve={{ geth_light_serv }}
{% endif %}
{% if geth_miner_enabled %}
--mine
--miner.threads="{{ geth_miner_threads }}"
--miner.etherbase="{{ geth_miner_account | mandatory }}"
{% endif %}
{% if geth_whisper_enabled %}
--shh
--shh.pow={{ geth_whisper_pow }}
{% endif %}
{% if geth_metrics_enabled %}
--metrics
--metrics.addr=0.0.0.0
--metrics.port={{ geth_metrics_port }}
{% endif %}
{% if geth_cache_size %}
--cache={{ geth_cache_size }}
{% endif %}
{% if geth_rpc_enabled %}
--http
--http.addr=0.0.0.0
--http.port={{ geth_rpc_port }}
--http.vhosts={{ geth_aliases | join(",") }}
--http.api={{ geth_rcp_api }}
--ipcpath=/data/geth.ipc
{% endif %}
{% if geth_websocket_enabled %}
--ws
--ws.addr=0.0.0.0
--ws.port={{ geth_websocket_port }}
--ws.api={{ geth_websocket_api }}
--ws.origins='{{ geth_websocket_origins }}'
{% endif %}
{% if (geth_bootnodes|length) > 0 %}
--bootnodes="{{ geth_bootnodes | join(',') }}"
{% endif %}
--nousb
--verbosity={{ geth_log_level_id }}
--maxpeers={{ geth_max_peers }}
--maxpendpeers="{{ geth_max_pend_peers }}"
--port={{ geth_port }}
--nat=extip:{{ geth_public_addr }}
--unlock={{ geth_account_addr }}
--allow-insecure-unlock
--datadir=/data
--password=/keys/account.pass
--keystore=/keys