Skip to content

Commit 42dff01

Browse files
committed
feat(setup): add timing reports and improve disk usage tracking
- Add script execution time tracking with minutes/seconds display - Improve Docker size calculation with robust fallback methods - Remove debug output (ls, pwd) and unused environment variables - Update gateway container to use horizon.json instead of tap-contracts.json - Disable set -e to allow graceful error handling - Add structured completion report with timing and disk usage metrics
1 parent 622fa97 commit 42dff01

File tree

1 file changed

+48
-22
lines changed

1 file changed

+48
-22
lines changed

setup-test-network.sh

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -e
2+
# set -e
33

44
# ==============================================================================
55
# SETUP LOCAL GRAPH NETWORK FOR TESTING (HORIZON VERSION)
@@ -15,12 +15,39 @@ set -e
1515
#
1616
# - The script checks for existing services and skips those already running
1717
# ==============================================================================
18-
#
18+
19+
get_docker_sizes() {
20+
local df_output=$(docker system df 2>/dev/null)
21+
22+
# Extract sizes using awk (more reliable)
23+
local images_size=$(echo "$df_output" | awk '/Images/ {print $4}' | head -1)
24+
local containers_size=$(echo "$df_output" | awk '/Containers/ {print $4}' | head -1)
25+
local volumes_size=$(echo "$df_output" | awk '/Local Volumes/ {print $5}' | head -1)
26+
27+
# If awk fails, try alternative method
28+
if [ -z "$images_size" ] || [ -z "$containers_size" ] || [ -z "$volumes_size" ]; then
29+
# Method 2: Use docker system df --format table and parse
30+
images_size=$(docker system df --format "table {{.Type}}\t{{.TotalCount}}\t{{.Size}}" 2>/dev/null | grep "Images" | awk '{print $4}' || echo "N/A")
31+
containers_size=$(docker system df --format "table {{.Type}}\t{{.TotalCount}}\t{{.Size}}" 2>/dev/null | grep "Containers" | awk '{print $4}' || echo "N/A")
32+
volumes_size=$(docker system df --format "table {{.Type}}\t{{.TotalCount}}\t{{.Size}}" 2>/dev/null | grep "Local Volumes" | awk '{print $5}' || echo "N/A")
33+
fi
34+
35+
# Set defaults if still empty
36+
images_size=${images_size:-"N/A"}
37+
containers_size=${containers_size:-"N/A"}
38+
volumes_size=${volumes_size:-"N/A"}
39+
40+
echo "$images_size $containers_size $volumes_size"
41+
}
42+
43+
# Track build times
44+
SCRIPT_START_TIME=$(date +%s)
1945
# Save the starting disk usage
2046
START_SPACE=$(df -h --output=used /var/lib/docker | tail -1)
21-
START_IMAGES_SIZE=$(docker system df --format '{{.ImagesSize}}' 2>/dev/null || echo "N/A")
22-
START_CONTAINERS_SIZE=$(docker system df --format '{{.ContainersSize}}' 2>/dev/null || echo "N/A")
23-
START_VOLUMES_SIZE=$(docker system df --format '{{.VolumesSize}}' 2>/dev/null || echo "N/A")
47+
START_SIZES=($(get_docker_sizes))
48+
START_IMAGES_SIZE=${START_SIZES[0]}
49+
START_CONTAINERS_SIZE=${START_SIZES[1]}
50+
START_VOLUMES_SIZE=${START_SIZES[2]}
2451

2552
echo "============ STARTING DISK USAGE ============"
2653
echo "Docker directory usage: $START_SPACE"
@@ -107,8 +134,6 @@ if container_running "indexer-service" && container_running "tap-agent" && conta
107134
fi
108135

109136
cd contrib/
110-
ls
111-
pwd
112137

113138
# Clone local-network repo if it doesn't exist
114139
if [ ! -d "local-network" ]; then
@@ -239,15 +264,10 @@ echo "Running gateway container..."
239264
docker run -d --name gateway \
240265
--network local-network_default \
241266
-p 7700:7700 \
242-
-v "$(pwd)/local-network/tap-contracts.json":/opt/tap-contracts.json:ro \
267+
-v "$(pwd)/local-network/horizon.json":/opt/horizon.json:ro \
243268
-v "$(pwd)/local-network/subgraph-service.json":/opt/subgraph-service.json:ro \
269+
-v "$(pwd)/local-network/.env":/opt/.env:ro \
244270
-e RUST_LOG=info,graph_gateway=trace \
245-
-e ACCOUNT0_SECRET="$ACCOUNT0_SECRET" \
246-
-e ACCOUNT0_ADDRESS="$ACCOUNT0_ADDRESS" \
247-
-e GATEWAY_API_KEY="$GATEWAY_API_KEY" \
248-
-e GRAPH_NODE_GRAPHQL="$GRAPH_NODE_GRAPHQL" \
249-
-e REDPANDA_KAFKA="$REDPANDA_KAFKA" \
250-
-e INDEXER_SERVICE="$INDEXER_SERVICE" \
251271
--restart on-failure:3 \
252272
local-gateway:latest
253273

@@ -268,15 +288,21 @@ done
268288
# Ensure gateway is ready before testing
269289
timeout 100 bash -c 'until curl -f http://localhost:7700/ > /dev/null 2>&1; do echo "Waiting for gateway service..."; sleep 5; done'
270290

271-
# After all services are running, measure the disk space used
272-
END_SPACE=$(df -h --output=used /var/lib/docker | tail -1)
273-
END_IMAGES_SIZE=$(docker system df --format '{{.ImagesSize}}' 2>/dev/null || echo "N/A")
274-
END_CONTAINERS_SIZE=$(docker system df --format '{{.ContainersSize}}' 2>/dev/null || echo "N/A")
275-
END_VOLUMES_SIZE=$(docker system df --format '{{.VolumesSize}}' 2>/dev/null || echo "N/A")
276-
277-
echo "All services are now running!"
278-
echo "You can enjoy your new local network setup for testing with horizon upgrade."
291+
# Calculate timing and final reports
292+
SCRIPT_END_TIME=$(date +%s)
293+
TOTAL_DURATION=$((SCRIPT_END_TIME - SCRIPT_START_TIME))
294+
MINUTES=$((TOTAL_DURATION / 60))
295+
SECONDS=$((TOTAL_DURATION % 60))
279296

297+
END_SPACE=$(df -h --output=used /var/lib/docker | tail -1)
298+
END_SIZES=($(get_docker_sizes))
299+
END_IMAGES_SIZE=${END_SIZES[0]}
300+
END_CONTAINERS_SIZE=${END_SIZES[1]}
301+
END_VOLUMES_SIZE=${END_SIZES[2]}
302+
303+
echo "============ SETUP COMPLETED ============"
304+
echo "Total setup time: ${MINUTES}m ${SECONDS}s"
305+
echo ""
280306
echo "============ FINAL DISK USAGE ============"
281307
echo "Docker directory usage: $END_SPACE"
282308
echo "Images size: $END_IMAGES_SIZE"

0 commit comments

Comments
 (0)