forked from dxzenith/allora-worker-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
allora.sh
291 lines (254 loc) · 8.76 KB
/
allora.sh
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
#!/bin/bash
BOLD="\033[1m"
UNDERLINE="\033[4m"
DARK_YELLOW="\033[0;33m"
CYAN="\033[0;36m"
RESET="\033[0;32m"
execute_with_prompt() {
echo -e "${BOLD}Executing: $1${RESET}"
if eval "$1"; then
echo "Command executed successfully."
else
echo -e "${BOLD}${DARK_YELLOW}Error executing command: $1${RESET}"
exit 1
fi
}
echo -e "${BOLD}${UNDERLINE}${DARK_YELLOW}Requirement for running allora-worker-node${RESET}"
echo
echo -e "${BOLD}${DARK_YELLOW}Operating System : Ubuntu 22.04${RESET}"
echo -e "${BOLD}${DARK_YELLOW}CPU : Min of 1/2 core.${RESET}"
echo -e "${BOLD}${DARK_YELLOW}RAM : 2 to 4 GB.${RESET}"
echo -e "${BOLD}${DARK_YELLOW}Storage : SSD or NVMe with at least 5GB of space.${RESET}"
echo
echo -e "${CYAN}Do you meet all of these requirements? (Y/N):${RESET}"
read -p "" response
echo
if [[ ! "$response" =~ ^[Yy]$ ]]; then
echo -e "${BOLD}${DARK_YELLOW}Error: You do not meet the required specifications. Exiting...${RESET}"
echo
exit 1
fi
echo -e "${BOLD}${DARK_YELLOW}Updating system dependencies...${RESET}"
execute_with_prompt "sudo apt update -y && sudo apt upgrade -y"
echo
echo -e "${BOLD}${DARK_YELLOW}Installing packages...${RESET}"
execute_with_prompt "sudo apt install ca-certificates zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev curl git wget make jq build-essential pkg-config lsb-release libssl-dev libreadline-dev libffi-dev gcc screen unzip lz4 -y"
echo
echo -e "${BOLD}${DARK_YELLOW}Installing python3...${RESET}"
execute_with_prompt "sudo apt install python3 python3-pip -y"
echo
echo -e "${BOLD}${DARK_YELLOW}Installing Docker...${RESET}"
execute_with_prompt 'curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg'
echo
execute_with_prompt 'echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null'
echo
execute_with_prompt 'sudo apt-get update'
echo
execute_with_prompt 'sudo apt-get install docker-ce docker-ce-cli containerd.io -y'
echo
echo -e "${BOLD}${DARK_YELLOW}Checking docker version...${RESET}"
execute_with_prompt 'docker version'
echo
echo -e "${BOLD}${DARK_YELLOW}Installing Docker Compose...${RESET}"
VER=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep tag_name | cut -d '"' -f 4)
echo
execute_with_prompt 'sudo curl -L "https://github.com/docker/compose/releases/download/'"$VER"'/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose'
echo
execute_with_prompt 'sudo chmod +x /usr/local/bin/docker-compose'
echo
echo -e "${BOLD}${DARK_YELLOW}Checking docker-compose version...${RESET}"
execute_with_prompt 'docker-compose --version'
echo
if ! grep -q '^docker:' /etc/group; then
execute_with_prompt 'sudo groupadd docker'
echo
fi
execute_with_prompt 'sudo usermod -aG docker $USER'
echo
echo -e "${BOLD}${DARK_YELLOW}Installing Go...${RESET}"
execute_with_prompt 'cd $HOME'
echo
execute_with_prompt 'ver="1.21.3" && wget "https://golang.org/dl/go$ver.linux-amd64.tar.gz"'
echo
execute_with_prompt 'sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf "go$ver.linux-amd64.tar.gz"'
echo
execute_with_prompt 'rm "go$ver.linux-amd64.tar.gz"'
echo
execute_with_prompt 'echo "export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin" >> $HOME/.bash_profile'
echo
execute_with_prompt 'source $HOME/.bash_profile'
echo
echo -e "${BOLD}${DARK_YELLOW}Checking go version...${RESET}"
execute_with_prompt 'go version'
echo
echo -e "${BOLD}${UNDERLINE}${DARK_YELLOW}Installing Allorand...${RESET}"
git clone https://github.com/allora-network/allora-chain.git
cd allora-chain && make all
echo
echo -e "${BOLD}${DARK_YELLOW}Checking allorand version...${RESET}"
allorad version
echo
echo -e "${BOLD}${UNDERLINE}${DARK_YELLOW}Importing wallet...${RESET}"
allorad keys add testkey --recover
echo
echo "Request faucet to your wallet from this link: https://faucet.testnet-1.testnet.allora.network/"
echo
echo -e "${BOLD}${UNDERLINE}${DARK_YELLOW}Installing worker node...${RESET}"
git clone https://github.com/allora-network/basic-coin-prediction-node
cd basic-coin-prediction-node
mkdir worker-data
mkdir head-data
echo
echo -e "${BOLD}${DARK_YELLOW}Giving permissions...${RESET}"
sudo chmod -R 777 worker-data head-data
echo
echo -e "${BOLD}${DARK_YELLOW}Creating Head keys...${RESET}"
echo
sudo docker run -it --entrypoint=bash -v $(pwd)/head-data:/data alloranetwork/allora-inference-base:latest -c "mkdir -p /data/keys && (cd /data/keys && allora-keys)"
echo
sudo docker run -it --entrypoint=bash -v $(pwd)/worker-data:/data alloranetwork/allora-inference-base:latest -c "mkdir -p /data/keys && (cd /data/keys && allora-keys)"
echo
echo -e "${BOLD}${DARK_YELLOW}This is your Head ID:${RESET}"
cat head-data/keys/identity
echo
if [ -f docker-compose.yml ]; then
rm docker-compose.yml
echo "Removed existing docker-compose.yml file."
echo
fi
read -p "Enter HEAD_ID: " HEAD_ID
echo
read -p "Enter WALLET_SEED_PHRASE: " WALLET_SEED_PHRASE
echo
read -p "Enter TOPIC_ID: " TOPIC_ID
echo
echo -e "${BOLD}${UNDERLINE}${DARK_YELLOW}Generating docker-compose.yml file...${RESET}"
cat <<EOF > docker-compose.yml
version: '3'
services:
inference:
container_name: inference-basic-eth-pred
build:
context: .
command: python -u /app/app.py
ports:
- "8000:8000"
networks:
eth-model-local:
aliases:
- inference
ipv4_address: 172.22.0.4
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/inference/ETH"]
interval: 10s
timeout: 10s
retries: 12
volumes:
- ./inference-data:/app/data
updater:
container_name: updater-basic-eth-pred
build: .
environment:
- INFERENCE_API_ADDRESS=http://inference:8000
command: >
sh -c "
while true; do
python -u /app/update_app.py;
sleep 24h;
done
"
depends_on:
inference:
condition: service_healthy
networks:
eth-model-local:
aliases:
- updater
ipv4_address: 172.22.0.5
worker:
container_name: worker-basic-eth-pred
environment:
- INFERENCE_API_ADDRESS=http://inference:8000
- HOME=/data
build:
context: .
dockerfile: Dockerfile_b7s
entrypoint:
- "/bin/bash"
- "-c"
- |
if [ ! -f /data/keys/priv.bin ]; then
echo "Generating new private keys..."
mkdir -p /data/keys
cd /data/keys
allora-keys
fi
allora-node --role=worker --peer-db=/data/peerdb --function-db=/data/function-db \
--runtime-path=/app/runtime --runtime-cli=bls-runtime --workspace=/data/workspace \
--private-key=/data/keys/priv.bin --log-level=debug --port=9011 \
--boot-nodes=/ip4/172.22.0.100/tcp/9010/p2p/$HEAD_ID \
--allora-chain-key-name=testkey \
--allora-chain-restore-mnemonic='$WALLET_SEED_PHRASE' \
--allora-node-rpc-address=https://allora-rpc.testnet-1.testnet.allora.network \
--topic=allora-topic-$TOPIC_ID-worker --allora-chain-worker-mode=worker
volumes:
- ./worker-data:/data
working_dir: /data
depends_on:
- inference
- head
networks:
eth-model-local:
aliases:
- worker
ipv4_address: 172.22.0.10
head:
container_name: head-basic-eth-pred
image: alloranetwork/allora-inference-base-head:latest
environment:
- HOME=/data
entrypoint:
- "/bin/bash"
- "-c"
- |
if [ ! -f /data/keys/priv.bin ]; then
echo "Generating new private keys..."
mkdir -p /data/keys
cd /data/keys
allora-keys
fi
allora-node --role=head --peer-db=/data/peerdb --function-db=/data/function-db \
--runtime-path=/app/runtime --runtime-cli=bls-runtime --workspace=/data/workspace \
--private-key=/data/keys/priv.bin --log-level=debug --port=9010 --rest-api=:6000
ports:
- "6000:6000"
volumes:
- ./head-data:/data
working_dir: /data
networks:
eth-model-local:
aliases:
- head
ipv4_address: 172.22.0.100
networks:
eth-model-local:
driver: bridge
ipam:
config:
- subnet: 172.22.0.0/24
volumes:
inference-data:
worker-data:
head-data:
EOF
echo -e "${BOLD}${DARK_YELLOW}docker-compose.yml file generated successfully!${RESET}"
echo
echo -e "${BOLD}${UNDERLINE}${DARK_YELLOW}Building and starting Docker containers...${RESET}"
docker-compose build
docker-compose up -d
echo
echo -e "${BOLD}${DARK_YELLOW}Checking running Docker containers...${RESET}"
docker ps
echo
echo "${BOLD}${DARK_YELLOW}Follow me on Twitter @ZunXBT for one click node run guides !!${RESET}"
echo