run.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. set -eo pipefail
  3. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  4. image="$1"
  5. # Build a client image with cgi-fcgi for testing
  6. clientImage='librarytest/php-fpm-hello-web:fcgi-client'
  7. docker build -t "$clientImage" - > /dev/null <<'EOF'
  8. FROM debian:trixie-slim
  9. RUN set -x && apt-get update && apt-get install -y --no-install-recommends libfcgi-bin && apt-get dist-clean
  10. ENTRYPOINT ["cgi-fcgi"]
  11. EOF
  12. serverImage="$("$dir/../image-name.sh" librarytest/php-fpm-hello-web "$image")"
  13. "$dir/../docker-build.sh" "$dir" "$serverImage" <<EOD
  14. FROM $image
  15. COPY dir/index.php /var/www/html/
  16. EOD
  17. # Create an instance of the container-under-test
  18. cid="$(docker run -d "$serverImage")"
  19. trap "docker rm -vf $cid > /dev/null" EXIT
  20. fcgi-request() {
  21. local method="$1"
  22. local url="$2"
  23. local queryString=
  24. if [[ "$url" == *\?* ]]; then
  25. queryString="${url#*\?}"
  26. url="${url%%\?*}"
  27. fi
  28. docker run --rm -i --link "$cid":fpm \
  29. -e REQUEST_METHOD="$method" \
  30. -e SCRIPT_NAME="$url" \
  31. -e SCRIPT_FILENAME=/var/www/html/"${url#/}" \
  32. -e QUERY_STRING="$queryString" \
  33. "$clientImage" \
  34. -bind -connect fpm:9000
  35. }
  36. # wait until ready
  37. . "$dir/../../retry.sh" --tries 30 'fcgi-request GET /index.php' > /dev/null 2>&1
  38. # Check that we can request /index.php with no params
  39. [ -n "$(fcgi-request GET "/index.php")" ]
  40. # Check that our index.php echoes the value of the "hello" param
  41. hello="world-$RANDOM-$RANDOM"
  42. [ "$(fcgi-request GET "/index.php?hello=$hello" | tail -1)" = "$hello" ]