-
Notifications
You must be signed in to change notification settings - Fork 1
/
launch.sh
executable file
·88 lines (68 loc) · 2.26 KB
/
launch.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
#!/bin/bash
# Initialize variables
client_port="8000"
registry_path="registry-200.txt"
latency_limit="150"
build=false
function usage() {
echo "Usage: $0 -p <port> -r <registry_path> -l <latency_limit>"
echo " -p Set the client API port (default: $client_port)"
echo " -r Registry file location (default: $registry_path)"
echo " -l Set the latency limit in milliseconds (default: $latency_limit)"
echo " -b Build images (default: $build)"
exit 1
}
function cleanup() {
echo "Cleaning up"
docker rm --force $(docker ps -a -q)
docker network rm dato-net
exit 0
}
# Parse options
while getopts "p:r:l:bh" opt; do
case $opt in
p) client_port=$OPTARG;;
r) registry_path=$OPTARG;;
l) latency_limit=$OPTARG;;
b) build=true;;
*) usage;;
esac
done
# Output the input options for verification
echo "Client Port: $client_port"
echo "Registry location: ./demo/$registry_path"
echo "Latency Limit: $latency_limit"
if [ "$build" = true ]; then
echo "Building docker images in $(pwd)"
docker build -t dato-validator -f Dockerfile.validator --load .
docker build -t dato-client -f Dockerfile.client --load .
exit 0
fi
trap cleanup EXIT
echo "Creating dato-net network"
docker network create -d bridge dato-net || true
# Read all lines in the registry
while IFS=',' read -r index privkey pubkey
do
instance="dato-validator-$index"
echo "Starting $instance"
docker run -d --network dato-net --name $instance -e RUST_LOG=debug --cap-add=NET_ADMIN dato-validator run --secret-key $privkey --port 8222
rand_latency=$(( ( RANDOM % $latency_limit ) + 1 ))
cmd="tc qdisc add dev eth0 root netem delay ${rand_latency}ms"
echo "Executing command: $cmd"
# Add latency to the validator instance
docker exec $instance $cmd
done < "./demo/$registry_path"
echo ""
echo "Waiting 3 seconds for validators to start..."
sleep 3
echo "Starting dato-client"
docker run -d \
--network dato-net \
--name dato-client \
--mount type=bind,source="$(pwd)/demo/${registry_path}",target="/${registry_path}",readonly \
-p $client_port:$client_port \
-e RUST_LOG=trace dato-client \
--registry-path "/${registry_path}" \
--api-port $client_port
docker logs -f dato-client