-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathocean-node-quickstart.sh
More file actions
executable file
·776 lines (694 loc) · 27 KB
/
ocean-node-quickstart.sh
File metadata and controls
executable file
·776 lines (694 loc) · 27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
#!/usr/bin/env bash
#
# Copyright (c) 2026 Ocean Protocol contributors
# SPDX-License-Identifier: Apache-2.0
#
validate_hex() {
if [[ ! "$1" =~ ^0x[0-9a-fA-F]{64}$ ]]; then
echo "The private key seems invalid, exiting ..."
exit 1
fi
}
validate_address() {
if [[ ! "$1" =~ ^0x[0-9a-fA-F]{40}$ ]]; then
echo "Invalid wallet address, exiting!"
exit 1
fi
}
validate_port() {
if [[ ! "$1" =~ ^[0-9]+$ ]] || [ "$1" -le 1024 ] || [ "$1" -ge 65535 ]; then
echo "Invalid port number, it must be between 1024 and 65535."
exit 1
fi
}
validate_ip_or_fqdn() {
local input=$1
if [[ "$input" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
IFS='.' read -r -a octets <<< "$input"
for octet in "${octets[@]}"; do
if (( octet < 0 || octet > 255 )); then
echo "Invalid IPv4 address. Each octet must be between 0 and 255."
return 1
fi
done
if [[ "$input" =~ ^10\.|^172\.(1[6-9]|2[0-9]|3[0-1])\.|^192\.168\.|^169\.254\.|^100\.64\.|^198\.51\.100\.|^203\.0\.113\.|^224\.|^240\. ]]; then
echo "The provided IP address belongs to a private or non-routable range and might not be accessible from other nodes."
return 1
fi
elif [[ "$input" =~ ^[a-zA-Z0-9.-]+$ ]]; then
return 0
else
echo "Invalid input, must be a valid IPv4 address or FQDN."
return 1
fi
return 0
}
ensure_jq() {
if command -v jq >/dev/null 2>&1; then
echo "jq is already installed."
return 0
fi
echo "jq not found. Attempting to install..."
if [ "$(id -u)" -ne 0 ]; then
SUDO="sudo"
else
SUDO=""
fi
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
debian|ubuntu|linuxmint|pop|kali)
$SUDO apt-get update && $SUDO apt-get install -y jq
;;
fedora)
$SUDO dnf install -y jq
;;
centos|rhel|almalinux|rocky)
if command -v dnf >/dev/null; then
$SUDO dnf install -y epel-release
$SUDO dnf install -y jq
else
$SUDO yum install -y epel-release
$SUDO yum install -y jq
fi
;;
alpine)
$SUDO apk add jq
;;
arch|manjaro)
$SUDO pacman -Sy --noconfirm jq
;;
opensuse*|sles)
$SUDO zypper install -y jq
;;
*)
echo "Error: Unsupported distribution '$ID'. Please install jq manually."
return 1
;;
esac
else
echo "Error: Cannot detect OS distribution. Please install jq manually."
return 1
fi
if command -v jq >/dev/null 2>&1; then
echo "jq installed successfully."
return 0
else
echo "Error: Failed to install jq."
return 1
fi
}
get_public_ip() {
if command -v curl >/dev/null 2>&1; then
DETECTED_PUBLIC_IP=$(curl -s ifconfig.me)
fi
}
echo "Checking prerequisites (jq) are installed.."
ensure_jq
read -p "Do you have your private key for running the Ocean Node [ y/n ]: " has_key
if [ "$has_key" == "y" ]; then
read -p "Enter your private key: " PRIVATE_KEY
validate_hex "$PRIVATE_KEY"
else
read -p "Do you want me to create a private key for you [ y/n ]: " create_key
if [ "$create_key" == "n" ]; then
echo "Exiting! Private Key is a mandatory variable"
exit 1
fi
echo "Generating Private Key, please wait..."
output=$(head -c 32 /dev/urandom | xxd -p | tr -d '\n' | awk '{print "0x" $0}')
PRIVATE_KEY=$(echo "$output")
echo -e "Generated Private Key: \e[1;31m$PRIVATE_KEY\e[0m"
validate_hex "$PRIVATE_KEY"
fi
read -p "Please provide the wallet address to be added as Ocean Node admin account: " ALLOWED_ADMINS
validate_address "$ALLOWED_ADMINS"
echo -ne "Provide the HTTP_API_PORT value or accept the default (press Enter) [\e[1;32m8000\e[0m]: "
read HTTP_API_PORT
HTTP_API_PORT=${HTTP_API_PORT:-8000}
validate_port "$HTTP_API_PORT"
echo -ne "Provide the P2P_ipV4BindTcpPort or accept the default (press Enter) [\e[1;32m9000\e[0m]: "
read P2P_ipV4BindTcpPort
P2P_ipV4BindTcpPort=${P2P_ipV4BindTcpPort:-9000}
validate_port "$P2P_ipV4BindTcpPort"
echo -ne "Provide the P2P_ipV4BindWsPort or accept the default (press Enter) [\e[1;32m9001\e[0m]: "
read P2P_ipV4BindWsPort
P2P_ipV4BindWsPort=${P2P_ipV4BindWsPort:-9001}
validate_port "$P2P_ipV4BindWsPort"
echo -ne "Provide the P2P_ipV6BindTcpPort or accept the default (press Enter) [\e[1;32m9002\e[0m]: "
read P2P_ipV6BindTcpPort
P2P_ipV6BindTcpPort=${P2P_ipV6BindTcpPort:-9002}
validate_port "$P2P_ipV6BindTcpPort"
echo -ne "Provide the P2P_ipV6BindWsPort or accept the default (press Enter) [\e[1;32m9003\e[0m]: "
read P2P_ipV6BindWsPort
P2P_ipV6BindWsPort=${P2P_ipV6BindWsPort:-9003}
validate_port "$P2P_ipV6BindWsPort"
P2P_ENABLE_UPNP='false'
read -p "Enable UPnP (useful in case you can no set up port forwarding)? [ y/n ]: " enable_upnp
if [ "$enable_upnp" == "y" ]; then
P2P_ENABLE_UPNP='true'
fi
get_public_ip
if [ -n "$DETECTED_PUBLIC_IP" ]; then
echo -ne "Provide the public IPv4 address or FQDN where this node will be accessible (press Enter to accept detected address: "$DETECTED_PUBLIC_IP") ":
read P2P_ANNOUNCE_ADDRESS
P2P_ANNOUNCE_ADDRESS=${P2P_ANNOUNCE_ADDRESS:-$DETECTED_PUBLIC_IP}
else
read -p "Provide the public IPv4 address or FQDN where this node will be accessible: " P2P_ANNOUNCE_ADDRESS
fi
if [ -n "$P2P_ANNOUNCE_ADDRESS" ]; then
validate_ip_or_fqdn "$P2P_ANNOUNCE_ADDRESS"
if [ $? -ne 0 ]; then
echo "Invalid address. Exiting!"
exit 1
fi
if [[ "$P2P_ANNOUNCE_ADDRESS" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
# IPv4
P2P_ANNOUNCE_ADDRESSES='["/ip4/'$P2P_ANNOUNCE_ADDRESS'/tcp/'$P2P_ipV4BindTcpPort'", "/ip4/'$P2P_ANNOUNCE_ADDRESS'/tcp/'$P2P_ipV4BindWsPort'/ws", "/ip4/'$P2P_ANNOUNCE_ADDRESS'/tcp/'$P2P_ipV4BindWsPort'/tls/ws"]'
elif [[ "$P2P_ANNOUNCE_ADDRESS" =~ ^[a-zA-Z0-9.-]+$ ]]; then
# FQDN
P2P_ANNOUNCE_ADDRESSES='["/dns4/'$P2P_ANNOUNCE_ADDRESS'/tcp/'$P2P_ipV4BindTcpPort'", "/dns4/'$P2P_ANNOUNCE_ADDRESS'/tcp/'$P2P_ipV4BindWsPort'/ws", "/dns4/'$P2P_ANNOUNCE_ADDRESS'/tcp/'$P2P_ipV4BindWsPort'/tls/ws"]'
fi
else
P2P_ANNOUNCE_ADDRESSES=''
echo "No input provided, the Ocean Node might not be accessible from other nodes."
fi
read -p "Do you want to run docker C2D jobs on your Ocean Node [ y/n ]: " run_c2d_jobs
if [ "$run_c2d_jobs" == "y" ]; then
echo "########################################################"
echo "### Docker Engine Compute Environments Configuration ###"
echo "########################################################"
echo "Check 'ComputeEnvironment' definition for more details on the format"
echo "_____________________________________________________"
echo ""
read -p "Do you want to add a specific docker environment configuration?
(Hint: You can enter multiple in JSON format) [ y/n ]: " c2d_env
if [ "$c2d_env" == "y" ]; then
read -p "Enter the array of docker environment(s): " DOCKER_COMPUTE_ENVIRONMENTS
fi
else
echo "Running node without docker C2D capabilities!"
fi
read -p "Do you want to enable TLS (HTTPS) for your Ocean Node [ y/n ]: " enable_tls
if [ "$enable_tls" == "y" ]; then
read -p "Enter the absolute path to your TLS certificate file: " HTTP_CERT_PATH
read -p "Enter the absolute path to your TLS private key file: " HTTP_KEY_PATH
if [ -z "$HTTP_CERT_PATH" ] || [ -z "$HTTP_KEY_PATH" ]; then
echo "Certificate and key paths are mandatory for TLS. Disabling TLS."
enable_tls="n"
fi
fi
# Set default compute environments if not already defined
if [ -z "$DOCKER_COMPUTE_ENVIRONMENTS" ]; then
echo "Setting default DOCKER_COMPUTE_ENVIRONMENTS configuration"
export DOCKER_COMPUTE_ENVIRONMENTS='[
{
"socketPath": "/var/run/docker.sock",
"environments": [
{
"storageExpiry": 604800,
"maxJobDuration": 36000,
"minJobDuration": 60,
"resources": [
{
"id": "disk",
"total": 10
}
],
"fees": {
"1": [
{
"feeToken": "0x123",
"prices": [
{
"id": "cpu",
"price": 1
}
]
}
]
},
"free": {
"maxJobDuration": 360000,
"minJobDuration": 60,
"maxJobs": 3,
"resources": [
{
"id": "cpu",
"max": 1
},
{
"id": "ram",
"max": 1
},
{
"id": "disk",
"max": 1
}
]
}
}
]
}
]'
fi
# GPU Detection and Integration
# Function to check for NVIDIA GPUs
get_nvidia_gpus() {
if command -v nvidia-smi &> /dev/null; then
nvidia-smi --query-gpu=name,uuid,driver_version,memory.total --format=csv,noheader | while IFS=, read -r name uuid driver_version memory_total; do
name=$(echo "$name" | xargs)
uuid=$(echo "$uuid" | xargs)
driver_version=$(echo "$driver_version" | xargs)
memory_total=$(echo "$memory_total" | xargs)
jq -c -n \
--arg name "$name" \
--arg uuid "$uuid" \
--arg driver_version "$driver_version" \
--arg memory_total "$memory_total" \
'{
description: $name,
driverVersion: (if $driver_version != "" then $driver_version else null end),
memoryTotal: (if $memory_total != "" then $memory_total else null end),
init: {
deviceRequests: {
Driver: "nvidia",
Devices: [$uuid]
}
}
} | del(.. | select(. == null))'
done
fi
}
get_driver_version() {
local module="$1"
local ver
ver=$(modinfo "$module" 2>/dev/null | awk '/^version:/ {print $2; exit}')
if [ -n "$ver" ]; then
echo "$ver"
return
fi
if modinfo "$module" 2>/dev/null | grep -q "^srcversion:"; then
uname -r
return
fi
}
get_intel_driver_version() {
# oneAPI / Level Zero runtime (Intel Arc)
local ver
ver=$(clinfo 2>/dev/null | awk '/Driver Version/ {print $NF; exit}')
[ -n "$ver" ] && { echo "$ver"; return; }
ver=$(dpkg -l 2>/dev/null | awk '/intel-level-zero-gpu/ {print $3; exit}')
[ -z "$ver" ] && ver=$(rpm -q --qf '%{VERSION}' intel-level-zero-gpu 2>/dev/null)
[ -n "$ver" ] && { echo "$ver"; return; }
get_driver_version "xe" || get_driver_version "i915"
}
get_amd_driver_version() {
local ver
ver=$(cat /opt/rocm/.info/version 2>/dev/null | head -n1)
[ -n "$ver" ] && { echo "ROCm $ver"; return; }
ver=$(rocm-smi --version 2>/dev/null | awk '/ROCm/ {print $NF; exit}')
[ -n "$ver" ] && { echo "$ver"; return; }
ver=$(dpkg -l 2>/dev/null | awk '/rocm-core/ {print $3; exit}')
[ -z "$ver" ] && ver=$(rpm -q --qf '%{VERSION}' rocm-core 2>/dev/null)
[ -n "$ver" ] && { echo "ROCm $ver"; return; }
get_driver_version "amdgpu"
}
get_amd_vram() {
local card_path="$1"
local real_device_path
real_device_path=$(readlink -f "$card_path/device")
local vram_bytes=""
for f in \
"$real_device_path/mem_info_vram_total" \
"$card_path/device/mem_info_vram_total"; do
if [ -r "$f" ]; then
vram_bytes=$(cat "$f" 2>/dev/null)
break
fi
done
if [ -n "$vram_bytes" ] && [ "$vram_bytes" -gt 0 ] 2>/dev/null; then
echo $(( vram_bytes / 1024 / 1024 )) MiB
fi
}
get_intel_vram() {
local card_path="$1"
local real_device_path
real_device_path=$(readlink -f "$card_path/device")
for f in \
"$real_device_path/drm/$(basename $card_path)/gt/gt0/mem_info_vram_total" \
"$real_device_path/mem_info_vram_total"; do
if [ -r "$f" ]; then
local bytes
bytes=$(cat "$f" 2>/dev/null)
if [ -n "$bytes" ] && [ "$bytes" -gt 0 ] 2>/dev/null; then
echo "$(( bytes / 1024 / 1024 )) MiB"
return
fi
fi
done
local slot
slot=$(basename "$real_device_path")
local raw
raw=$(lspci -s "$slot" -v 2>/dev/null | awk '/Memory at|prefetchable/ && /size=/ {
match($0, /size=([0-9]+[KMG])/, a); if (a[1]) { print a[1]; exit }
}')
if [ -n "$raw" ]; then
local num unit
num=$(echo "$raw" | tr -d 'KMG')
unit=$(echo "$raw" | tr -d '0-9')
case "$unit" in
K) echo "$(( num / 1024 )) MiB" ;;
M) echo "${num} MiB" ;;
G) echo "$(( num * 1024 )) MiB" ;;
esac
fi
}
# Declare the associative array (hashmap) globally
declare -A gpu_map
map_pci_to_primary() {
for card_path in /sys/class/drm/card*; do
[ -e "$card_path" ] || continue
real_device_path=$(readlink -f "$card_path/device")
pci_id=$(basename "$real_device_path")
card_name=$(basename "$card_path")
gpu_map["$pci_id"]="/dev/dri/$card_name"
done
}
# Function to check for other GPUs (AMD, Intel, etc.) via lspci
get_generic_gpus() {
if ! command -v lspci &> /dev/null; then
return
fi
map_pci_to_primary
lspci -mm -n -d ::0300 | while read -r line; do process_pci_line "$line"; done
lspci -mm -n -d ::0302 | while read -r line; do process_pci_line "$line"; done
}
process_pci_line() {
line="$1"
slot=$(echo "$line" | awk '{print $1}')
vendor_id_hex=$(echo "$line" | awk '{print $3}' | tr -d '"')
if [[ "$vendor_id_hex" == "10de" ]] && command -v nvidia-smi &> /dev/null; then
return
fi
full_info=$(lspci -s "$slot" -vmm)
vendor_name=$(echo "$full_info" | grep "^Vendor:" | cut -f2-)
device_name=$(echo "$full_info" | grep "^Device:" | cut -f2-)
description="$vendor_name $device_name"
pci_id="0000:$slot"
driver=""
if [[ "$vendor_id_hex" == "1002" ]]; then # AMD
driver="amdgpu"
elif [[ "$vendor_id_hex" = "8086" ]]; then # Intel
driver="intel"
fi
device_id=""
card_path=""
if [ -n "${gpu_map[$pci_id]}" ]; then
device_id="${gpu_map[$pci_id]}" # e.g. /dev/dri/card0
card_name=$(basename "$device_id")
card_path="/sys/class/drm/$card_name"
else
device_id="${pci_id}"
fi
local devices=()
local binds=()
local cap_add=()
local group_add=()
local ipc_mode="null"
local shm_size="null"
local security_opt="null"
if [ -n "$card_path" ] && [ -e "$card_path" ]; then
local real_device_path=$(readlink -f "$card_path/device")
local render_name=""
if [ -d "$real_device_path/drm" ]; then
render_name=$(ls "$real_device_path/drm" | grep "^renderD" | head -n 1)
fi
case "$vendor_id_hex" in
"1002") # AMD (0x1002)
local amd_driver_version
amd_driver_version=$(get_amd_driver_version)
local amd_memory_total
amd_memory_total=$(get_amd_vram "$card_path")
if [ -e "/dev/dxg" ]; then
devices+=("/dev/dxg")
else
devices+=("/dev/kfd")
fi
[ -n "$render_name" ] && devices+=("/dev/dri/$render_name")
devices+=("$device_id") # /dev/dri/cardX
[ -e "/opt/rocm/lib/libhsa-runtime64.so.1" ] && \
binds+=("/opt/rocm/lib/libhsa-runtime64.so.1:/opt/rocm/lib/libhsa-runtime64.so.1")
cap_add+=("SYS_PTRACE")
ipc_mode="\"host\""
shm_size="8589934592"
security_opt='{"seccomp": "unconfined"}'
;;
"8086") # Intel (0x8086)
local intel_driver_version
intel_driver_version=$(get_intel_driver_version)
local intel_memory_total
intel_memory_total=$(get_intel_vram "$card_path")
[ -n "$render_name" ] && devices+=("/dev/dri/$render_name")
devices+=("$device_id")
group_add+=("video" "render")
cap_add+=("SYS_ADMIN")
;;
esac
else
if [[ "$vendor_id_hex" == "1002" ]] || [[ "$vendor_id_hex" == "8086" ]]; then
if [[ "$device_id" == /dev/* ]]; then
devices+=("$device_id")
fi
fi
fi
json_devices=$(printf '%s\n' "${devices[@]}" | jq -R . | jq -s . | jq 'map(select(length > 0))')
json_binds=$(printf '%s\n' "${binds[@]}" | jq -R . | jq -s . | jq 'map(select(length > 0))')
json_cap=$(printf '%s\n' "${cap_add[@]}" | jq -R . | jq -s . | jq 'map(select(length > 0))')
json_group=$(printf '%s\n' "${group_add[@]}" | jq -R . | jq -s . | jq 'map(select(length > 0))')
if [ "$(echo "$json_devices" | jq length)" -eq 0 ]; then
json_devices="[\"$device_id\"]"
fi
local driver_version=""
local memory_total=""
case "$vendor_id_hex" in
"1002") driver_version="$amd_driver_version"; memory_total="$amd_memory_total" ;;
"8086") driver_version="$intel_driver_version"; memory_total="$intel_memory_total" ;;
esac
jq -c -n \
--arg desc "$description" \
--arg driver "$driver" \
--arg device_id "$device_id" \
--arg driver_version "$driver_version" \
--arg memory_total "$memory_total" \
--argjson dev "$json_devices" \
--argjson bind "$json_binds" \
--argjson cap "$json_cap" \
--argjson group "$json_group" \
--argjson sec "$security_opt" \
--argjson shm "$shm_size" \
--argjson ipc "$ipc_mode" \
'{
description: $desc,
driverVersion: (if $driver_version != "" then $driver_version else null end),
memoryTotal: (if $memory_total != "" then $memory_total else null end),
init: {
deviceRequests: {
Driver: (if $driver != "" then $driver else null end),
Devices: $dev,
Capabilities: [["gpu"]]
},
Binds: $bind,
CapAdd: $cap,
GroupAdd: $group,
SecurityOpt: $sec,
ShmSize: $shm,
IpcMode: $ipc
}
} | del(.. | select(. == null)) | del(.. | select(. == []))'
}
# Function to get all GPUs in JSON array format
get_all_gpus_json() {
(
get_nvidia_gpus
get_generic_gpus
) | jq -s '
group_by(.description) | map(
{
id: (.[0].description | ascii_downcase | gsub("[^a-z0-9]"; "-") | gsub("-+"; "-") | sub("^-"; "") | sub("-$"; "")),
description: .[0].description,
type: "gpu",
total: length,
driverVersion: (.[0].driverVersion // null),
memoryTotal: (.[0].memoryTotal // null),
platform: (if .[0].init.deviceRequests.Driver == "amdgpu" then "amd" else .[0].init.deviceRequests.Driver end),
init: (
if .[0].init.deviceRequests.Driver == "nvidia" then
{
deviceRequests: {
Driver: .[0].init.deviceRequests.Driver,
DeviceIDs: (map(.init.deviceRequests.Devices[]?) | unique),
Capabilities: [["gpu"]]
}
}
else
{
advanced: {
Driver: .[0].init.deviceRequests.Driver,
Devices: (map(.init.deviceRequests.Devices[]?) | unique),
Capabilities: [["gpu"]],
Binds: (map(.init.Binds[]?) | unique),
CapAdd: (map(.init.CapAdd[]?) | unique),
GroupAdd: (map(.init.GroupAdd[]?) | unique),
SecurityOpt: .[0].init.SecurityOpt,
ShmSize: .[0].init.ShmSize,
IpcMode: .[0].init.IpcMode
} | del(.. | select(. == null)) | del(.. | select(. == []))
}
end
)
} | del(.. | select(. == null)) | del(.. | select(. == []))
)
'
}
if command -v jq &> /dev/null; then
echo "Checking for GPUs..."
DETECTED_GPUS=$(get_all_gpus_json)
GPU_COUNT=$(echo "$DETECTED_GPUS" | jq 'length')
if [ "$GPU_COUNT" -gt 0 ]; then
echo "Detected $GPU_COUNT GPU type(s). Updating configuration..."
DOCKER_COMPUTE_ENVIRONMENTS=$(echo "$DOCKER_COMPUTE_ENVIRONMENTS" | jq --argjson gpus "$DETECTED_GPUS" '.[0].environments[0].resources += $gpus')
echo "GPUs added to Compute Environment resources."
else
echo "No GPUs detected."
fi
fi
echo $DOCKER_COMPUTE_ENVIRONMENTS
cat <<EOF > docker-compose.yml
services:
ocean-node:
image: oceanprotocol/ocean-node:latest
pull_policy: always
container_name: ocean-node
restart: on-failure
ports:
- "$HTTP_API_PORT:$HTTP_API_PORT"
- "$P2P_ipV4BindTcpPort:$P2P_ipV4BindTcpPort"
- "$P2P_ipV4BindWsPort:$P2P_ipV4BindWsPort"
- "$P2P_ipV6BindTcpPort:$P2P_ipV6BindTcpPort"
- "$P2P_ipV6BindWsPort:$P2P_ipV6BindWsPort"
environment:
PRIVATE_KEY: '$PRIVATE_KEY'
RPCS: '{"1":{"rpc":"https://ethereum-rpc.publicnode.com","fallbackRPCs":["https://rpc.ankr.com/eth","https://1rpc.io/eth","https://eth.api.onfinality.io/public"],"chainId":1,"network":"mainnet","chunkSize":100},"10":{"rpc":"https://mainnet.optimism.io","fallbackRPCs":["https://optimism-mainnet.public.blastapi.io","https://rpc.ankr.com/optimism","https://optimism-rpc.publicnode.com"],"chainId":10,"network":"optimism","chunkSize":100},"137":{"rpc":"https://polygon-rpc.com/","fallbackRPCs":["https://polygon-mainnet.public.blastapi.io","https://1rpc.io/matic","https://rpc.ankr.com/polygon"],"chainId":137,"network":"polygon","chunkSize":100},"23294":{"rpc":"https://sapphire.oasis.io","fallbackRPCs":["https://1rpc.io/oasis/sapphire"],"chainId":23294,"network":"sapphire","chunkSize":100},"23295":{"rpc":"https://testnet.sapphire.oasis.io","chainId":23295,"network":"sapphire-testnet","chunkSize":100},"11155111":{"rpc":"https://eth-sepolia.public.blastapi.io","fallbackRPCs":["https://1rpc.io/sepolia","https://eth-sepolia.g.alchemy.com/v2/demo"],"chainId":11155111,"network":"sepolia","chunkSize":100},"11155420":{"rpc":"https://sepolia.optimism.io","fallbackRPCs":["https://endpoints.omniatech.io/v1/op/sepolia/public","https://optimism-sepolia.blockpi.network/v1/rpc/public"],"chainId":11155420,"network":"optimism-sepolia","chunkSize":100}}'
DB_URL: 'http://typesense:8108/?apiKey=xyz'
IPFS_GATEWAY: 'https://ipfs.io/'
ARWEAVE_GATEWAY: 'https://arweave.net/'
# LOAD_INITIAL_DDOS: ''
# FEE_TOKENS: ''
# FEE_AMOUNT: ''
# ADDRESS_FILE: ''
# NODE_ENV: ''
# AUTHORIZED_DECRYPTERS: ''
# AUTHORIZED_DECRYPTERS_LIST: ''
# OPERATOR_SERVICE_URL: ''
# POLICY_SERVER_URL: ''
INTERFACES: '["HTTP","P2P"]'
# ALLOWED_VALIDATORS: ''
# ALLOWED_VALIDATORS_LIST: ''
# AUTHORIZED_PUBLISHERS: ''
# AUTHORIZED_PUBLISHERS_LIST: ''
# INDEXER_NETWORKS: '[]'
ALLOWED_ADMINS: '["$ALLOWED_ADMINS"]'
# ALLOWED_ADMINS_LIST: ''
# INDEXER_INTERVAL: ''
# RATE_DENY_LIST: ''
# MAX_REQ_PER_MINUTE: ''
# MAX_CONNECTIONS_PER_MINUTE: ''
# MAX_CHECKSUM_LENGTH: ''
# LOG_LEVEL: ''
HTTP_API_PORT: '$HTTP_API_PORT'
P2P_ENABLE_IPV4: 'true'
P2P_ENABLE_IPV6: 'false'
P2P_ipV4BindAddress: '0.0.0.0'
P2P_ipV4BindTcpPort: '$P2P_ipV4BindTcpPort'
P2P_ipV4BindWsPort: '$P2P_ipV4BindWsPort'
P2P_ipV6BindAddress: '::'
P2P_ipV6BindTcpPort: '$P2P_ipV6BindTcpPort'
P2P_ipV6BindWsPort: '$P2P_ipV6BindWsPort'
P2P_ANNOUNCE_ADDRESSES: '$P2P_ANNOUNCE_ADDRESSES'
# P2P_ANNOUNCE_PRIVATE: ''
# P2P_pubsubPeerDiscoveryInterval: ''
# P2P_dhtMaxInboundStreams: ''
# P2P_dhtMaxOutboundStreams: ''
# P2P_mDNSInterval: ''
# P2P_connectionsMaxParallelDials: ''
# P2P_connectionsDialTimeout: ''
P2P_ENABLE_UPNP: '$P2P_ENABLE_UPNP'
# P2P_ENABLE_AUTONAT: ''
P2P_ENABLE_CIRCUIT_RELAY_SERVER: false
P2P_ENABLE_CIRCUIT_RELAY_CLIENT: false
# P2P_BOOTSTRAP_NODES: ''
# P2P_FILTER_ANNOUNCED_ADDRESSES: ''
DOCKER_COMPUTE_ENVIRONMENTS: '$DOCKER_COMPUTE_ENVIRONMENTS'
ENABLE_BENCHMARK: true
$(
if [ "$enable_tls" == "y" ]; then
echo " HTTP_CERT_PATH: '/usr/src/app/certs/cert.pem'"
echo " HTTP_KEY_PATH: '/usr/src/app/certs/key.pem'"
fi
)
networks:
- ocean_network
volumes:
- node-sqlite:/usr/src/app/databases
- /var/run/docker.sock:/var/run/docker.sock
$(
if [ "$enable_tls" == "y" ]; then
echo " - $HTTP_CERT_PATH:/usr/src/app/certs/cert.pem:ro"
echo " - $HTTP_KEY_PATH:/usr/src/app/certs/key.pem:ro"
fi
)
depends_on:
- typesense
typesense:
image: typesense/typesense:26.0
container_name: typesense
ports:
- "8108:8108"
networks:
- ocean_network
volumes:
- typesense-data:/data
command: '--data-dir /data --api-key=xyz'
volumes:
typesense-data:
driver: local
node-sqlite:
driver: local
networks:
ocean_network:
driver: bridge
EOF
echo -e "\e[1;32mDocker Compose file has been generated successfully.\e[0m"
echo ""
echo -e "\e[1;32mYou are now ready to start your Ocean Node.\e[0m"
echo ""
echo -e "\e[1;32m1)\e[0m If further customization is required, edit the \e[1;32mdocker-compose.yml\e[0m file."
echo -e "For all available configurations, refer to the environment variables documentation:"
echo -e "\e[1;34mhttps://github.com/oceanprotocol/ocean-node/blob/main/docs/env.md\e[0m"
echo ""
echo -e "\e[1;32m2)\e[0m Start your Ocean Node by running the command:"
echo -e "\e[1;32mdocker-compose up -d\e[0m"
echo ""
echo -e "\e[1;32m3)\e[0m Allow and forward the following incoming TCP ports through the firewall to the Ocean Node host:"
echo -e "\e[1;32mHTTP API Port: $HTTP_API_PORT\e[0m"
echo -e "\e[1;32mP2P IPv4 TCP Port: $P2P_ipV4BindTcpPort\e[0m"
echo -e "\e[1;32mP2P IPv4 WebSocket Port: $P2P_ipV4BindWsPort\e[0m"
echo -e "\e[1;32mP2P IPv6 TCP Port: $P2P_ipV6BindTcpPort\e[0m"
echo -e "\e[1;32mP2P IPv6 WebSocket Port: $P2P_ipV6BindWsPort\e[0m"
echo ""
echo -e "\e[1;32m4)\e[0m If using SSL/TLS with a custom domain name, make sure to listen on host port 443 for the HTTP API, or use a reverse proxy with TLS offloading"
echo ""
echo -e "If your node is not reachable by other peers (NAT, no public IP, port forwarding issues),"
echo -e "refer to the networking guide for help with Dynamic DNS, port forwarding, and circuit relay:"
echo -e "\e[1;34mhttps://github.com/oceanprotocol/ocean-node/blob/main/docs/networking.md\e[0m"