run.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. set -eo pipefail
  3. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  4. image="$1"
  5. # Use a client image with curl for testing
  6. clientImage='buildpack-deps:bookworm-curl'
  7. # ensure the clientImage is ready and available
  8. if ! docker image inspect "$clientImage" &> /dev/null; then
  9. docker pull "$clientImage" > /dev/null
  10. fi
  11. serverImage="$("$dir/../image-name.sh" librarytest/php-apache-hello-web "$image")"
  12. "$dir/../docker-build.sh" "$dir" "$serverImage" <<EOD
  13. FROM $image
  14. COPY dir/index.php /var/www/html/
  15. EOD
  16. # Create an instance of the container-under-test
  17. cid="$(docker run -d "$serverImage")"
  18. trap "docker rm -vf $cid > /dev/null" EXIT
  19. _request() {
  20. local method="$1"
  21. shift
  22. local url="${1#/}"
  23. shift
  24. docker run --rm \
  25. --link "$cid":apache \
  26. "$clientImage" \
  27. curl -fs -X"$method" "$@" "http://apache/$url"
  28. }
  29. # Make sure that Apache is listening
  30. . "$dir/../../retry.sh" '[ "$(_request GET / --output /dev/null || echo $?)" != 7 ]'
  31. # Check that we can request /index.php with no params
  32. [ -n "$(_request GET "/index.php")" ]
  33. # Check that our index.php echoes the value of the "hello" param
  34. hello="world-$RANDOM-$RANDOM"
  35. [ "$(_request GET "/index.php?hello=$hello" | tail -1)" = "$hello" ]