Skip to content

Commit

Permalink
docker: drop RPC flag and add REST API flags
Browse files Browse the repository at this point in the history
Related to removal of RPC API support in:
waku-org/nwaku#2416

Signed-off-by: Jakub Sokołowski <[email protected]>
  • Loading branch information
jakubgs committed Feb 13, 2024
1 parent 0b25d83 commit 249d9ad
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 71 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ The configured domain URL should be in the format 'enrtree://<key>@<fqdn>', for
nim_waku_dns_disc_enabled: true
nim_waku_dns_disc_url: 'enrtree://AOFTICU2XWDULNLZGRMQS4RIZPAZEHYMV4FYHAPW563HNRAOERP7C@test.waku.nodes.status.im'
```
REST API is avalable to inspect the node and use protocols:
```yaml
nim_waku_rest_enabled: true
nim_waku_rest_addr: '127.0.0.1'
nim_waku_rest_port: 8645
nim_waku_rest_apis_enabled: ['admin', 'private']
```
For full docs see [API docs page](https://waku-org.github.io/waku-rest-api/).
# Usage
Expand Down
6 changes: 4 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ nim_waku_disc_v5_bootstrap_nodes: []
nim_waku_dns4_domain_name: '{{ ansible_hostname }}'

nim_waku_public_address: '{{ ansible_host }}'
nim_waku_rpc_tcp_addr: '127.0.0.1'
nim_waku_rpc_tcp_port: 8545
nim_waku_rest_enabled: true
nim_waku_rest_addr: '127.0.0.1'
nim_waku_rest_port: 8645
nim_waku_rest_apis_enabled: ['admin'] # admin, private
nim_waku_websock_port: 8000
nim_waku_disc_v5_port: 9000
nim_waku_p2p_tcp_port: 30303
Expand Down
16 changes: 7 additions & 9 deletions tasks/consul.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@
# Single-threated nature blocking responses due to DB I/O.
disabled: true

- id: '{{ nim_waku_cont_name }}-rpc'
name: '{{ nim_waku_consul_service_name }}-rpc'
port: '{{ nim_waku_rpc_tcp_port }}'
- id: '{{ nim_waku_cont_name }}-rest'
name: '{{ nim_waku_consul_service_name }}-rest'
port: '{{ nim_waku_rest_port }}'
address: '{{ ansible_local.wireguard.vpn_ip }}'
tags: ['env:{{ env }}', 'stage:{{ stage }}', 'nim', 'waku', 'rpc']
tags: ['env:{{ env }}', 'stage:{{ stage }}', 'nim', 'waku', 'rest']
checks:
- id: '{{ nim_waku_cont_name }}-rpc-health'
type: 'script'
script: '{{ nim_waku_cont_vol }}/rpc.sh get_waku_v2_debug_v1_info'
# Single-threated nature blocking responses due to DB I/O.
disabled: true
- id: '{{ nim_waku_cont_name }}-rest-health'
type: 'http'
http: 'http://localhost:{{ nim_waku_rest_port }}/debug/v1/version'

- name: Define Websocket service
when: nim_waku_websocket_enabled
Expand Down
6 changes: 3 additions & 3 deletions tasks/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
group: docker
mode: 0775

- name: Create script for calling RPC endpoint
- name: Create script for calling REST API
template:
src: 'rpc.sh.j2'
dest: '{{ nim_waku_cont_vol }}/rpc.sh'
src: 'api.sh.j2'
dest: '{{ nim_waku_cont_vol }}/api.sh'
owner: dockremap
group: docker
mode: 0755
Expand Down
22 changes: 8 additions & 14 deletions tasks/query.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
---
- name: 'Wait for RPC port to be available'
- name: 'Wait for REST port to be available'
wait_for:
port: '{{ nim_waku_rpc_tcp_port }}'
port: '{{ nim_waku_rest_port }}'
delay: 5

- name: 'Extract address of the node for Consul'
uri:
url: 'http://localhost:{{ nim_waku_rpc_tcp_port }}/'
method: POST
body:
method: 'get_waku_v2_debug_v1_info'
params: []
jsonrpc: '2.0'
id: 1
url: 'http://localhost:{{ nim_waku_rest_port }}/debug/v1/info'
status_code: 200
body_format: json
register: waku_info
ignore_errors: true

- name: Verify we got the node address
assert:
that: 'waku_info.json.result.listenAddresses is defined'
that: 'waku_info.json.listenAddresses is defined'
fail_msg: 'Did not receive Nim-Waku node address!'
quiet: true

- name: Extract LibP2P TCP address from list
set_fact:
nim_waku_libp2p_enr_uri: |-
{{ waku_info.json.result.enrUri }}
{{ waku_info.json.enrUri }}
nim_waku_libp2p_multiaddr: |-
{{ waku_info.json.result.listenAddresses
{{ waku_info.json.listenAddresses
| reject("contains", "/ws") | first }}
- name: Extract LibP2P WS address from list
when: nim_waku_websocket_enabled or nim_waku_websockify_enabled
set_fact:
nim_waku_libp2p_websocket: |-
{{ waku_info.json.result.listenAddresses
{{ waku_info.json.listenAddresses
| select("contains", "/ws") | first }}
- name: Extract peer ID from RPC response
- name: Extract peer ID from API response
set_fact:
nim_waku_peer_id: '{{ nim_waku_libp2p_multiaddr.split("/") | last }}'
27 changes: 27 additions & 0 deletions templates/api.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# vim: set ft=sh:

TIMEOUT="${TIMEOUT:-5}"
URL="http://localhost:{{ nim_waku_rest_port }}/"

# List known useful endpoints when called without arguments.
read -r -d '' ENDPOINTS << EOF
/debug/v1/info
/debug/v1/version
/admin/v1/peers
/health
EOF
if [[ $# == 0 ]]; then
echo "${ENDPOINTS}" | fzf \
--preview='{{ nim_waku_cont_vol }}/api.sh ${1}' \
--preview-window=bottom,22
exit 0
elif [[ $# > 1 ]]; then
echo "Too many arguments!" >&2
exit 1
fi
ENDPOINT="${1}"

# The jq script checks if error exists and adjusts exit code.
curl --silent --max-time "${TIMEOUT}" --show-error --fail-with-body \
"${URL}${ENDPOINT}" | jq
12 changes: 8 additions & 4 deletions templates/docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
- '{{ nim_waku_websocket_ssl_dir }}:{{ nim_waku_websocket_ssl_dir | mandatory }}'
{% endif %}
ports:
- '{{ nim_waku_rpc_tcp_addr }}:{{ nim_waku_rpc_tcp_port }}:{{ nim_waku_rpc_tcp_port }}/tcp'
- '{{ nim_waku_rest_addr }}:{{ nim_waku_rest_port }}:{{ nim_waku_rest_port }}/tcp'
- '{{ nim_waku_p2p_tcp_port }}:{{ nim_waku_p2p_tcp_port }}/tcp'
- '{{ nim_waku_p2p_udp_port }}:{{ nim_waku_p2p_udp_port }}/udp'
- '{{ nim_waku_metrics_port }}:{{ nim_waku_metrics_port }}/tcp'
Expand All @@ -44,7 +44,6 @@ services:
{% for protocol in nim_waku_protocols_enabled %}
--{{ protocol }}=true
{% endfor %}
--rpc-admin=true
--peer-persistence={{ nim_waku_peer_persistence | to_json }}
--keep-alive={{ nim_waku_keep_alive | to_json }}
--max-connections={{ nim_waku_p2p_max_connections }}
Expand Down Expand Up @@ -103,9 +102,14 @@ services:
{% endif %}
--nat=extip:{{ nim_waku_public_address }}
--log-level={{ nim_waku_log_level | upper }}
--rpc-port={{ nim_waku_rpc_tcp_port }}
--rpc-address=0.0.0.0
--tcp-port={{ nim_waku_p2p_tcp_port }}
--rest={{ nim_waku_rest_enabled }}
{% if nim_waku_rest_enabled %}
--rest-address={{ nim_waku_rest_addr }}
--rest-port={{ nim_waku_rest_port }}
--rest-admin={{ "admin" in nim_waku_rest_apis_enabled }}
--rest-private={{ "private" in nim_waku_rest_apis_enabled }}
{% endif %}
--metrics-server={{ nim_waku_metrics_enabled }}
--metrics-server-port={{ nim_waku_metrics_port }}
--metrics-server-address=0.0.0.0
Expand Down
39 changes: 0 additions & 39 deletions templates/rpc.sh.j2

This file was deleted.

0 comments on commit 249d9ad

Please sign in to comment.