-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathsetup-test-network.sh
executable file
·210 lines (173 loc) · 7.93 KB
/
setup-test-network.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
#!/bin/bash
set -e
# ==============================================================================
# SETUP LOCAL GRAPH NETWORK FOR TESTING
# ==============================================================================
# This script sets up a local Graph network for testing.
#
# NOTES:
# - If you encounter container conflicts, run: docker compose down
# to stop all services before running this script again
#
# - To test changes to your indexer code without restarting everything:
# just reload
#
# - The script checks for existing services and skips those already running
# ==============================================================================
#
# Save the starting disk usage
START_SPACE=$(df -h --output=used /var/lib/docker | tail -1)
START_IMAGES_SIZE=$(docker system df --format '{{.ImagesSize}}' 2>/dev/null || echo "N/A")
START_CONTAINERS_SIZE=$(docker system df --format '{{.ContainersSize}}' 2>/dev/null || echo "N/A")
START_VOLUMES_SIZE=$(docker system df --format '{{.VolumesSize}}' 2>/dev/null || echo "N/A")
echo "============ STARTING DISK USAGE ============"
echo "Docker directory usage: $START_SPACE"
echo "Images size: $START_IMAGES_SIZE"
echo "Containers size: $START_CONTAINERS_SIZE"
echo "Volumes size: $START_VOLUMES_SIZE"
echo "=============================================="
# Your existing script starts here
container_running() {
docker ps --format '{{.Names}}' | grep -q "^$1$"
return $?
}
if container_running "indexer-service" && container_running "tap-agent" && container_running "gateway"; then
echo "====================================================================================="
echo "All services are already running. To test changes to your indexer code, you can use:"
echo " just reload - To rebuild and restart just indexer-service tap-agent services"
echo ""
echo "If you need to start from scratch, first stop all services with:"
echo " just down"
echo " docker rm -f indexer-service tap-agent gateway"
echo "====================================================================================="
exit 0
fi
cd contrib/
ls
pwd
# Clone local-network repo if it doesn't exist
if [ ! -d "local-network" ]; then
git clone https://github.com/edgeandnode/local-network.git
cd local-network
# Checkout to a specific commit that is known to work
git checkout 006e2511d4b8262ff14ff6cd5e1b75f0663dee98
cd ..
fi
# Start the required services from local-network
cd local-network
echo "Starting core infrastructure services..."
docker compose up -d chain ipfs postgres graph-node
# Wait for graph-node to be healthy
echo "Waiting for graph-node to be healthy..."
timeout 300 bash -c 'until docker ps | grep graph-node | grep -q healthy; do sleep 5; done'
echo "Deploying contract services..."
docker compose up -d graph-contracts
# Wait for contracts to be deployed
timeout 300 bash -c 'until docker ps -a | grep graph-contracts | grep -q "Exited (0)"; do sleep 5; done'
# Verify the contracts have code
graph_token_address=$(jq -r '."1337".GraphToken.address' contracts.json)
controller_address=$(jq -r '."1337".Controller.address' contracts.json)
echo "Checking GraphToken contract at $graph_token_address"
code=$(docker exec chain cast code $graph_token_address --rpc-url http://localhost:8545)
if [ -z "$code" ] || [ "$code" == "0x" ]; then
echo "ERROR: GraphToken contract has no code!"
exit 1
fi
echo "GraphToken contract verified."
echo "Checking Controller contract at $controller_address"
code=$(docker exec chain cast code $controller_address --rpc-url http://localhost:8545)
if [ -z "$code" ] || [ "$code" == "0x" ]; then
echo "ERROR: Controller contract has no code!"
exit 1
fi
echo "Controller contract verified."
echo "Contract deployment successful."
docker compose up -d tap-contracts
echo "Starting indexer services..."
docker compose up -d block-oracle
echo "Waiting for block-oracle to be healthy..."
timeout 300 bash -c 'until docker ps | grep block-oracle | grep -q healthy; do sleep 5; done'
docker compose up -d indexer-agent
echo "Waiting for indexer-agent to be healthy..."
timeout 300 bash -c 'until docker ps | grep indexer-agent | grep -q healthy; do sleep 5; done'
echo "Starting subgraph deployment..."
docker compose up --build -d subgraph-deploy
sleep 10 # Give time for subgraphs to deploy
echo "Starting TAP services..."
echo "Starting tap-aggregator..."
docker compose up -d tap-aggregator
sleep 10
# tap-escrow-manager requires subgraph-deploy
echo "Starting tap-escrow-manager..."
docker compose up -d tap-escrow-manager
sleep 10
# Start redpanda if it's not already started (required for gateway)
if ! docker ps | grep -q redpanda; then
echo "Starting redpanda..."
docker compose up -d redpanda
echo "Waiting for redpanda to be healthy..."
timeout 300 bash -c 'until docker ps | grep redpanda | grep -q healthy; do sleep 5; done'
fi
# Get the network name used by local-network
NETWORK_NAME=$(docker inspect graph-node --format='{{range $net,$v := .NetworkSettings.Networks}}{{$net}}{{end}}')
echo "Local-network is using Docker network: $NETWORK_NAME"
# Output the network name for use in the next step
echo "NETWORK_NAME=$NETWORK_NAME" >>$GITHUB_ENV || echo "NETWORK_NAME=$NETWORK_NAME"
cd ..
# Get the network name from the environment or use a default
NETWORK_NAME=${NETWORK_NAME:-local-network_default}
# Create a temporary docker-compose override file to set the network
cat >docker-compose.override.yml <<EOF
version: '3'
networks:
default:
name: $NETWORK_NAME
external: true
EOF
# Build the base image for development(base image:latest)
# This is used for hot reloading
echo "Building base Docker image for development..."
docker build -t indexer-base:latest -f base/Dockerfile ..
# Check to stop any previous instance of indexer-service
# and tap-agent
echo "Checking for existing conflicting services..."
if docker ps -a | grep -q "indexer-service\|tap-agent\|gateway"; then
echo "Stopping existing indexer-service or tap-agent containers..."
docker stop indexer-service tap-agent gateway 2>/dev/null || true
docker rm indexer-service tap-agent gateway 2>/dev/null || true
fi
# Run the custom services using the override file
docker compose -f docker-compose.yml -f docker-compose.override.yml up --build -d
rm docker-compose.override.yml
timeout 30 bash -c 'until docker ps | grep indexer | grep -q healthy; do sleep 5; done'
timeout 30 bash -c 'until docker ps | grep tap-agent | grep -q healthy; do sleep 5; done'
# Mine some blocks
# This is important for the gateway
(./local-network/scripts/mine-block.sh 10) 2>/dev/null || true
echo "Building gateway image..."
docker build -t local-gateway:latest ./local-network/gateway
echo "Running gateway container..."
docker run -d --name gateway \
--network local-network_default \
-p 7700:7700 \
-v $(pwd)/local-network/.env:/opt/.env:ro \
-v $(pwd)/local-network/contracts.json:/opt/contracts.json:ro \
-e RUST_LOG=info,graph_gateway=trace \
--restart on-failure:3 \
local-gateway:latest
echo "Waiting for gateway to be available..."
# Ensure gateway is ready before testing
timeout 300 bash -c 'until curl -f http://localhost:7700/ > /dev/null 2>&1; do echo "Waiting for gateway service..."; sleep 5; done'
# After all services are running, measure the disk space used
END_SPACE=$(df -h --output=used /var/lib/docker | tail -1)
END_IMAGES_SIZE=$(docker system df --format '{{.ImagesSize}}' 2>/dev/null || echo "N/A")
END_CONTAINERS_SIZE=$(docker system df --format '{{.ContainersSize}}' 2>/dev/null || echo "N/A")
END_VOLUMES_SIZE=$(docker system df --format '{{.VolumesSize}}' 2>/dev/null || echo "N/A")
echo "All services are now running!"
echo "You can enjoy your new local network setup for testing."
echo "============ FINAL DISK USAGE ============"
echo "Docker directory usage: $END_SPACE"
echo "Images size: $END_IMAGES_SIZE"
echo "Containers size: $END_CONTAINERS_SIZE"
echo "Volumes size: $END_VOLUMES_SIZE"
echo "==========================================="