run.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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:buster-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. # Create an instance of the container-under-test
  13. serverImage="$("$dir/../image-name.sh" librarytest/rapidoid-hello-web "$image")"
  14. "$dir/../docker-build.sh" "$dir" "$serverImage" <<EOD
  15. FROM $image
  16. RUN mkdir -p /app/static
  17. COPY dir/index.html /app/static/
  18. EOD
  19. cid="$(docker run -d "$serverImage" app.services=ping)"
  20. trap "docker rm -vf $cid > /dev/null" EXIT
  21. _request() {
  22. local method="$1"
  23. shift
  24. local url="${1#/}"
  25. shift
  26. docker run --rm \
  27. --link "$cid":rapidoid \
  28. "$clientImage" \
  29. curl -fs -X"$method" "$@" "http://rapidoid:8888/$url"
  30. }
  31. # Make sure that Rapidoid is listening on port 8888
  32. . "$dir/../../retry.sh" --tries 40 --sleep 0.25 '[ "$(_request GET / --output /dev/null || echo $?)" != 7 ]'
  33. # Make sure that Rapidoid serves the static page index.html
  34. [ "$(_request GET "/")" = "Hello world!" ]
  35. [ "$(_request GET "/index.html")" = "Hello world!" ]
  36. # Make sure that Rapidoid's built-in Ping service works correctly
  37. [ "$(_request GET "/rapidoid/ping")" = "OK" ]