-
Notifications
You must be signed in to change notification settings - Fork 429
Expand file tree
/
Copy pathrun_itk.sh
More file actions
executable file
·168 lines (146 loc) · 5.23 KB
/
run_itk.sh
File metadata and controls
executable file
·168 lines (146 loc) · 5.23 KB
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
#!/bin/bash
set -ex
# Initialize default exit code
RESULT=1
# Cleanup function to be called on exit
cleanup() {
set +x
echo "Cleaning up artifacts..."
docker stop itk-service > /dev/null 2>&1 || true
docker rm itk-service > /dev/null 2>&1 || true
docker rmi itk_service > /dev/null 2>&1 || true
rm -rf a2a-samples > /dev/null 2>&1 || true
rm -rf pyproto > /dev/null 2>&1 || true
rm -f instruction.proto > /dev/null 2>&1 || true
echo "Done. Final exit code: $RESULT"
}
# Register cleanup function to run on script exit
trap cleanup EXIT
# 1. Pull a2a-samples and checkout revision
: "${A2A_SAMPLES_REVISION:=$(grep "A2A_SAMPLES_REVISION:" ../.github/workflows/itk.yaml | head -n 1 | awk '{print $2}')}"
if [ ! -d "a2a-samples" ]; then
git clone https://github.com/a2aproject/a2a-samples.git a2a-samples
fi
cd a2a-samples
git fetch origin
git checkout "$A2A_SAMPLES_REVISION"
# Only pull if it's a branch (not a detached HEAD)
if git symbolic-ref -q HEAD > /dev/null; then
git pull origin "$A2A_SAMPLES_REVISION"
fi
cd ..
# 2. Copy instruction.proto from a2a-samples
cp a2a-samples/itk/protos/instruction.proto ./instruction.proto
# 3. Build pyproto library
mkdir -p pyproto
touch pyproto/__init__.py
uv run --with grpcio-tools python -m grpc_tools.protoc \
-I. \
--python_out=pyproto \
--grpc_python_out=pyproto \
instruction.proto
# Fix imports in generated file
sed -i 's/^import instruction_pb2 as instruction__pb2/from . import instruction_pb2 as instruction__pb2/' pyproto/instruction_pb2_grpc.py
# 4. Build jit itk_service docker image from root of a2a-samples/itk
# We run docker build from the itk directory inside a2a-samples
docker build -t itk_service a2a-samples/itk
# 5. Start docker service
# Mounting a2a-python as repo and itk as current agent
A2A_PYTHON_ROOT=$(cd .. && pwd)
ITK_DIR=$(pwd)
# Stop existing container if any
docker rm -f itk-service || true
docker run -d --name itk-service \
-v "$A2A_PYTHON_ROOT:/app/agents/repo" \
-v "$ITK_DIR:/app/agents/repo/itk" \
-v "$A2A_PYTHON_ROOT/.git:/app/agents/repo/.git" \
-p 8000:8000 \
itk_service
# 5.1. Fix dubious ownership for git (needed for uv-dynamic-versioning)
docker exec itk-service git config --global --add safe.directory /app/agents/repo
docker exec itk-service git config --global --add safe.directory /app/agents/repo/itk
# 6. Verify service is up and send post request
MAX_RETRIES=30
echo "Waiting for ITK service to start on 127.0.0.1:8000..."
set +e
for i in $(seq 1 $MAX_RETRIES); do
if curl -s http://127.0.0.1:8000/ > /dev/null; then
echo "Service is up!"
break
fi
echo "Still waiting... ($i/$MAX_RETRIES)"
sleep 2
done
# If we reached the end of the loop without success
if ! curl -s http://127.0.0.1:8000/ > /dev/null; then
echo "Error: ITK service failed to start on port 8000"
docker logs itk-service
exit 1
fi
echo "ITK Service is up! Sending compatibility test request..."
RESPONSE=$(curl -s -X POST http://127.0.0.1:8000/run \
-H "Content-Type: application/json" \
-d '{
"tests": [
{
"name": "Star Topology (Full) - JSONRPC & GRPC",
"sdks": ["current", "python_v10", "python_v03", "go_v10", "go_v03"],
"traversal": "euler",
"edges": ["0->1", "0->2", "0->3", "0->4", "1->0", "2->0", "3->0", "4->0"],
"protocols": ["jsonrpc", "grpc"]
},
{
"name": "Star Topology (No Go v03) - HTTP_JSON",
"sdks": ["current", "python_v10", "python_v03", "go_v10"],
"traversal": "euler",
"edges": ["0->1", "0->2", "0->3", "1->0", "2->0", "3->0"],
"protocols": ["http_json"]
},
{
"name": "Star Topology (Full) - JSONRPC & GRPC (Streaming)",
"sdks": ["current", "python_v10", "python_v03", "go_v10", "go_v03"],
"traversal": "euler",
"edges": ["0->1", "0->2", "0->3", "0->4", "1->0", "2->0", "3->0", "4->0"],
"protocols": ["jsonrpc", "grpc"],
"streaming": true
},
{
"name": "Star Topology (No Go v03) - HTTP_JSON (Streaming)",
"sdks": ["current", "python_v10", "python_v03", "go_v10"],
"traversal": "euler",
"edges": ["0->1", "0->2", "0->3", "1->0", "2->0", "3->0"],
"protocols": ["http_json"],
"streaming": true
}
]
}')
echo "--------------------------------------------------------"
echo "ITK TEST RESULTS:"
echo "--------------------------------------------------------"
echo "$RESPONSE" | python3 -c "
import sys, json
try:
data = json.load(sys.stdin)
all_passed = data.get('all_passed', False)
results = data.get('results', {})
for test, passed in results.items():
status = 'PASSED' if passed else 'FAILED'
print(f'{test}: {status}')
print('--------------------------------------------------------')
print(f'OVERALL STATUS: {\"PASSED\" if all_passed else \"FAILED\"}')
if not all_passed:
sys.exit(1)
except Exception as e:
print(f'Error parsing results: {e}')
print(f'Raw response: {data if \"data\" in locals() else \"no data\"}')
sys.exit(1)
"
RESULT=$?
set -e
if [ $RESULT -ne 0 ]; then
echo "Tests failed. Container logs:"
docker logs itk-service
fi
echo "--------------------------------------------------------"
# Final exit result will be captured by trap cleanup
exit $RESULT