Skip to content

Commit 1e38f1d

Browse files
committed
feat: role for our go node
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent f2c62f0 commit 1e38f1d

File tree

6 files changed

+299
-0
lines changed

6 files changed

+299
-0
lines changed

roles/go_node/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
go_node
2+
=========
3+
4+
This role deploys a Blink Labs Go Cardano node instance.
5+
6+
Requirements
7+
------------
8+
9+
Any pre-requisites that may not be covered by Ansible itself or the role should
10+
be mentioned here. For instance, if the role uses the EC2 module, it may be a
11+
good idea to mention in this section that the boto package is required.
12+
13+
Role Variables
14+
--------------
15+
16+
A description of the settable variables for this role should go here, including
17+
any variables that are in defaults/main.yml, vars/main.yml, and any variables
18+
that can/should be set via parameters to the role. Any variables that are read
19+
from other roles and/or the global scope (ie. hostvars, group vars, etc.)
20+
should be mentioned here as well.
21+
22+
Dependencies
23+
------------
24+
25+
A list of other roles hosted on Galaxy should go here, plus any details in
26+
regards to parameters that may need to be set for other roles, or variables
27+
that are used from other roles.
28+
29+
Example Playbook
30+
----------------
31+
32+
Including an example of how to use your role (for instance, with variables
33+
passed in as parameters) is always nice for users too:
34+
35+
```yaml
36+
- hosts: servers
37+
tasks:
38+
- include_role:
39+
name: blinklabs.cardano.go_node
40+
```
41+
42+
License
43+
-------
44+
45+
Apache 2.0
46+
47+
Author Information
48+
------------------
49+
50+
An optional section for the role authors to include contact information, or a
51+
website (HTML is not allowed).

roles/go_node/defaults/main.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
# Install method
3+
go_node_install_method: 'docker'
4+
5+
# Cardano node version
6+
go_node_version: 'main'
7+
8+
# Cardano network
9+
go_node_network: mainnet
10+
11+
# Base host directory for node data
12+
go_node_dir: /opt/cardano
13+
14+
# Config directory for host/container
15+
go_node_config_dir: '{{ go_node_dir }}/config'
16+
go_node_config_container_dir: '{{ go_node_config_dir }}'
17+
18+
# DB directory for host/container
19+
go_node_db_dir: '{{ go_node_dir }}/data'
20+
go_node_db_container_dir: '{{ go_node_db_dir }}'
21+
22+
# IPC directory for host/container
23+
go_node_ipc_dir: '{{ go_node_dir }}/ipc'
24+
go_node_ipc_container_dir: '{{ go_node_ipc_dir }}'
25+
26+
# Topology directory for host/container
27+
go_node_topology_dir: '{{ go_node_config_dir }}'
28+
go_node_topology_container_dir: '{{ go_node_topology_dir }}'
29+
30+
# Block producer keys directory for host/container
31+
go_node_keys_dir: '{{ go_node_config_dir }}/keys'
32+
go_node_keys_container_dir: '{{ go_node_keys_dir }}'
33+
34+
# User/group for file/directory ownership
35+
go_node_user: root
36+
go_node_group: root
37+
38+
# Docker image
39+
go_node_docker_image: 'ghcr.io/blinklabs-io/node:{{ go_node_version }}'
40+
41+
# Docker container name
42+
go_node_docker_container_name: node
43+
44+
# Port for host/container
45+
go_node_container_port: 3001
46+
go_node_port: '{{ go_node_container_port }}'
47+
48+
# Metrics port for host/container
49+
go_node_metrics_container_port: 12798
50+
go_node_metrics_port: '{{ go_node_metrics_container_port }}'
51+
52+
# Socket file name
53+
go_node_socket_name: node.socket
54+
55+
# Config
56+
go_node_manage_config: false # this currently controls mounting only
57+
go_node_config_file: '{{ go_node_config_container_dir }}/{{ go_node_network }}/config.json'
58+
59+
# Topology
60+
go_node_manage_topology: false
61+
go_node_topology_file: '{{ go_node_topology_container_dir }}/{{ go_node_network }}/topology.json'
62+
go_node_topology_use_ledger_after_slot: 128908821
63+
go_node_topology_localroots: []
64+
go_node_topology_publicroots: []
65+
# Adjust for non-mainnet deployments
66+
go_node_topology_bootstrap_peers:
67+
- address: 'backbone.cardano.iog.io'
68+
port: 3001
69+
- address: 'backbone.mainnet.emurgornd.com'
70+
port: 3001
71+
- address: 'backbone.mainnet.cardanofoundation.org'
72+
port: 3001
73+
74+
# Install chrony
75+
chrony_enabled: true
76+
77+
# Mithril configuration
78+
go_node_restore_snapshot: true
79+
go_node_snapshot_digest: 'latest'
80+
81+
# Block Producer (also controls mounts for keys)
82+
go_node_block_producer: false
83+
go_node_shelley_kes_key: '{{ go_node_keys_container_dir }}/kes.skey'
84+
go_node_shelley_opcert: '{{ go_node_keys_container_dir }}/node.cert'
85+
go_node_shelley_vrf_key: '{{ go_node_keys_container_dir }}/vrf.skey'

roles/go_node/meta/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
galaxy_info: {}
2+
3+
dependencies: []

roles/go_node/tasks/docker.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
- name: Initialize go_node_docker_volumes fact
3+
set_fact:
4+
go_node_docker_volumes: '{{ go_node_docker_volumes | default([]) + [item] }}'
5+
loop:
6+
- '{{ go_node_ipc_dir }}:{{ go_node_ipc_container_dir }}'
7+
- '{{ go_node_db_dir }}:{{ go_node_db_container_dir }}'
8+
9+
- name: Add config to go_node_docker_volumes fact
10+
set_fact:
11+
go_node_docker_volumes: '{{ go_node_docker_volumes | default([]) + [item] }}'
12+
loop:
13+
- '{{ go_node_config_file }}:{{ go_node_config_file }}'
14+
when: go_node_manage_config
15+
16+
- name: Add topology to go_node_docker_volumes fact
17+
set_fact:
18+
go_node_docker_volumes: '{{ go_node_docker_volumes | default([]) + [item] }}'
19+
loop:
20+
- '{{ go_node_topology_file }}:{{ go_node_topology_file }}'
21+
when: go_node_manage_topology
22+
23+
- name: Add keys to go_node_docker_volumes fact
24+
set_fact:
25+
go_node_docker_volumes: '{{ go_node_docker_volumes | default([]) + [item] }}'
26+
loop:
27+
- '{{ go_node_keys_dir }}:{{ go_node_keys_container_dir }}'
28+
when: go_node_block_producer | bool
29+
30+
- name: Create container
31+
docker_container:
32+
name: '{{ go_node_docker_container_name }}'
33+
image: '{{ go_node_docker_image }}'
34+
command:
35+
- run
36+
restart_policy: unless-stopped
37+
ports:
38+
- '{{ go_node_port }}:{{ go_node_container_port }}'
39+
- '{{ go_node_metrics_port }}:{{ go_node_metrics_container_port }}'
40+
env:
41+
CARDANO_BLOCK_PRODUCER: '{{ go_node_block_producer | string }}'
42+
CARDANO_CONFIG: '{{ go_node_config_file }}'
43+
CARDANO_DATABASE_PATH: '{{ go_node_db_container_dir }}'
44+
CARDANO_NETWORK: '{{ go_node_network }}'
45+
CARDANO_NODE_SOCKET_PATH: '{{ go_node_ipc_container_dir }}/{{ go_node_socket_name }}'
46+
CARDANO_PORT: '{{ go_node_port | string }}'
47+
CARDANO_SHELLEY_KES_KEY: '{{ go_node_shelley_kes_key }}'
48+
CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE: '{{ go_node_shelley_opcert }}'
49+
CARDANO_SHELLEY_VRF_KEY: '{{ go_node_shelley_vrf_key }}'
50+
CARDANO_SOCKET_PATH: '{{ go_node_ipc_container_dir }}/{{ go_node_socket_name }}'
51+
CARDANO_TOPOLOGY: '{{ go_node_topology_file }}'
52+
RESTORE_SNAPSHOT: '{{ go_node_restore_snapshot | string }}'
53+
SNAPSHOT_DIGEST: '{{ go_node_snapshot_digest }}'
54+
volumes: '{{ go_node_docker_volumes | list }}'

roles/go_node/tasks/main.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
- name: Check install method
3+
vars:
4+
_allowed_install_methods: ['docker']
5+
ansible.builtin.assert:
6+
that:
7+
- go_node_install_method in _allowed_install_methods
8+
fail_msg: 'The specified install method ({{ go_node_install_method }}) is not one of the allowed values ({{ _allowed_install_methods | join(", ") }})'
9+
10+
- name: Install chrony
11+
package:
12+
name: chrony
13+
state: present
14+
when: chrony_enabled
15+
16+
- name: Create directories for persistent data
17+
ansible.builtin.file:
18+
state: directory
19+
path: '{{ item }}'
20+
owner: '{{ go_node_user | string }}'
21+
group: '{{ go_node_group | string }}'
22+
mode: '0755'
23+
loop:
24+
- '{{ go_node_db_dir }}'
25+
- '{{ go_node_ipc_dir }}'
26+
27+
- name: Create directories for topology
28+
ansible.builtin.file:
29+
state: directory
30+
path: '{{ item }}'
31+
owner: '{{ go_node_user | string }}'
32+
group: '{{ go_node_group | string }}'
33+
mode: '0755'
34+
loop:
35+
- '{{ go_node_topology_dir }}'
36+
when: go_node_manage_topology
37+
38+
- name: Generate custom topology config
39+
template:
40+
dest: '{{ go_node_topology_file }}'
41+
src: custom-topology.json.j2
42+
owner: '{{ go_node_user | string }}'
43+
group: '{{ go_node_group | string }}'
44+
mode: 0644
45+
register: cardano_topology
46+
when: go_node_manage_topology
47+
48+
- name: Include docker-related tasks
49+
ansible.builtin.include_tasks: docker.yml
50+
when: go_node_install_method == 'docker'
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
{% set peer_count = go_node_topology_bootstrap_peers | length %}
3+
{% if peer_count > 0 %}
4+
"bootstrapPeers": [
5+
{% for peer in go_node_topology_bootstrap_peers %}
6+
{
7+
"address": "{{ peer.address }}",
8+
"port": {{ peer.port | int }}
9+
{% if loop.index == peer_count %}
10+
}
11+
{% else %}
12+
},
13+
{% endif %}
14+
{% endfor %}
15+
],
16+
{% endif %}
17+
"localRoots": [
18+
{
19+
"accessPoints": [
20+
{% set peer_count = go_node_topology_localroots | length %}
21+
{% for peer in go_node_topology_localroots %}
22+
{
23+
"address": "{{ peer.address }}",
24+
"port": {{ peer.port | int }}
25+
{% if loop.index == peer_count %}
26+
}
27+
{% else %}
28+
},
29+
{% endif %}
30+
{% endfor %}
31+
],
32+
"advertise": false,
33+
"trustable": false,
34+
"valency": 1
35+
}
36+
],
37+
"publicRoots": [
38+
{
39+
"accessPoints": [
40+
{% set peer_count = go_node_topology_publicroots | length %}
41+
{% for peer in go_node_topology_publicroots %}
42+
{
43+
"address": "{{ peer.address }}",
44+
"port": {{ peer.port | int }}
45+
{% if loop.index == peer_count %}
46+
}
47+
{% else %}
48+
},
49+
{% endif %}
50+
{% endfor %}
51+
],
52+
"advertise": false
53+
}
54+
],
55+
"useLedgerAfterSlot": {{ go_node_topology_use_ledger_after_slot }}
56+
}

0 commit comments

Comments
 (0)