From 08115bd6e05e26a8ca4d2f5b1c8ba8f92f9007aa Mon Sep 17 00:00:00 2001 From: Kenneth Bingham Date: Thu, 12 Dec 2024 11:16:46 -0500 Subject: [PATCH] print logs and debug facts if the test fails --- .github/workflows/cmake.yml | 3 +- docker/compose.test.yml | 9 +++++- docker/docker.test.bash | 61 +++++++++++++++++++++++++++++++------ 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 719ac51a..2000a7e3 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -1,4 +1,5 @@ -name: CI build +# callable workflows' jobs appear in the calling workflow's run, so clicking this workflow in GitHub shows no runs +name: Callable CMake Build on: workflow_dispatch: diff --git a/docker/compose.test.yml b/docker/compose.test.yml index 4a477747..44b2a161 100644 --- a/docker/compose.test.yml +++ b/docker/compose.test.yml @@ -1,4 +1,5 @@ services: + httpbin: image: mccutchen/go-httpbin expose: @@ -9,13 +10,19 @@ services: ziti-tun: pull_policy: never command: run --verbose=4 --dns-ip-range=100.95.255.128/25 + environment: + - ZITI_LOG=4 ziti-host: pull_policy: never + depends_on: + httpbin: + condition: service_started networks: - quickstart command: run-host --verbose=4 - # entrypoint: ["bash", "-x", "/docker-entrypoint.sh"] + environment: + - ZITI_LOG=4 quickstart: image: ${ZITI_CLI_IMAGE:-docker.io/openziti/ziti-controller}:${ZITI_CLI_TAG:-latest} diff --git a/docker/docker.test.bash b/docker/docker.test.bash index 18337e42..ab76677f 100755 --- a/docker/docker.test.bash +++ b/docker/docker.test.bash @@ -17,6 +17,39 @@ cleanup(){ echo "DEBUG: cleanup complete" } +debug(){ + + set -o errexit + docker compose logs + docker compose exec -T quickstart bash << BASH + +set -o errexit +set -o nounset +set -o pipefail +set -o xtrace + +ziti edge list edge-routers +ziti edge list terminators +ziti edge policy-advisor services httpbin-service --quiet + +BASH + + for SVC in ziti-{host,tun} + do + docker compose exec -T "${SVC}" bash << BASH || true + +set -o errexit +set -o nounset +set -o pipefail +set -o xtrace + +ziti-edge-tunnel tunnel_status | jq + +BASH + done + +} + checkCommand() { if ! command -v "$1" &>/dev/null; then logError "this script requires command '$1'." @@ -85,7 +118,7 @@ export \ ZITI_EDGE_TUNNEL_IMAGE \ ZITI_EDGE_TUNNEL_TAG \ ZITI_HOST_IMAGE \ -ZITI_HOST_TAG \ +ZITI_HOST_TAG export COMPOSE_FILE="docker/compose.intercept.yml:docker/compose.host.yml:docker/compose.test.yml" @@ -154,23 +187,31 @@ BASH ZITI_ENROLL_TOKEN="$(docker compose exec quickstart cat /tmp/httpbin-host.ott.jwt)" \ docker compose up ziti-host --detach -docker compose up httpbin --detach ZITI_ENROLL_TOKEN="$(docker compose exec quickstart cat /tmp/httpbin-client.ott.jwt)" \ docker compose up ziti-tun --detach -ATTEMPTS=5 -DELAY=3 +ATTEMPTS=2 +DELAY=1 -curl_cmd="curl --fail --max-time 1 --silent --show-error --request POST --header 'Content-Type: application/json' --data '{\"ziti\": \"works\"}' http://httpbin.ziti.internal/post" +curl_cmd="curl --fail --connect-timeout 1 --silent --show-error --request POST --header 'Content-Type: application/json' --data '{\"ziti\": \"works\"}' http://httpbin.ziti.internal/post" until ! ((ATTEMPTS)) || eval "${curl_cmd}" &> /dev/null do (( ATTEMPTS-- )) - echo "Waiting for httpbin service" + : $ATTEMPTS remaining attempts - waiting for httpbin service + docker compose ps sleep ${DELAY} done -eval "${curl_cmd}" | jq .json - -(( I_AM_ROBOT )) || read -p "Press [Enter] to continue..." -cleanup +if eval "${curl_cmd}" | jq .json +then + (( I_AM_ROBOT )) || read -rp "Press [Enter] to continue..." + cleanup + : PASSED + exit 0 +else + debug + cleanup + : FAILED + exit 1 +fi