|
1 | 1 | #!/bin/bash |
2 | | -set -ex |
3 | | - |
4 | | -# Set default log level |
5 | | -export ITK_LOG_LEVEL="${ITK_LOG_LEVEL:-INFO}" |
6 | | - |
7 | | -# Detect container runtime (docker or podman) |
8 | | -if command -v docker &> /dev/null; then |
9 | | - CONTAINER_RT=docker |
10 | | -elif command -v podman &> /dev/null; then |
11 | | - CONTAINER_RT=podman |
12 | | -else |
13 | | - echo "Error: neither docker nor podman found" |
14 | | - exit 1 |
15 | | -fi |
16 | | - |
17 | | -# Initialize default exit code |
18 | | -RESULT=1 |
19 | | - |
20 | | -# Cleanup function to be called on exit |
21 | | -cleanup() { |
22 | | - set +x |
23 | | - echo "Cleaning up artifacts..." |
24 | | - $CONTAINER_RT stop itk-service > /dev/null 2>&1 || true |
25 | | - $CONTAINER_RT rm itk-service > /dev/null 2>&1 || true |
26 | | - $CONTAINER_RT rmi itk_service > /dev/null 2>&1 || true |
27 | | - rm -rf a2a-itk > /dev/null 2>&1 || true |
28 | | - echo "Done. Final exit code: $RESULT" |
29 | | -} |
30 | | - |
31 | | -# Register cleanup function to run on script exit |
32 | | -trap cleanup EXIT |
33 | | - |
34 | | -# 1. Pull a2a-itk and checkout revision. |
35 | | -# The clone doubles as the single source of truth for instruction.proto: |
36 | | -# protobuf-maven-plugin in itk/pom.xml reads it directly from |
37 | | -# ${project.basedir}/a2a-itk/protos (see the `a2a.itk.proto.dir` property). |
| 2 | +# ITK harness for a2a-java — a thin shim over a2a-itk's shared driver. |
| 3 | +# |
| 4 | +# Everything that used to live here (runtime detection, image build, container |
| 5 | +# start, readiness poll, POST /run, result reporting, nightly metrics) is now |
| 6 | +# in a2a-itk/scripts/run_itk_shared.sh, which all five SDK repos share — |
| 7 | +# including the podman fallback this repo needs, which is why the shared |
| 8 | +# driver has it. |
| 9 | +# |
| 10 | +# Scenarios come from the shared role-based set in a2a-itk rather than a |
| 11 | +# scenarios.json in this repo — see a2a-itk/scenarios/traversal/. |
| 12 | +set -e |
| 13 | +cd "$(dirname "${BASH_SOURCE[0]}")" |
| 14 | + |
| 15 | +ITK_SDK_NAME=java |
| 16 | +ITK_SCENARIO_SET=shared |
| 17 | + |
| 18 | +# No codegen step: protobuf-maven-plugin reads instruction.proto straight out |
| 19 | +# of the a2a-itk checkout (`a2a.itk.proto.dir` in itk/pom.xml), so there is |
| 20 | +# nothing to copy. And the repo-root mount already exposes itk/, so the second |
| 21 | +# bind mount other SDKs use would be redundant here. |
| 22 | +ITK_COPY_PROTO=0 |
| 23 | +ITK_MOUNT_ITK_DIR=0 |
| 24 | + |
| 25 | +# --- bootstrap ------------------------------------------------------------- |
| 26 | +# The shared driver lives in a2a-itk, so the checkout has to exist before it |
| 27 | +# can be sourced. CI has already placed it here via actions/checkout; locally |
| 28 | +# we clone it from a2aproject/a2a-itk. |
38 | 29 | : "${A2A_ITK_REVISION:?A2A_ITK_REVISION environment variable must be set}" |
39 | | - |
40 | | -if [ ! -d "a2a-itk" ]; then |
| 30 | +if [ ! -d a2a-itk ]; then |
41 | 31 | git clone https://github.com/a2aproject/a2a-itk.git a2a-itk |
| 32 | + git -C a2a-itk checkout "$A2A_ITK_REVISION" |
42 | 33 | fi |
43 | | -cd a2a-itk |
44 | | -git fetch origin |
45 | | -git checkout "$A2A_ITK_REVISION" |
46 | | - |
47 | | -# Only pull if it's a branch (not a detached HEAD) |
48 | | -if git symbolic-ref -q HEAD > /dev/null; then |
49 | | - git pull origin "$A2A_ITK_REVISION" |
50 | | -fi |
51 | | -cd .. |
52 | | - |
53 | | -# 2. Build itk_service container image from root of a2a-itk (skipped in CI |
54 | | -# where the workflow builds via docker/build-push-action for GHA caching). |
55 | | -if [ "${ITK_SKIP_BUILD:-0}" != "1" ]; then |
56 | | - CONTAINER_BUILD_ARGS="" |
57 | | - if [ "$CONTAINER_RT" = "podman" ]; then |
58 | | - CONTAINER_BUILD_ARGS="--format docker" |
59 | | - fi |
60 | | - $CONTAINER_RT build $CONTAINER_BUILD_ARGS -t itk_service a2a-itk |
61 | | -fi |
62 | | - |
63 | | -# 3. Start container service with a single mount: the a2a-java repo |
64 | | -A2A_JAVA_ROOT=$(cd .. && pwd) |
65 | | - |
66 | | -# Stop existing container if any |
67 | | -$CONTAINER_RT rm -f itk-service || true |
68 | | - |
69 | | -# Create logs directory if debug |
70 | | -if [ "${ITK_LOG_LEVEL^^}" = "DEBUG" ]; then |
71 | | - mkdir -p logs |
72 | | -fi |
73 | | - |
74 | | -DOCKER_MOUNT_LOGS="" |
75 | | -if [ "${ITK_LOG_LEVEL^^}" = "DEBUG" ]; then |
76 | | - DOCKER_MOUNT_LOGS="-v $(pwd)/logs:/app/logs" |
77 | | -fi |
78 | | - |
79 | | -mkdir -p "$HOME/.cache/a2a-itk-launcher" |
80 | | - |
81 | | -$CONTAINER_RT run -d --name itk-service \ |
82 | | - -v "$A2A_JAVA_ROOT:/app/agents/repo" \ |
83 | | - -v "$HOME/.cache/a2a-itk-launcher:/root/.cache/a2a-itk" \ |
84 | | - $DOCKER_MOUNT_LOGS \ |
85 | | - -e ITK_LOG_LEVEL="$ITK_LOG_LEVEL" \ |
86 | | - -e ITK_ENTRYPOINT="${ITK_ENTRYPOINT:-itk_service_v2.py}" \ |
87 | | - -e ITK_READINESS_TIMEOUT="${ITK_READINESS_TIMEOUT:-180}" \ |
88 | | - -e ITK_MAX_WORKERS="${ITK_MAX_WORKERS:-2}" \ |
89 | | - -p 8000:8000 \ |
90 | | - itk_service |
91 | | - |
92 | | -# Launcher's peer checkouts under /root/.cache/a2a-itk are host-owned; trust |
93 | | -# only repos under the launcher cache dir so container-side git accepts them. |
94 | | -$CONTAINER_RT exec itk-service bash -lc 'while IFS= read -r -d "" d; do git config --system --add safe.directory "${d%/.git}"; done < <(find /root/.cache/a2a-itk -type d -name .git -print0)' |
95 | | - |
96 | | -# 4. Verify service is up and send post request |
97 | | -MAX_RETRIES=30 |
98 | | -echo "Waiting for ITK service to start on 127.0.0.1:8000..." |
99 | | -set +e |
100 | | -for i in $(seq 1 $MAX_RETRIES); do |
101 | | - if curl -s http://127.0.0.1:8000/ > /dev/null; then |
102 | | - echo "Service is up!" |
103 | | - break |
104 | | - fi |
105 | | - echo "Still waiting... ($i/$MAX_RETRIES)" |
106 | | - sleep 2 |
107 | | -done |
108 | | - |
109 | | -# If we reached the end of the loop without success |
110 | | -if ! curl -s http://127.0.0.1:8000/ > /dev/null; then |
111 | | - echo "Error: ITK service failed to start on port 8000" |
112 | | - $CONTAINER_RT logs itk-service |
113 | | - exit 1 |
114 | | -fi |
115 | | - |
116 | | - |
117 | | -SCENARIO_FILE="scenarios.json" |
118 | | -if [ "${ITK_NIGHTLY_RUN^^}" = "TRUE" ]; then |
119 | | - SCENARIO_FILE="scenarios_full.json" |
120 | | -fi |
121 | | - |
122 | | -echo "ITK Service is up! Sending compatibility test request using $SCENARIO_FILE..." |
123 | | -RESPONSE=$(curl -s -X POST http://127.0.0.1:8000/run \ |
124 | | - -H "Content-Type: application/json" \ |
125 | | - -d "@$SCENARIO_FILE") |
126 | | - |
127 | | -if [ "${ITK_NIGHTLY_RUN^^}" = "TRUE" ]; then |
128 | | - echo "Nightly run detected. Saving raw results and running process_results.py..." |
129 | | - echo "$RESPONSE" > raw_results.json |
130 | | - python3 a2a-itk/scripts/process_results.py \ |
131 | | - --history_output_file itk_java.json \ |
132 | | - --history_url https://github.com/a2aproject/a2a-java/releases/download/nightly-metrics/itk_java.json |
133 | | - RESULT=$? |
134 | | -else |
135 | | - echo "--------------------------------------------------------" |
136 | | - echo "ITK TEST RESULTS:" |
137 | | - echo "--------------------------------------------------------" |
138 | | - echo "$RESPONSE" | python3 -c " |
139 | | -import sys, json |
140 | | -raw = sys.stdin.read() |
141 | | -try: |
142 | | - data = json.loads(raw) |
143 | | - all_passed = data.get('all_passed', False) |
144 | | - results = data.get('results', {}) |
145 | | - for test, passed in results.items(): |
146 | | - status = 'PASSED' if passed else 'FAILED' |
147 | | - print(f'{test}: {status}') |
148 | | - print('--------------------------------------------------------') |
149 | | - print(f'OVERALL STATUS: {\"PASSED\" if all_passed else \"FAILED\"}') |
150 | | - if not all_passed: |
151 | | - sys.exit(1) |
152 | | -except Exception as e: |
153 | | - print(f'Error parsing results: {e}') |
154 | | - print(f'Raw response: {raw}') |
155 | | - sys.exit(1) |
156 | | -" |
157 | | - RESULT=$? |
158 | | -fi |
159 | | -set -e |
160 | | - |
161 | | -if [ $RESULT -ne 0 ]; then |
162 | | - echo "Tests failed. Container logs:" |
163 | | - $CONTAINER_RT logs itk-service |
164 | | -fi |
165 | | -echo "--------------------------------------------------------" |
166 | 34 |
|
167 | | -# Final exit result will be captured by trap cleanup |
168 | | -exit $RESULT |
| 35 | +source a2a-itk/scripts/run_itk_shared.sh |
0 commit comments