support running init before container creation

This allows for providing a custom genesis config file.

For more details see:
https://github.com/status-im/infra-nimbus/issues/53

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2021-04-29 13:13:13 +02:00
parent 8d2eeb8961
commit 27ff1d257b
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
4 changed files with 52 additions and 1 deletions

View File

@ -47,7 +47,7 @@ geth_websocket_port: '{{ geth_rpc_port + 1 | int }}'
geth_websocket_api: 'eth,net,web3,personal,admin'
geth_websocket_origins: 'localhost'
# Sync mode: full, fast, light
# Sync mode: full, fast, light, snap
geth_sync_mode: 'light'
# Maximum number of untrusted peers that can connect
geth_max_peers: 50
@ -64,6 +64,12 @@ geth_trusted_peers_file: '{{ geth_cont_vol }}/data/trusted-nodes.json'
# Any additional flags you want to provide
geth_extra_flags: []
# Some custom testnets require a custom init
geth_init_enabled: false
geth_init_genesis_path: '{{ geth_cont_vol }}/genesis.json'
#geth_init_url: ~
#geth_init_sha256: ~
# Custom bootnodes
geth_bootnodes: []

View File

@ -44,6 +44,7 @@
docker_container:
name: '{{ geth_cont_name }}'
image: '{{ geth_cont_image }}'
detach: false
pull: true
auto_remove: yes
command: |

42
tasks/init.yml Normal file
View File

@ -0,0 +1,42 @@
---
- name: Download genesis config file
get_url:
url: '{{ geth_init_url | mandatory }}'
dest: '{{ geth_init_genesis_path | mandatory }}'
checksum: 'sha256: {{ geth_init_sha256 | mandatory }}'
owner: dockremap
group: docker
mode: 0644
- name: Check if chaindata was created
stat:
path: '{{ geth_cont_vol }}/data/geth/chaindata'
register: geth_chaindata_dir_before
- name: Initialize network definition
when: not geth_chaindata_dir_before.stat.exists
block:
- name: Run init command with config
docker_container:
name: '{{ geth_cont_name }}-init'
image: '{{ geth_cont_image }}'
user: root
detach: false
auto_remove: true
volumes:
- '{{ geth_cont_vol }}/keys:/keys:rw'
- '{{ geth_cont_vol }}/data:/data:rw'
- '{{ geth_init_genesis_path }}:/genesis.json:rw'
command: |
{{ geth_extra_flags | join(" ") }} --datadir=/data init /genesis.json
- name: Check if chaindata was created
stat:
path: '{{ geth_cont_vol }}/data/geth/chaindata'
register: geth_chaindata_dir_after
- name: Verify chaindata folder was created
assert:
that: '{{ geth_chaindata_dir_after.stat.exists }}'
fail_msg: 'Failed to init node genesis state!'
quiet: true

View File

@ -2,6 +2,8 @@
- import_tasks: checks.yml
- import_tasks: generate.yml
- import_tasks: trusted_peers.yml
- import_tasks: init.yml
when: geth_init_enabled
- import_tasks: container.yml
- import_tasks: firewall.yml
- import_tasks: wrappers.yml