run.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. [ "$DEBUG" ] && set -x
  3. set -eo pipefail
  4. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  5. image="$1"
  6. # Use a client image with curl for testing
  7. clientImage='buildpack-deps:bookworm-curl'
  8. # ensure the clientImage is ready and available
  9. if ! docker image inspect "$clientImage" &> /dev/null; then
  10. docker pull "$clientImage" > /dev/null
  11. fi
  12. app1id="$(docker run -d "$image" rapidoid.port=80 id=app1 app.services=ping,status)"
  13. app2id="$(docker run -d "$image" rapidoid.port=80 id=app2 app.services=ping,status)"
  14. proxyid="$(docker run -d --link "$app1id":app1 --link "$app2id":app2 "$image" rapidoid.port=80 '/ -> http://app1, http://app2' app.services=ping)"
  15. trap "docker rm -vf $proxyid $app1id $app2id > /dev/null" EXIT
  16. _request() {
  17. local cid="$1"
  18. shift
  19. local method="$1"
  20. shift
  21. local url="${1#/}"
  22. shift
  23. docker run --rm \
  24. --link "$cid":rapidoid \
  25. "$clientImage" \
  26. curl -fs -X"$method" "$@" "http://rapidoid/$url"
  27. }
  28. # Make sure all Rapidoid servers are listening on port 80
  29. for cid in $app1id $app2id $proxyid; do
  30. . "$dir/../../retry.sh" --tries 40 --sleep 0.25 '[ "$(_request '$cid' GET /rapidoid/ping --output /dev/null || echo $?)" != 7 ]'
  31. done
  32. # Make sure that the round-robin load balancing works properly
  33. for n in `seq 1 5`; do
  34. for i in 1 2; do
  35. [[ "$(_request $cid GET "/rapidoid/status")" == *"\"app$i\""* ]]
  36. done
  37. done