-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·289 lines (237 loc) · 9.63 KB
/
build.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
#!/bin/bash
# check if .env exists
if [ ! -f .env ]; then
echo ".env file not found, please create one!";
echo "creating .env file...";
cp env.example .env;
# ask user for SOURCE_RPC_URL and replace it in .env
if [ -z "$SOURCE_RPC_URL" ]; then
echo "Enter SOURCE_RPC_URL: ";
read SOURCE_RPC_URL;
sed -i'.backup' "s#<source-rpc-url>#$SOURCE_RPC_URL#" .env
fi
# ask user for SIGNER_ACCOUNT_ADDRESS and replace it in .env
if [ -z "$SIGNER_ACCOUNT_ADDRESS" ]; then
echo "Enter SIGNER_ACCOUNT_ADDRESS: ";
read SIGNER_ACCOUNT_ADDRESS;
sed -i'.backup' "s#<signer-account-address>#$SIGNER_ACCOUNT_ADDRESS#" .env
fi
# ask user for SIGNER_ACCOUNT_PRIVATE_KEY and replace it in .env
if [ -z "$SIGNER_ACCOUNT_PRIVATE_KEY" ]; then
echo "Enter SIGNER_ACCOUNT_PRIVATE_KEY: ";
read SIGNER_ACCOUNT_PRIVATE_KEY;
sed -i'.backup' "s#<signer-account-private-key>#$SIGNER_ACCOUNT_PRIVATE_KEY#" .env
fi
# ask user for SLOT_ID and replace it in .env
if [ -z "$SLOT_ID" ]; then
echo "Enter Your SLOT_ID (NFT_ID): ";
read SLOT_ID;
sed -i'.backup' "s#<slot-id>#$SLOT_ID#" .env
fi
# ask user for TELEGRAM_CHAT_ID and replace it in .env
if [ -z "$TELEGRAM_CHAT_ID" ]; then
echo "Enter Your TELEGRAM_CHAT_ID (Optional, leave blank to skip.): ";
read TELEGRAM_CHAT_ID;
sed -i'.backup' "s#<telegram-chat-id>#$TELEGRAM_CHAT_ID#" .env
fi
fi
echo "bootstrapping..."
./bootstrap.sh
source .env
export DOCKER_NETWORK_NAME="snapshotter-lite-v2-${SLOT_ID}"
# Use 172.18.0.0/16 as the base, which is within Docker's default pool
if [ -z "$SUBNET_THIRD_OCTET" ]; then
SUBNET_THIRD_OCTET=1
echo "SUBNET_THIRD_OCTET not found in .env, setting to default value ${SUBNET_THIRD_OCTET}"
fi
export DOCKER_NETWORK_SUBNET="172.18.${SUBNET_THIRD_OCTET}.0/24"
echo "Selected DOCKER_NETWORK_NAME: ${DOCKER_NETWORK_NAME}"
echo "Selected DOCKER_NETWORK_SUBNET: ${DOCKER_NETWORK_SUBNET}"
# Check if the first argument is "test"
if [ "$1" = "test" ]; then
echo "Running subnet calculation tests..."
# Test function for subnet calculation
test_subnet_calculation() {
local test_slot_id=$1
local expected_third_octet=$2
SLOT_ID=$test_slot_id
SUBNET_THIRD_OCTET=$((SLOT_ID % 256))
SUBNET="172.18.${SUBNET_THIRD_OCTET}.0/24"
if [ $SUBNET_THIRD_OCTET -eq $expected_third_octet ]; then
echo "Test passed for SLOT_ID $test_slot_id: $SUBNET"
else
echo "Test failed for SLOT_ID $test_slot_id: Expected 172.18.$expected_third_octet.0/24, got $SUBNET"
fi
}
# Run test cases
test_subnet_calculation 0 0
test_subnet_calculation 1 1
test_subnet_calculation 99 99
test_subnet_calculation 100 100
test_subnet_calculation 255 255
test_subnet_calculation 256 0
echo "Subnet calculation tests completed."
exit 0
fi
# check if ufw command exists
if [ -x "$(command -v ufw)" ]; then
# delete old blanket allow rule
ufw delete allow $LOCAL_COLLECTOR_PORT >> /dev/null
ufw allow from $DOCKER_NETWORK_SUBNET to any port $LOCAL_COLLECTOR_PORT
if [ $? -eq 0 ]; then
echo "ufw allow rule added for local collector port ${LOCAL_COLLECTOR_PORT} to allow connections from ${DOCKER_NETWORK_SUBNET}.\n"
else
echo "ufw firewall allow rule could not added for local collector port ${LOCAL_COLLECTOR_PORT} \
Please attempt to add it manually with the following command with sudo privileges: \
sudo ufw allow from $DOCKER_NETWORK_SUBNET to any port $LOCAL_COLLECTOR_PORT \
Then run ./build.sh again."
# exit script if ufw rule not added
exit 1
fi
else
echo "ufw command not found, skipping firewall rule addition for local collector port ${LOCAL_COLLECTOR_PORT}. \
If you are on a Linux VPS, please ensure that the port is open for connections from ${DOCKER_NETWORK_SUBNET} manually to ${LOCAL_COLLECTOR_PORT}."
fi
if [ -z "$OVERRIDE_DEFAULTS" ]; then
echo "setting default values...";
export PROST_RPC_URL="https://rpc-prost1m.powerloom.io"
export PROTOCOL_STATE_CONTRACT="0xE88E5f64AEB483d7057645326AdDFA24A3B312DF"
export DATA_MARKET_CONTRACT="0x0C2E22fe7526fAeF28E7A58c84f8723dEFcE200c"
export PROST_CHAIN_ID="11169"
fi
echo "testing before build...";
if [ -z "$SOURCE_RPC_URL" ]; then
echo "RPC URL not found, please set this in your .env!";
exit 1;
fi
if [ -z "$SIGNER_ACCOUNT_ADDRESS" ]; then
echo "SIGNER_ACCOUNT_ADDRESS not found, please set this in your .env!";
exit 1;
fi
if [ -z "$SIGNER_ACCOUNT_PRIVATE_KEY" ]; then
echo "SIGNER_ACCOUNT_ADDRESS not found, please set this in your .env!";
exit 1;
fi
echo "Found SOURCE RPC URL ${SOURCE_RPC_URL}"
echo "Found SIGNER ACCOUNT ADDRESS ${SIGNER_ACCOUNT_ADDRESS}";
if [ "$PROST_RPC_URL" ]; then
echo "Found PROST_RPC_URL ${PROST_RPC_URL}";
fi
if [ "$PROST_CHAIN_ID" ]; then
echo "Found PROST_CHAIN_ID ${PROST_CHAIN_ID}";
fi
if [ "$IPFS_URL" ]; then
echo "Found IPFS_URL ${IPFS_URL}";
fi
if [ "$PROTOCOL_STATE_CONTRACT" ]; then
echo "Found PROTOCOL_STATE_CONTRACT ${PROTOCOL_STATE_CONTRACT}";
fi
if [ "$WEB3_STORAGE_TOKEN" ]; then
echo "Found WEB3_STORAGE_TOKEN ${WEB3_STORAGE_TOKEN}";
fi
if [ "$SLACK_REPORTING_URL" ]; then
echo "Found SLACK_REPORTING_URL ${SLACK_REPORTING_URL}";
fi
if [ "$POWERLOOM_REPORTING_URL" ]; then
echo "Found POWERLOOM_REPORTING_URL ${POWERLOOM_REPORTING_URL}";
fi
if [ -z "$CORE_API_PORT" ]; then
export CORE_API_PORT=8002;
echo "CORE_API_PORT not found in .env, setting to default value ${CORE_API_PORT}";
else
echo "Found CORE_API_PORT ${CORE_API_PORT}";
fi
if [ -z "$LOCAL_COLLECTOR_PORT" ]; then
export LOCAL_COLLECTOR_PORT=50051;
echo "LOCAL_COLLECTOR_PORT not found in .env, setting to default value ${LOCAL_COLLECTOR_PORT}";
else
echo "Found LOCAL_COLLECTOR_PORT ${LOCAL_COLLECTOR_PORT}";
fi
if [ "$MAX_STREAM_POOL_SIZE" ]; then
echo "Found MAX_STREAM_POOL_SIZE ${MAX_STREAM_POOL_SIZE}";
else
export MAX_STREAM_POOL_SIZE=2
echo "MAX_STREAM_POOL_SIZE not found in .env, setting to default value ${MAX_STREAM_POOL_SIZE}";
fi
if [ -z "$STREAM_HEALTH_CHECK_TIMEOUT_MS" ]; then
export STREAM_HEALTH_CHECK_TIMEOUT_MS=5000
echo "STREAM_HEALTH_CHECK_TIMEOUT_MS not found in .env, setting to default value ${STREAM_HEALTH_CHECK_TIMEOUT_MS}";
else
echo "Found STREAM_HEALTH_CHECK_TIMEOUT_MS ${STREAM_HEALTH_CHECK_TIMEOUT_MS}";
fi
if [ -z "$STREAM_WRITE_TIMEOUT_MS" ]; then
export STREAM_WRITE_TIMEOUT_MS=5000
echo "STREAM_WRITE_TIMEOUT_MS not found in .env, setting to default value ${STREAM_WRITE_TIMEOUT_MS}";
else
echo "Found STREAM_WRITE_TIMEOUT_MS ${STREAM_WRITE_TIMEOUT_MS}";
fi
if [ -z "$MAX_WRITE_RETRIES" ]; then
export MAX_WRITE_RETRIES=3
echo "MAX_WRITE_RETRIES not found in .env, setting to default value ${MAX_WRITE_RETRIES}";
else
echo "Found MAX_WRITE_RETRIES ${MAX_WRITE_RETRIES}";
fi
if [ -z "$MAX_CONCURRENT_WRITES" ]; then
export MAX_CONCURRENT_WRITES=4
echo "MAX_CONCURRENT_WRITES not found in .env, setting to default value ${MAX_CONCURRENT_WRITES}";
else
echo "Found MAX_CONCURRENT_WRITES ${MAX_CONCURRENT_WRITES}";
fi
# check if ufw command exists
if [ -x "$(command -v ufw)" ]; then
# delete old blanket allow rule
ufw delete allow $LOCAL_COLLECTOR_PORT >> /dev/null
ufw allow from $DOCKER_NETWORK_SUBNET to any port $LOCAL_COLLECTOR_PORT
if [ $? -eq 0 ]; then
echo "ufw allow rule added for local collector port ${LOCAL_COLLECTOR_PORT} to allow connections from ${DOCKER_NETWORK_SUBNET}.\n"
else
echo "ufw firewall allow rule could not added for local collector port ${LOCAL_COLLECTOR_PORT} \
Please attempt to add it manually with the following command with sudo privileges: \
sudo ufw allow from $DOCKER_NETWORK_SUBNET to any port $LOCAL_COLLECTOR_PORT \
Then run ./build.sh again."
# exit script if ufw rule not added
exit 1
fi
else
echo "ufw command not found, skipping firewall rule addition for local collector port ${LOCAL_COLLECTOR_PORT}. \
If you are on a Linux VPS, please ensure that the port is open for connections from ${DOCKER_NETWORK_SUBNET} manually to ${LOCAL_COLLECTOR_PORT}."
fi
#fetch current git branch name
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Current branch is ${GIT_BRANCH}";
#if on main git branch, set image_tag to latest or use the branch name
if [ "$GIT_BRANCH" = "dockerify" ]; then
export IMAGE_TAG="dockerify"
else
export IMAGE_TAG="latest"
fi
echo "Building image with tag ${IMAGE_TAG}";
# Get the first command line argument
# Check if the first command line argument exists, and if not, assign it a default value
if [ -z "$1" ]; then
ARG1="yes_collector"
else
ARG1="no_collector"
fi
if [ "$ARG1" = "yes_collector" ]; then
COLLECTOR_PROFILE_STRING="--profile local-collector"
else
COLLECTOR_PROFILE_STRING=""
fi
if ! [ -x "$(command -v docker-compose)" ]; then
echo 'docker compose not found, trying to see if compose exists within docker';
# assign docker compose file according to $ARG1
docker compose -f docker-compose.yaml $COLLECTOR_PROFILE_STRING pull
if [ -n "$IPFS_URL" ]; then
docker compose -f docker-compose.yaml --profile ipfs $COLLECTOR_PROFILE_STRING up -V
else
docker compose -f docker-compose.yaml $COLLECTOR_PROFILE_STRING up -V
fi
else
docker-compose -f docker-compose.yaml $COLLECTOR_PROFILE_STRING pull
if [ -n "$IPFS_URL" ]; then
docker-compose -f docker-compose.yaml --profile ipfs $COLLECTOR_PROFILE_STRING up -V
else
docker-compose -f docker-compose.yaml $COLLECTOR_PROFILE_STRING up -V
fi
fi