refactor to use Docker Compose file
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
b49b5dde83
commit
f446b09f19
|
@ -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
|
||||
#geth_account_addr: ~
|
||||
#geth_account_pass: ~
|
||||
#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
|
||||
geth_cont_tag: 'v1.10.1'
|
||||
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_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_enode_file: '{{ geth_cont_vol }}/keys/enode'
|
||||
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
|
||||
geth_rpc_enabled: true
|
||||
geth_rpc_addr: '127.0.0.1'
|
||||
geth_rpc_port: 8545
|
||||
# Available: admin, clique, debug, eth, les, miner, net, personal, rpc, txpool, web3
|
||||
geth_rcp_api: 'eth,net,web3,personal,admin'
|
||||
# Alternative IPC socket
|
||||
geth_ipc_path: '/data/geth.ipc'
|
||||
# Web Sockets API
|
||||
geth_websocket_enabled: true
|
||||
geth_websocket_port: '{{ geth_rpc_port + 1 | int }}'
|
||||
|
@ -54,15 +59,11 @@ geth_discovery_enabled: true
|
|||
geth_v5disc_enabled: true
|
||||
# List of trusted peers to connect to
|
||||
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
|
||||
geth_bootnodes: []
|
||||
|
||||
# Enable metrics
|
||||
geth_metrics_enabled: true
|
||||
geth_metrics_port: 6060
|
||||
|
||||
# Mining settings
|
||||
geth_miner_enabled: false
|
||||
geth_miner_threads: '{{ ansible_processor_vcpus }}'
|
||||
|
@ -92,8 +93,6 @@ geth_port: 30303
|
|||
geth_public_addr: '{{ ansible_host }}'
|
||||
|
||||
# Consul config
|
||||
geth_consul_address: '{{ ansible_host }}'
|
||||
geth_consul_rpc_address: '{{ ansible_local.tinc.vpn_ip }}'
|
||||
geth_consul_enabled: true
|
||||
geth_consul_default_tags:
|
||||
- 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_swap_limit: '{{ (geth_cont_mem_limit|int) + (ansible_swaptotal_mb * geth_cont_mem_ratio|float) | int }}'
|
||||
|
||||
# generic container beaviour
|
||||
cont_state: started
|
||||
cont_restart: false
|
||||
cont_recreate: false
|
||||
cont_restart_policy: always
|
||||
# general container management
|
||||
compose_recreate: 'smart'
|
||||
compose_state: 'present'
|
||||
compose_restart: false
|
||||
|
|
|
@ -18,37 +18,39 @@
|
|||
- name: Geth | Create Consul service definition
|
||||
include_role: name=consul-service
|
||||
vars:
|
||||
consul_config_name: '{{ geth_cont_name | replace("-", "_") }}'
|
||||
consul_config_name: '{{ geth_service_name | replace("-", "_") }}'
|
||||
consul_services:
|
||||
- name: '{{ geth_cont_name }}'
|
||||
- name: '{{ geth_service_name }}'
|
||||
tags: '{{ geth_consul_tags }}'
|
||||
port: '{{ geth_port }}'
|
||||
address: '{{ geth_consul_address }}'
|
||||
address: '{{ ansible_host }}'
|
||||
meta:
|
||||
env: '{{ env }}'
|
||||
stage: '{{ stage }}'
|
||||
node_addr: '{{ node_info.json.result.id }}'
|
||||
node_enode: '{{ node_info.json.result.enode }}'
|
||||
checks:
|
||||
- id: '{{ geth_cont_name }}-status'
|
||||
- id: '{{ geth_service_name }}-status'
|
||||
type: tcp
|
||||
tcp: '127.0.0.1:{{ geth_port }}'
|
||||
- name: '{{ geth_cont_name }}-rpc'
|
||||
|
||||
- name: '{{ geth_service_name }}-rpc'
|
||||
tags: '{{ geth_consul_tags + ["rpc"] }}'
|
||||
port: '{{ geth_rpc_port }}'
|
||||
address: '{{ geth_consul_rpc_address }}'
|
||||
address: '{{ ansible_local.tinc.vpn_ip }}'
|
||||
meta:
|
||||
env: '{{ env }}'
|
||||
stage: '{{ stage }}'
|
||||
checks:
|
||||
- id: '{{ geth_cont_name }}-rpc-status'
|
||||
- id: '{{ geth_service_name }}-rpc-status'
|
||||
type: script
|
||||
script: '{{ geth_sync_check_script }}'
|
||||
timeout: '5s'
|
||||
- name: '{{ geth_cont_name }}-ws'
|
||||
|
||||
- name: '{{ geth_service_name }}-ws'
|
||||
tags: '{{ geth_consul_tags + ["websocket"] }}'
|
||||
port: '{{ geth_websocket_port }}'
|
||||
address: '{{ geth_consul_rpc_address }}'
|
||||
address: '{{ ansible_local.tinc.vpn_ip }}'
|
||||
meta:
|
||||
env: '{{ env }}'
|
||||
stage: '{{ stage }}'
|
||||
|
|
|
@ -1,87 +1,26 @@
|
|||
---
|
||||
- name: Geth | Create the container
|
||||
docker_container:
|
||||
name: '{{ geth_cont_name }}'
|
||||
image: '{{ geth_cont_image }}'
|
||||
user: root
|
||||
- name: Geth | Create compose file
|
||||
template:
|
||||
src: 'docker-compose.yml.j2'
|
||||
dest: '{{ geth_compose_path }}'
|
||||
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
|
||||
restart_policy: '{{ cont_restart_policy }}'
|
||||
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'
|
||||
build: false
|
||||
|
|
|
@ -5,10 +5,9 @@
|
|||
owner: dockremap
|
||||
group: docker
|
||||
state: directory
|
||||
recurse: true
|
||||
with_items:
|
||||
- '{{ geth_data_path }}'
|
||||
- '{{ geth_keys_path }}'
|
||||
- '{{ geth_cont_vol }}/data'
|
||||
- '{{ geth_cont_vol }}/keys'
|
||||
|
||||
- name: Geth | Check if account file exists
|
||||
stat:
|
||||
|
@ -60,7 +59,7 @@
|
|||
|
||||
- name: Geth | Find newly generate account file
|
||||
find:
|
||||
paths: '{{ geth_keys_path }}'
|
||||
paths: '{{ geth_cont_vol }}/keys'
|
||||
patterns: 'UTC*'
|
||||
file_type: file
|
||||
register: found_account_files
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
host: 'localhost'
|
||||
port: '{{ geth_rpc_port }}'
|
||||
delay: 5
|
||||
connect_timeout: 10
|
||||
state: drained
|
||||
|
||||
- name: Geth | Get enode address
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue