run.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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:trixie-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/jetty-hello-web "$image")"
  14. "$dir/../docker-build.sh" "$dir" "$serverImage" <<EOD
  15. FROM $image
  16. COPY dir/index.jsp /var/lib/jetty/webapps/ROOT/
  17. EOD
  18. if [[ $image == *"12."* ]]; then
  19. cid="$(docker run -d "$serverImage" sh -c 'java -jar $JETTY_HOME/start.jar --add-to-start=ee10-deploy,ee10-jsp ; /docker-entrypoint.sh')"
  20. else
  21. cid="$(docker run -d "$serverImage")"
  22. fi
  23. trap "docker rm -vf $cid > /dev/null" EXIT
  24. _request() {
  25. local method="$1"
  26. shift
  27. local url="${1#/}"
  28. shift
  29. docker run --rm \
  30. --link "$cid":jetty \
  31. "$clientImage" \
  32. curl -fs -X"$method" "$@" "http://jetty:8080/$url"
  33. }
  34. # Make sure that Jetty is listening on port 8080
  35. . "$dir/../../retry.sh" --tries 40 --sleep 0.25 '[ "$(_request GET / --output /dev/null || echo $?)" != 7 ]'
  36. # Check that we can request /index.jsp with no params
  37. [ "$(_request GET "/" | tail -1)" = "null" ]
  38. # Check that our index.jsp echoes the value of the "hello" param
  39. hello="world-$RANDOM-$RANDOM"
  40. [ "$(_request GET "/?hello=$hello" | tail -1)" = "$hello" ]